simplify column count customization
This commit is contained in:
parent
f01bcb0f35
commit
51c38109e9
8 changed files with 60 additions and 46 deletions
|
@ -190,9 +190,7 @@ class MainActivity : SimpleActivity() {
|
|||
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden && currentFragment !is StorageFragment
|
||||
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden && currentFragment !is StorageFragment
|
||||
|
||||
findItem(R.id.increase_column_count).isVisible =
|
||||
currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT && currentFragment !is StorageFragment
|
||||
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 && currentFragment !is StorageFragment
|
||||
findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID && currentFragment !is StorageFragment
|
||||
|
||||
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
|
||||
findItem(R.id.settings).isVisible = !isCreateDocumentIntent
|
||||
|
@ -235,8 +233,7 @@ class MainActivity : SimpleActivity() {
|
|||
R.id.change_view_type -> changeViewType()
|
||||
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
||||
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
||||
R.id.increase_column_count -> increaseColumnCount()
|
||||
R.id.reduce_column_count -> reduceColumnCount()
|
||||
R.id.column_count -> changeColumnCount()
|
||||
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
|
||||
R.id.settings -> launchSettings()
|
||||
R.id.about -> launchAbout()
|
||||
|
@ -568,15 +565,21 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun increaseColumnCount() {
|
||||
getAllFragments().forEach {
|
||||
(it as? ItemOperationsListener)?.increaseColumnCount()
|
||||
private fun changeColumnCount() {
|
||||
val items = ArrayList<RadioItem>()
|
||||
for (i in 1..MAX_COLUMN_COUNT) {
|
||||
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduceColumnCount() {
|
||||
getAllFragments().forEach {
|
||||
(it as? ItemOperationsListener)?.reduceColumnCount()
|
||||
val currentColumnCount = config.fileColumnCnt
|
||||
RadioGroupDialog(this, items, config.fileColumnCnt) {
|
||||
val newColumnCount = it as Int
|
||||
if (currentColumnCount != newColumnCount) {
|
||||
config.fileColumnCnt = newColumnCount
|
||||
getAllFragments().forEach {
|
||||
(it as? ItemOperationsListener)?.columnCountChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,14 @@ import android.view.MenuItem
|
|||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.MenuItemCompat
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.NavigationIcon
|
||||
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
|
||||
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.filemanager.pro.R
|
||||
|
@ -85,8 +87,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
|
|||
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 = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT
|
||||
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1
|
||||
findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,8 +100,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
|
|||
R.id.change_view_type -> changeViewType()
|
||||
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
||||
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
||||
R.id.increase_column_count -> increaseColumnCount()
|
||||
R.id.reduce_column_count -> reduceColumnCount()
|
||||
R.id.column_count -> changeColumnCount()
|
||||
else -> return@setOnMenuItemClickListener false
|
||||
}
|
||||
return@setOnMenuItemClickListener true
|
||||
|
@ -166,20 +166,44 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
|
|||
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
|
||||
}
|
||||
|
||||
private fun changeColumnCount() {
|
||||
val items = ArrayList<RadioItem>()
|
||||
for (i in 1..MAX_COLUMN_COUNT) {
|
||||
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
|
||||
}
|
||||
|
||||
val currentColumnCount = config.fileColumnCnt
|
||||
RadioGroupDialog(this, items, config.fileColumnCnt) {
|
||||
val newColumnCount = it as Int
|
||||
if (currentColumnCount != newColumnCount) {
|
||||
config.fileColumnCnt = newColumnCount
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun increaseColumnCount() {
|
||||
if (currentViewType == VIEW_TYPE_GRID) {
|
||||
config.fileColumnCnt = ++(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
config.fileColumnCnt += 1
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
override fun reduceColumnCount() {
|
||||
if (currentViewType == VIEW_TYPE_GRID) {
|
||||
config.fileColumnCnt = --(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
config.fileColumnCnt -= 1
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
override fun columnCountChanged() {
|
||||
(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt
|
||||
refreshMenuItems()
|
||||
getRecyclerAdapter()?.apply {
|
||||
notifyItemRangeChanged(0, listItems.size)
|
||||
}
|
||||
}
|
||||
|
||||
override fun finishActMode() {}
|
||||
|
||||
private fun setupSearch(menu: Menu) {
|
||||
|
@ -370,13 +394,6 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun columnCountChanged() {
|
||||
refreshMenuItems()
|
||||
getRecyclerAdapter()?.apply {
|
||||
notifyItemRangeChanged(0, listItems.size)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupLayoutManager() {
|
||||
if (config.getFolderViewType(currentMimeType) == VIEW_TYPE_GRID) {
|
||||
currentViewType = VIEW_TYPE_GRID
|
||||
|
|
|
@ -488,19 +488,20 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||
|
||||
override fun increaseColumnCount() {
|
||||
if (currentViewType == VIEW_TYPE_GRID) {
|
||||
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
context!!.config.fileColumnCnt += 1
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
override fun reduceColumnCount() {
|
||||
if (currentViewType == VIEW_TYPE_GRID) {
|
||||
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
context!!.config.fileColumnCnt -= 1
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun columnCountChanged() {
|
||||
override fun columnCountChanged() {
|
||||
(items_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt
|
||||
(activity as? MainActivity)?.refreshMenuItems()
|
||||
getRecyclerAdapter()?.apply {
|
||||
notifyItemRangeChanged(0, listItems.size)
|
||||
|
|
|
@ -178,19 +178,20 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||
|
||||
override fun increaseColumnCount() {
|
||||
if (currentViewType == VIEW_TYPE_GRID) {
|
||||
context?.config?.fileColumnCnt = ++(recents_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
context!!.config.fileColumnCnt += 1
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
override fun reduceColumnCount() {
|
||||
if (currentViewType == VIEW_TYPE_GRID) {
|
||||
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
context!!.config.fileColumnCnt -= 1
|
||||
columnCountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun columnCountChanged() {
|
||||
override fun columnCountChanged() {
|
||||
(recents_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt
|
||||
(activity as? MainActivity)?.refreshMenuItems()
|
||||
getRecyclerAdapter()?.apply {
|
||||
notifyItemRangeChanged(0, listItems.size)
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES
|
|||
import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS
|
||||
|
||||
const val PATH = "path"
|
||||
const val MAX_COLUMN_COUNT = 20
|
||||
const val MAX_COLUMN_COUNT = 15
|
||||
|
||||
// shared preferences
|
||||
const val SHOW_HIDDEN = "show_hidden"
|
||||
|
|
|
@ -18,6 +18,8 @@ interface ItemOperationsListener {
|
|||
|
||||
fun toggleFilenameVisibility()
|
||||
|
||||
fun columnCountChanged()
|
||||
|
||||
fun increaseColumnCount()
|
||||
|
||||
fun reduceColumnCount()
|
||||
|
|
|
@ -54,14 +54,9 @@
|
|||
android:title="@string/stop_showing_hidden"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/increase_column_count"
|
||||
android:id="@+id/column_count"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/increase_column_count"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/reduce_column_count"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/reduce_column_count"
|
||||
android:title="@string/column_count"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/more_apps_from_us"
|
||||
|
|
|
@ -35,13 +35,8 @@
|
|||
android:title="@string/stop_showing_hidden"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/increase_column_count"
|
||||
android:id="@+id/column_count"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/increase_column_count"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/reduce_column_count"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/reduce_column_count"
|
||||
android:title="@string/column_count"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
|
Loading…
Reference in a new issue