From 427e44f3bde1319f7d49c29e7f3254f695c824f3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jul 2016 22:41:58 +0200 Subject: [PATCH] allow refreshing media view too - closes #10 --- .../gallery/activities/MediaActivity.java | 24 +++++++++++++++---- app/src/main/res/layout/activity_media.xml | 24 ++++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index 687927ff1..a687bf40c 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -13,6 +13,7 @@ import android.os.Parcelable; import android.provider.MediaStore; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; +import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; import android.util.SparseBooleanArray; import android.view.ActionMode; @@ -44,9 +45,11 @@ import butterknife.BindView; import butterknife.ButterKnife; public class MediaActivity extends SimpleActivity - implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { + implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener, + SwipeRefreshLayout.OnRefreshListener { private static final String TAG = MediaActivity.class.getSimpleName(); @BindView(R.id.media_grid) GridView mGridView; + @BindView(R.id.media_holder) SwipeRefreshLayout mSwipeRefreshLayout; private static List mMedia; private static String mPath; @@ -66,6 +69,10 @@ public class MediaActivity extends SimpleActivity ButterKnife.bind(this); mIsGetImageIntent = getIntent().getBooleanExtra(Constants.GET_IMAGE_INTENT, false); mIsGetVideoIntent = getIntent().getBooleanExtra(Constants.GET_VIDEO_INTENT, false); + mToBeDeleted = new ArrayList<>(); + mSwipeRefreshLayout.setOnRefreshListener(this); + mPath = getIntent().getStringExtra(Constants.DIRECTORY); + mMedia = new ArrayList<>(); } @Override @@ -93,9 +100,12 @@ public class MediaActivity extends SimpleActivity } private void initializeGallery() { - mToBeDeleted = new ArrayList<>(); - mPath = getIntent().getStringExtra(Constants.DIRECTORY); - mMedia = getMedia(); + final List newMedia = getMedia(); + if (newMedia.toString().equals(mMedia.toString())) { + return; + } + + mMedia = newMedia; if (isDirEmpty()) return; @@ -347,4 +357,10 @@ public class MediaActivity extends SimpleActivity return false; } + + @Override + public void onRefresh() { + initializeGallery(); + mSwipeRefreshLayout.setRefreshing(false); + } } diff --git a/app/src/main/res/layout/activity_media.xml b/app/src/main/res/layout/activity_media.xml index dc5279a1d..aa6227314 100644 --- a/app/src/main/res/layout/activity_media.xml +++ b/app/src/main/res/layout/activity_media.xml @@ -6,15 +6,21 @@ android:layout_height="match_parent" android:background="@android:color/black"> - + android:layout_height="wrap_content"> + + +