fix #1146, allow setting view type per-folder
This commit is contained in:
parent
c2178d467e
commit
8758b3c9fc
8 changed files with 67 additions and 20 deletions
|
@ -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)
|
||||
|
|
|
@ -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<ThumbnailItem>, 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()
|
||||
|
|
|
@ -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<ThumbnailItem>, 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<Thumbnai
|
|||
private val ITEM_MEDIUM = 1
|
||||
|
||||
private val config = activity.config
|
||||
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
|
||||
private val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path)
|
||||
private val isListViewType = viewType == VIEW_TYPE_LIST
|
||||
private var visibleItemPaths = ArrayList<String>()
|
||||
private var loadImageInstantly = false
|
||||
private var delayHandler = Handler(Looper.getMainLooper())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -22,7 +22,8 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
|||
var dialog: AlertDialog
|
||||
var shownMedia = ArrayList<ThumbnailItem>()
|
||||
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<ThumbnailItem>, null, true, false, view.media_grid, null) {
|
||||
val adapter = MediaAdapter(activity, shownMedia.clone() as ArrayList<ThumbnailItem>, null, true, false, path, view.media_grid, null) {
|
||||
if (it is Medium) {
|
||||
callback(it.path)
|
||||
dialog.dismiss()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -50,5 +50,13 @@
|
|||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:text="@string/group_direct_subfolders"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/change_view_type_dialog_use_for_this_folder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:text="@string/use_for_this_folder"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
Loading…
Reference in a new issue