allow changing the column count with gestures and menu buttons
This commit is contained in:
parent
07ba82f4ee
commit
3f849da18f
|
@ -58,7 +58,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.31.15'
|
||||
implementation 'com.simplemobiletools:commons:5.31.16'
|
||||
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
||||
implementation 'com.github.Stericson:RootShell:1.6'
|
||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
|||
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
||||
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
|
||||
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
|
||||
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
||||
import com.stericson.RootTools.RootTools
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
@ -95,6 +96,9 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
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.viewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT
|
||||
findItem(R.id.reduce_column_count).isVisible = config.viewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -111,6 +115,8 @@ 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 -> fragment.increaseColumnCount()
|
||||
R.id.reduce_column_count -> fragment.reduceColumnCount()
|
||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
R.id.about -> launchAbout()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.simplemobiletools.commons.helpers.isRPlus
|
|||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.commons.views.Breadcrumbs
|
||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.filemanager.pro.R
|
||||
import com.simplemobiletools.filemanager.pro.activities.MainActivity
|
||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||
|
@ -24,6 +25,7 @@ import com.simplemobiletools.filemanager.pro.dialogs.CreateNewItemDialog
|
|||
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||
import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot
|
||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
||||
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
|
||||
import com.simplemobiletools.filemanager.pro.helpers.PATH
|
||||
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
||||
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
||||
|
@ -45,6 +47,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
private var isSearchOpen = false
|
||||
private var lastSearchedText = ""
|
||||
private var scrollStates = HashMap<String, Parcelable>()
|
||||
private var zoomListener: MyRecyclerView.MyZoomListener? = null
|
||||
|
||||
private var storedItems = ArrayList<ListItem>()
|
||||
private var storedTextColor = 0
|
||||
|
@ -69,6 +72,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
breadcrumbs.updateFontSize(context!!.getTextSize())
|
||||
}
|
||||
setupLayoutManager(false)
|
||||
initZoomListener()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
@ -173,6 +177,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
|
||||
itemClicked(it as FileDirItem)
|
||||
}.apply {
|
||||
setupZoomListener(zoomListener)
|
||||
items_list.adapter = this
|
||||
}
|
||||
|
||||
|
@ -421,12 +426,50 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
|
||||
private fun setupGridLayoutManager() {
|
||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
||||
layoutManager.spanCount = 4
|
||||
layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3
|
||||
}
|
||||
|
||||
private fun setupListLayoutManager() {
|
||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
||||
layoutManager.spanCount = 1
|
||||
zoomListener = null
|
||||
}
|
||||
|
||||
private fun initZoomListener() {
|
||||
if (context?.config?.viewType == VIEW_TYPE_GRID) {
|
||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
||||
zoomListener = object : MyRecyclerView.MyZoomListener {
|
||||
override fun zoomIn() {
|
||||
if (layoutManager.spanCount > 1) {
|
||||
reduceColumnCount()
|
||||
getRecyclerAdapter()?.finishActMode()
|
||||
}
|
||||
}
|
||||
|
||||
override fun zoomOut() {
|
||||
if (layoutManager.spanCount < MAX_COLUMN_COUNT) {
|
||||
increaseColumnCount()
|
||||
getRecyclerAdapter()?.finishActMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
zoomListener = null
|
||||
}
|
||||
}
|
||||
|
||||
fun increaseColumnCount() {
|
||||
context?.config?.fileColumnCnt = ++(mView.items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
columnCountChanged()
|
||||
}
|
||||
|
||||
fun reduceColumnCount() {
|
||||
context?.config?.fileColumnCnt = --(mView.items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||
columnCountChanged()
|
||||
}
|
||||
|
||||
private fun columnCountChanged() {
|
||||
mView.items_list.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun breadcrumbClicked(id: Int) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.filemanager.pro.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import com.simplemobiletools.commons.extensions.getInternalStoragePath
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
||||
|
@ -90,4 +91,22 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
}
|
||||
|
||||
fun hasCustomViewType(path: String) = prefs.contains(VIEW_TYPE_PREFIX + path.toLowerCase())
|
||||
|
||||
var fileColumnCnt: Int
|
||||
get() = prefs.getInt(getFileColumnsField(), getDefaultFileColumnCount())
|
||||
set(fileColumnCnt) = prefs.edit().putInt(getFileColumnsField(), fileColumnCnt).apply()
|
||||
|
||||
private fun getFileColumnsField(): String {
|
||||
val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
return if (isPortrait) {
|
||||
FILE_COLUMN_CNT
|
||||
} else {
|
||||
FILE_LANDSCAPE_COLUMN_CNT
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDefaultFileColumnCount(): Int {
|
||||
val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
return if (isPortrait) 3 else 5
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.filemanager.pro.helpers
|
||||
|
||||
const val PATH = "path"
|
||||
const val MAX_COLUMN_COUNT = 20
|
||||
|
||||
// shared preferences
|
||||
const val SHOW_HIDDEN = "show_hidden"
|
||||
|
@ -11,6 +12,8 @@ const val ENABLE_ROOT_ACCESS = "enable_root_access"
|
|||
const val EDITOR_TEXT_ZOOM = "editor_text_zoom"
|
||||
const val VIEW_TYPE = "view_type"
|
||||
const val VIEW_TYPE_PREFIX = "view_type_folder_"
|
||||
const val FILE_COLUMN_CNT = "file_column_cnt"
|
||||
const val FILE_LANDSCAPE_COLUMN_CNT = "file_landscape_column_cnt"
|
||||
|
||||
// open as
|
||||
const val OPEN_AS_DEFAULT = 0
|
||||
|
|
|
@ -48,6 +48,14 @@
|
|||
android:id="@+id/stop_showing_hidden"
|
||||
android:title="@string/stop_showing_hidden"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/increase_column_count"
|
||||
android:title="@string/increase_column_count"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/reduce_column_count"
|
||||
android:title="@string/reduce_column_count"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:title="@string/settings"
|
||||
|
|
Loading…
Reference in New Issue