store Show All in shared prefs making it permanent

This commit is contained in:
tibbi 2016-12-06 17:59:54 +01:00
parent 73cd9a5638
commit 6f11b05e25
6 changed files with 32 additions and 6 deletions

View file

@ -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<String>) {

View file

@ -57,7 +57,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
media_holder.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY)
mMedia = ArrayList<Medium>()
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)

View file

@ -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()) {

View file

@ -43,6 +43,10 @@ class Config private constructor(context: Context) {
get() = mPrefs.getStringSet(PINNED_FOLDERS, HashSet<String>())
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<String>) {
val currPinnedFolders = HashSet<String>(pinnedFolders)
currPinnedFolders.addAll(paths)

View file

@ -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"

View file

@ -11,6 +11,10 @@
android:icon="@mipmap/toggle_filename"
android:title="@string/toggle_filename"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/folder_view"
android:title="@string/folder_view"
app:showAsAction="never"/>
<item
android:id="@+id/hide_folder"
android:title="@string/hide_folder"