diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index f1f33fd10..fd2d67c33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -787,7 +787,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { runOnUiThread { checkPlaceholderVisibility(dirs) - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFolders == VIEW_TYPE_GRID directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll) directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll) setupAdapter(dirs) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 8eaa3ccf4..fdca85100 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -219,10 +219,10 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden - findItem(R.id.increase_column_count).isVisible = config.viewTypeFiles == VIEW_TYPE_GRID && config.mediaColumnCnt < MAX_COLUMN_COUNT - findItem(R.id.reduce_column_count).isVisible = config.viewTypeFiles == VIEW_TYPE_GRID && config.mediaColumnCnt > 1 - - findItem(R.id.toggle_filename).isVisible = config.viewTypeFiles == VIEW_TYPE_GRID + val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) + findItem(R.id.increase_column_count).isVisible = viewType == VIEW_TYPE_GRID && config.mediaColumnCnt < MAX_COLUMN_COUNT + findItem(R.id.reduce_column_count).isVisible = viewType == VIEW_TYPE_GRID && config.mediaColumnCnt > 1 + findItem(R.id.toggle_filename).isVisible = viewType == VIEW_TYPE_GRID } setupSearch(menu) @@ -362,7 +362,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { initZoomListener() val fastscroller = if (config.scrollHorizontally) media_horizontal_fastscroller else media_vertical_fastscroller MediaAdapter(this, mMedia.clone() as ArrayList, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, - mAllowPickingMultiple, media_grid, fastscroller) { + mAllowPickingMultiple, mPath, media_grid, fastscroller) { if (it is Medium) { itemClicked(it.path) } @@ -380,7 +380,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun setupScrollDirection() { - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) + val allowHorizontalScroll = config.scrollHorizontally && viewType == VIEW_TYPE_GRID media_vertical_fastscroller.isHorizontal = false media_vertical_fastscroller.beGoneIf(allowHorizontalScroll) @@ -488,7 +489,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun changeViewType() { - ChangeViewTypeDialog(this, false) { + ChangeViewTypeDialog(this, false, mPath) { invalidateOptionsMenu() setupLayoutManager() media_grid.adapter = null @@ -636,7 +637,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun setupLayoutManager() { - if (config.viewTypeFiles == VIEW_TYPE_GRID) { + val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) + if (viewType == VIEW_TYPE_GRID) { setupGridLayoutManager() } else { setupListLayoutManager() @@ -712,7 +714,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun initZoomListener() { - if (config.viewTypeFiles == VIEW_TYPE_GRID) { + val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) + if (viewType == VIEW_TYPE_GRID) { val layoutManager = media_grid.layoutManager as MyGridLayoutManager mZoomListener = object : MyRecyclerView.MyZoomListener { override fun zoomIn() { @@ -830,7 +833,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache) media_grid.beVisibleIf(media_empty_text_label.isGone()) - val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID + val viewType = config.getFolderViewType(if (mShowAll) SHOW_ALL else mPath) + val allowHorizontalScroll = config.scrollHorizontally && viewType == VIEW_TYPE_GRID media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll) media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll) setupAdapter() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index e20ea1351..6d1a1b3bb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -24,6 +24,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.pro.extensions.* +import com.simplemobiletools.gallery.pro.helpers.SHOW_ALL import com.simplemobiletools.gallery.pro.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener import com.simplemobiletools.gallery.pro.models.Medium @@ -35,7 +36,7 @@ import java.text.SimpleDateFormat import java.util.* class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, - val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : + val allowMultiplePicks: Boolean, val path: String, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { private val INSTANT_LOAD_DURATION = 2000L @@ -45,7 +46,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList() private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt index 858101b04..78537069a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt @@ -7,13 +7,15 @@ import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config +import com.simplemobiletools.gallery.pro.helpers.SHOW_ALL import com.simplemobiletools.gallery.pro.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.pro.helpers.VIEW_TYPE_LIST import kotlinx.android.synthetic.main.dialog_change_view_type.view.* -class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView: Boolean, val callback: () -> Unit) { +class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView: Boolean, val path: String = "", val callback: () -> Unit) { private var view: View private var config = activity.config + private var pathToUse = if (path.isEmpty()) SHOW_ALL else path init { view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply { @@ -23,10 +25,13 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView } else { change_view_type_dialog_radio_list.id } - } else if (config.viewTypeFiles == VIEW_TYPE_GRID) { - change_view_type_dialog_radio_grid.id } else { - change_view_type_dialog_radio_list.id + val currViewType = config.getFolderViewType(pathToUse) + if (currViewType == VIEW_TYPE_GRID) { + change_view_type_dialog_radio_grid.id + } else { + change_view_type_dialog_radio_list.id + } } change_view_type_dialog_radio.check(viewToCheck) @@ -34,6 +39,11 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView beVisibleIf(fromFoldersView) isChecked = config.groupDirectSubfolders } + + change_view_type_dialog_use_for_this_folder.apply { + beVisibleIf(!fromFoldersView) + isChecked = config.hasCustomViewType(pathToUse) + } } AlertDialog.Builder(activity) @@ -50,7 +60,12 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView config.viewTypeFolders = viewType config.groupDirectSubfolders = view.change_view_type_dialog_group_direct_subfolders.isChecked } else { - config.viewTypeFiles = viewType + if (view.change_view_type_dialog_use_for_this_folder.isChecked) { + config.saveFolderViewType(pathToUse, viewType) + } else { + config.removeFolderViewType(pathToUse) + config.viewTypeFiles = viewType + } } callback() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt index b1f83527b..f75a8f301 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickMediumDialog.kt @@ -22,7 +22,8 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c var dialog: AlertDialog var shownMedia = ArrayList() val view = activity.layoutInflater.inflate(R.layout.dialog_medium_picker, null) - var isGridViewType = activity.config.viewTypeFiles == VIEW_TYPE_GRID + val viewType = activity.config.getFolderViewType(if (activity.config.showAll) SHOW_ALL else path) + var isGridViewType = viewType == VIEW_TYPE_GRID init { (view.media_grid.layoutManager as MyGridLayoutManager).apply { @@ -64,7 +65,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c return shownMedia = media - val adapter = MediaAdapter(activity, shownMedia.clone() as ArrayList, null, true, false, view.media_grid, null) { + val adapter = MediaAdapter(activity, shownMedia.clone() as ArrayList, null, true, false, path, view.media_grid, null) { if (it is Medium) { callback(it.path) dialog.dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index cdb7ef840..5956bf22f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -59,6 +59,22 @@ class Config(context: Context) : BaseConfig(context) { fun hasCustomGrouping(path: String) = prefs.contains(GROUP_FOLDER_PREFIX + path.toLowerCase()) + fun saveFolderViewType(path: String, value: Int) { + if (path.isEmpty()) { + viewTypeFiles = value + } else { + prefs.edit().putInt(VIEW_TYPE_PREFIX + path.toLowerCase(), value).apply() + } + } + + fun getFolderViewType(path: String) = prefs.getInt(VIEW_TYPE_PREFIX + path.toLowerCase(), viewTypeFiles) + + fun removeFolderViewType(path: String) { + prefs.edit().remove(VIEW_TYPE_PREFIX + path.toLowerCase()).apply() + } + + fun hasCustomViewType(path: String) = prefs.contains(VIEW_TYPE_PREFIX + path.toLowerCase()) + var wasHideFolderTooltipShown: Boolean get() = prefs.getBoolean(HIDE_FOLDER_TOOLTIP_SHOWN, false) set(wasShown) = prefs.edit().putBoolean(HIDE_FOLDER_TOOLTIP_SHOWN, wasShown).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 95a068eb0..5514193b4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -6,6 +6,7 @@ import com.simplemobiletools.commons.helpers.MONTH_SECONDS const val DIRECTORY_SORT_ORDER = "directory_sort_order" const val SORT_FOLDER_PREFIX = "sort_folder_" const val GROUP_FOLDER_PREFIX = "group_folder_" +const val VIEW_TYPE_PREFIX = "view_type_folder_" const val SHOW_HIDDEN_MEDIA = "show_hidden_media" const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden" const val IS_THIRD_PARTY_INTENT = "is_third_party_intent" diff --git a/app/src/main/res/layout/dialog_change_view_type.xml b/app/src/main/res/layout/dialog_change_view_type.xml index 003692bb9..b6e1f342c 100644 --- a/app/src/main/res/layout/dialog_change_view_type.xml +++ b/app/src/main/res/layout/dialog_change_view_type.xml @@ -50,5 +50,13 @@ android:paddingBottom="@dimen/activity_margin" android:text="@string/group_direct_subfolders"/> + +