From b31a18e48c9adb05a04c42b030d11b18a70ba9e3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 20 Jul 2016 22:35:29 +0200 Subject: [PATCH] add pull to refresh to the directories view --- .../gallery/activities/MainActivity.java | 23 ++++++++++++++---- app/src/main/res/layout/activity_main.xml | 24 ++++++++++++------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 0840e54d9..db1a5a90e 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -14,6 +14,7 @@ import android.provider.MediaStore; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AlertDialog; import android.util.SparseBooleanArray; import android.view.ActionMode; @@ -45,8 +46,10 @@ import butterknife.BindView; import butterknife.ButterKnife; public class MainActivity extends SimpleActivity - implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { + implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener, + SwipeRefreshLayout.OnRefreshListener { @BindView(R.id.directories_grid) GridView mGridView; + @BindView(R.id.directories_holder) SwipeRefreshLayout mSwipeRefreshLayout; private static final int STORAGE_PERMISSION = 1; private static final int PICK_MEDIA = 2; @@ -79,9 +82,12 @@ public class MainActivity extends SimpleActivity mIsGetImageContentIntent = isGetImageContentIntent(intent); mIsGetVideoContentIntent = isGetVideoContentIntent(intent); mIsSetWallpaperIntent = isSetWallpaperIntent(intent); - mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsSetWallpaperIntent; + + mToBeDeleted = new ArrayList<>(); + mSwipeRefreshLayout.setOnRefreshListener(this); + mDirs = new ArrayList<>(); } @Override @@ -155,8 +161,11 @@ public class MainActivity extends SimpleActivity } private void initializeGallery() { - mToBeDeleted = new ArrayList<>(); - mDirs = getDirectories(); + final List newDirs = getDirectories(); + if (newDirs.toString().equals(mDirs.toString())) { + return; + } + mDirs = newDirs; final DirectoryAdapter adapter = new DirectoryAdapter(this, mDirs); mGridView.setAdapter(adapter); @@ -533,4 +542,10 @@ public class MainActivity extends SimpleActivity }); } } + + @Override + public void onRefresh() { + initializeGallery(); + mSwipeRefreshLayout.setRefreshing(false); + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9f4d42496..6d462dfb0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,15 +6,21 @@ android:layout_height="match_parent" android:background="@android:color/black"> - + android:layout_height="wrap_content"> + + +