From 6f11b05e25117a2f653f660409e58cda157ebc43 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 6 Dec 2016 17:59:54 +0100 Subject: [PATCH] store Show All in shared prefs making it permanent --- .../gallery/activities/MainActivity.kt | 8 ++++++-- .../gallery/activities/MediaActivity.kt | 17 ++++++++++++++++- .../gallery/activities/ViewPagerActivity.kt | 3 +-- .../simplemobiletools/gallery/helpers/Config.kt | 4 ++++ .../gallery/helpers/Constants.kt | 2 +- app/src/main/res/menu/menu_media.xml | 4 ++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 369b8470d..e83983b23 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -114,7 +114,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun tryloadGallery() { if (hasStoragePermission()) { - getDirectories() + if (mConfig.showAll) + showAllMedia() + else + getDirectories() } else { ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION) } @@ -150,11 +153,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun showAllMedia() { + mConfig.showAll = true Intent(this, MediaActivity::class.java).apply { putExtra(DIRECTORY, "/") - putExtra(SHOW_ALL, true) startActivity(this) } + finish() } override fun prepareForDeleting(paths: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 3982ce623..f9adba4bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -57,7 +57,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_holder.setOnRefreshListener({ getMedia() }) mPath = intent.getStringExtra(DIRECTORY) mMedia = ArrayList() - mShowAll = intent.getBooleanExtra(SHOW_ALL, false) + mShowAll = mConfig.showAll + if (mShowAll) + supportActionBar?.setDisplayHomeAsUpEnabled(false) } override fun onResume() { @@ -103,6 +105,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val isFolderHidden = mConfig.getIsFolderHidden(mPath) menu.findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll menu.findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll + + menu.findItem(R.id.folder_view).isVisible = mShowAll + return true } @@ -116,6 +121,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { toggleFilenameVisibility() true } + R.id.folder_view -> { + switchToFolderView() + true + } R.id.hide_folder -> { hideFolder() true @@ -140,6 +149,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } + private fun switchToFolderView() { + mConfig.showAll = false + startActivity(Intent(this, MainActivity::class.java)) + finish() + } + private fun hideFolder() { mConfig.addHiddenFolder(mPath) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 015c0316d..67f1a8401 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -27,7 +27,6 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER -import com.simplemobiletools.gallery.helpers.SHOW_ALL import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_medium.* import java.io.File @@ -67,7 +66,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } else { mPath = intent.getStringExtra(MEDIUM) - mShowAll = intent.getBooleanExtra(SHOW_ALL, false) + mShowAll = mConfig.showAll } if (mPath.isEmpty()) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 0e8467c75..cd9627cc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -43,6 +43,10 @@ class Config private constructor(context: Context) { get() = mPrefs.getStringSet(PINNED_FOLDERS, HashSet()) set(pinnedFolders) = mPrefs.edit().putStringSet(PINNED_FOLDERS, pinnedFolders).apply() + var showAll: Boolean + get() = mPrefs.getBoolean(SHOW_ALL, false) + set(showAll) = mPrefs.edit().putBoolean(SHOW_ALL, showAll).apply() + fun addPinnedFolders(paths: Set) { val currPinnedFolders = HashSet(pinnedFolders) currPinnedFolders.addAll(paths) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index e9504baea..a736fc33c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -13,6 +13,7 @@ val AUTOPLAY_VIDEOS = "autoplay_videos" val TREE_URI = "tree_uri" val DISPLAY_FILE_NAMES = "display_file_names" val PINNED_FOLDERS = "pinned_folders" +val SHOW_ALL = "show_all" // sorting val SORT_BY_NAME = 1 @@ -26,7 +27,6 @@ val SORT_DESCENDING = 1024 val OPEN_DOCUMENT_TREE = 1000 val DIRECTORY = "directory" -val SHOW_ALL = "show_all" val MEDIUM = "medium" val GET_IMAGE_INTENT = "get_image_intent" val GET_VIDEO_INTENT = "get_video_intent" diff --git a/app/src/main/res/menu/menu_media.xml b/app/src/main/res/menu/menu_media.xml index 6292b4349..72a4fbced 100644 --- a/app/src/main/res/menu/menu_media.xml +++ b/app/src/main/res/menu/menu_media.xml @@ -11,6 +11,10 @@ android:icon="@mipmap/toggle_filename" android:title="@string/toggle_filename" app:showAsAction="ifRoom"/> +