create a separate dialog for Group By for more flexibility
This commit is contained in:
parent
05d37cbfcc
commit
637913415b
5 changed files with 234 additions and 23 deletions
|
@ -33,6 +33,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
|||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeGroupingDialog
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||
import com.simplemobiletools.gallery.dialogs.FilterMediaDialog
|
||||
|
@ -418,23 +419,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
private fun showGroupByDialog() {
|
||||
val items = arrayListOf(
|
||||
RadioItem(GROUP_BY_NONE, getString(R.string.do_not_group_files)),
|
||||
RadioItem(GROUP_BY_LAST_MODIFIED, getString(R.string.by_last_modified)),
|
||||
RadioItem(GROUP_BY_DATE_TAKEN, getString(R.string.by_date_taken)),
|
||||
RadioItem(GROUP_BY_FILE_TYPE, getString(R.string.by_file_type)),
|
||||
RadioItem(GROUP_BY_EXTENSION, getString(R.string.by_extension))
|
||||
)
|
||||
|
||||
if (mShowAll) {
|
||||
items.add(RadioItem(GROUP_BY_FOLDER, getString(R.string.by_folder)))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items, config.groupBy) {
|
||||
config.groupBy = it as Int
|
||||
invalidateOptionsMenu()
|
||||
media_grid.adapter = null
|
||||
setupAdapter()
|
||||
ChangeGroupingDialog(this, mShowAll, mPath) {
|
||||
mLoadedInitialPhotos = false
|
||||
getMedia()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package com.simplemobiletools.gallery.dialogs
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import kotlinx.android.synthetic.main.dialog_change_grouping.view.*
|
||||
|
||||
class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: Boolean, val path: String = "", val callback: () -> Unit) :
|
||||
DialogInterface.OnClickListener {
|
||||
private var currGrouping = 0
|
||||
private var config = activity.config
|
||||
private var view: View
|
||||
|
||||
init {
|
||||
view = activity.layoutInflater.inflate(R.layout.dialog_change_grouping, null).apply {
|
||||
use_for_this_folder_divider.beVisibleIf(!isShowingAll)
|
||||
grouping_dialog_use_for_this_folder.beVisibleIf(!isShowingAll)
|
||||
grouping_dialog_use_for_this_folder.isChecked = config.hasCustomGrouping(path)
|
||||
grouping_dialog_radio_folder.beVisibleIf(isShowingAll)
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, this)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.group_by)
|
||||
}
|
||||
|
||||
currGrouping = config.getFolderGrouping(path)
|
||||
setupGroupRadio()
|
||||
setupOrderRadio()
|
||||
}
|
||||
|
||||
private fun setupGroupRadio() {
|
||||
val groupingRadio = view.grouping_dialog_radio_grouping
|
||||
|
||||
val groupBtn = when {
|
||||
currGrouping and GROUP_BY_NONE != 0 -> groupingRadio.grouping_dialog_radio_none
|
||||
currGrouping and GROUP_BY_LAST_MODIFIED != 0 -> groupingRadio.grouping_dialog_radio_last_modified
|
||||
currGrouping and GROUP_BY_DATE_TAKEN != 0 -> groupingRadio.grouping_dialog_radio_date_taken
|
||||
currGrouping and GROUP_BY_FILE_TYPE != 0 -> groupingRadio.grouping_dialog_radio_file_type
|
||||
currGrouping and GROUP_BY_EXTENSION != 0 -> groupingRadio.grouping_dialog_radio_extension
|
||||
else -> groupingRadio.grouping_dialog_radio_folder
|
||||
}
|
||||
groupBtn.isChecked = true
|
||||
}
|
||||
|
||||
private fun setupOrderRadio() {
|
||||
val orderRadio = view.grouping_dialog_radio_order
|
||||
var orderBtn = orderRadio.grouping_dialog_radio_ascending
|
||||
|
||||
if (currGrouping and GROUP_DESCENDING != 0) {
|
||||
orderBtn = orderRadio.grouping_dialog_radio_descending
|
||||
}
|
||||
orderBtn.isChecked = true
|
||||
}
|
||||
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
val groupingRadio = view.grouping_dialog_radio_grouping
|
||||
var grouping = when (groupingRadio.checkedRadioButtonId) {
|
||||
R.id.grouping_dialog_radio_none -> GROUP_BY_NONE
|
||||
R.id.grouping_dialog_radio_last_modified -> GROUP_BY_LAST_MODIFIED
|
||||
R.id.grouping_dialog_radio_date_taken -> GROUP_BY_DATE_TAKEN
|
||||
R.id.grouping_dialog_radio_file_type -> GROUP_BY_FILE_TYPE
|
||||
R.id.grouping_dialog_radio_extension -> GROUP_BY_EXTENSION
|
||||
else -> GROUP_BY_FOLDER
|
||||
}
|
||||
|
||||
if (view.grouping_dialog_radio_order.checkedRadioButtonId == R.id.grouping_dialog_radio_descending) {
|
||||
grouping = grouping or GROUP_DESCENDING
|
||||
}
|
||||
|
||||
if (view.grouping_dialog_use_for_this_folder.isChecked) {
|
||||
config.saveFolderGrouping(path, grouping)
|
||||
} else {
|
||||
config.removeFolderGrouping(path)
|
||||
config.groupBy = grouping
|
||||
}
|
||||
callback()
|
||||
}
|
||||
}
|
|
@ -36,6 +36,28 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
|
||||
fun hasCustomSorting(path: String) = prefs.contains(SORT_FOLDER_PREFIX + path.toLowerCase())
|
||||
|
||||
fun saveFolderGrouping(path: String, value: Int) {
|
||||
if (path.isEmpty()) {
|
||||
groupBy = value
|
||||
} else {
|
||||
prefs.edit().putInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun getFolderGrouping(path: String): Int {
|
||||
var groupBy = prefs.getInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), groupBy)
|
||||
if (path.isNotEmpty() && groupBy and GROUP_BY_FOLDER != 0) {
|
||||
groupBy -= GROUP_BY_FOLDER + 1
|
||||
}
|
||||
return groupBy
|
||||
}
|
||||
|
||||
fun removeFolderGrouping(path: String) {
|
||||
prefs.edit().remove(GROUP_FOLDER_PREFIX + path.toLowerCase()).apply()
|
||||
}
|
||||
|
||||
fun hasCustomGrouping(path: String) = prefs.contains(GROUP_FOLDER_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()
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.helpers
|
|||
// shared preferences
|
||||
const val DIRECTORY_SORT_ORDER = "directory_sort_order"
|
||||
const val SORT_FOLDER_PREFIX = "sort_folder_"
|
||||
const val GROUP_FOLDER_PREFIX = "group_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"
|
||||
|
@ -114,9 +115,10 @@ const val LOCAITON_INTERNAL = 1
|
|||
const val LOCATION_SD = 2
|
||||
const val LOCATION_OTG = 3
|
||||
|
||||
const val GROUP_BY_NONE = 0
|
||||
const val GROUP_BY_LAST_MODIFIED = 1
|
||||
const val GROUP_BY_DATE_TAKEN = 2
|
||||
const val GROUP_BY_FILE_TYPE = 3
|
||||
const val GROUP_BY_EXTENSION = 4
|
||||
const val GROUP_BY_FOLDER = 5
|
||||
const val GROUP_BY_NONE = 1
|
||||
const val GROUP_BY_LAST_MODIFIED = 2
|
||||
const val GROUP_BY_DATE_TAKEN = 4
|
||||
const val GROUP_BY_FILE_TYPE = 8
|
||||
const val GROUP_BY_EXTENSION = 16
|
||||
const val GROUP_BY_FOLDER = 32
|
||||
const val GROUP_DESCENDING = 1024
|
||||
|
|
113
app/src/main/res/layout/dialog_change_grouping.xml
Normal file
113
app/src/main/res/layout/dialog_change_grouping.xml
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/grouping_dialog_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/grouping_dialog_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/grouping_dialog_radio_grouping"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/medium_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_none"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/do_not_group_files"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_last_modified"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/by_last_modified"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_date_taken"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/by_date_taken"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_file_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/by_file_type"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_extension"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/by_extension"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_folder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/by_folder"/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<include
|
||||
layout="@layout/divider"/>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/grouping_dialog_radio_order"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/medium_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_ascending"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/ascending"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/grouping_dialog_radio_descending"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/descending"/>
|
||||
</RadioGroup>
|
||||
|
||||
<include
|
||||
android:id="@+id/use_for_this_folder_divider"
|
||||
layout="@layout/divider"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/grouping_dialog_use_for_this_folder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/use_for_this_folder"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
Loading…
Reference in a new issue