moving some functions from MyViewPagerFragment to ItemOperationsListener

This commit is contained in:
tibbi 2021-10-10 22:58:03 +02:00
parent 1af8303bbb
commit dbfab9c0cf
4 changed files with 24 additions and 37 deletions

View File

@ -33,6 +33,7 @@ import com.simplemobiletools.filemanager.pro.fragments.MyViewPagerFragment
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
import com.simplemobiletools.filemanager.pro.helpers.tabsList import com.simplemobiletools.filemanager.pro.helpers.tabsList
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.stericson.RootTools.RootTools import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.items_fragment.* import kotlinx.android.synthetic.main.items_fragment.*
@ -94,13 +95,13 @@ class MainActivity : SimpleActivity() {
if (storedFontSize != config.fontSize) { if (storedFontSize != config.fontSize) {
getAllFragments().forEach { getAllFragments().forEach {
it?.setupFontSize() (it as? ItemOperationsListener)?.setupFontSize()
} }
} }
if (storedDateFormat != config.dateFormat || storedTimeFormat != getTimeFormat()) { if (storedDateFormat != config.dateFormat || storedTimeFormat != getTimeFormat()) {
getAllFragments().forEach { getAllFragments().forEach {
it?.setupDateTimeFormat() (it as? ItemOperationsListener)?.setupDateTimeFormat()
} }
} }
@ -237,7 +238,7 @@ class MainActivity : SimpleActivity() {
override fun onQueryTextChange(newText: String): Boolean { override fun onQueryTextChange(newText: String): Boolean {
if (isSearchOpen) { if (isSearchOpen) {
getCurrentFragment()?.searchQueryChanged(newText) (getCurrentFragment() as? ItemOperationsListener)?.searchQueryChanged(newText)
} }
return true return true
} }
@ -342,7 +343,7 @@ class MainActivity : SimpleActivity() {
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) { override fun onPageScrollStateChanged(state: Int) {
if (isSearchOpen) { if (isSearchOpen) {
getCurrentFragment()?.searchQueryChanged("") (getCurrentFragment() as? ItemOperationsListener)?.searchQueryChanged("")
searchMenuItem?.collapseActionView() searchMenuItem?.collapseActionView()
} }
} }
@ -352,7 +353,7 @@ class MainActivity : SimpleActivity() {
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
main_tabs_holder.getTabAt(position)?.select() main_tabs_holder.getTabAt(position)?.select()
getAllFragments().forEach { getAllFragments().forEach {
it?.finishActMode() (it as? ItemOperationsListener)?.finishActMode()
} }
invalidateOptionsMenu() invalidateOptionsMenu()
} }
@ -463,19 +464,19 @@ class MainActivity : SimpleActivity() {
private fun toggleFilenameVisibility() { private fun toggleFilenameVisibility() {
config.displayFilenames = !config.displayFilenames config.displayFilenames = !config.displayFilenames
getAllFragments().forEach { getAllFragments().forEach {
it?.toggleFilenameVisibility() (it as? ItemOperationsListener)?.toggleFilenameVisibility()
} }
} }
private fun increaseColumnCount() { private fun increaseColumnCount() {
getAllFragments().forEach { getAllFragments().forEach {
it?.increaseColumnCount() (it as? ItemOperationsListener)?.increaseColumnCount()
} }
} }
private fun reduceColumnCount() { private fun reduceColumnCount() {
getAllFragments().forEach { getAllFragments().forEach {
it?.reduceColumnCount() (it as? ItemOperationsListener)?.reduceColumnCount()
} }
} }

View File

@ -38,19 +38,5 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
abstract fun setupColors(textColor: Int, primaryColor: Int) abstract fun setupColors(textColor: Int, primaryColor: Int)
abstract fun setupFontSize()
abstract fun setupDateTimeFormat()
abstract fun searchQueryChanged(text: String)
abstract fun finishActMode()
abstract fun toggleFilenameVisibility()
abstract fun increaseColumnCount()
abstract fun reduceColumnCount()
abstract fun refreshItems() abstract fun refreshItems()
} }

View File

@ -15,21 +15,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun setupColors(textColor: Int, primaryColor: Int) {} override fun setupColors(textColor: Int, primaryColor: Int) {}
override fun toggleFilenameVisibility() {} private fun getMediaTypeSize(uri: Uri): Long {
override fun increaseColumnCount() {}
override fun reduceColumnCount() {}
override fun setupFontSize() {}
override fun setupDateTimeFormat() {}
override fun searchQueryChanged(text: String) {}
override fun finishActMode() {}
private fun getFileTypeSize(uri: Uri): Long {
val projection = arrayOf( val projection = arrayOf(
MediaStore.Files.FileColumns.SIZE MediaStore.Files.FileColumns.SIZE
) )

View File

@ -9,4 +9,18 @@ interface ItemOperationsListener {
fun deleteFiles(files: ArrayList<FileDirItem>) fun deleteFiles(files: ArrayList<FileDirItem>)
fun selectedPaths(paths: ArrayList<String>) fun selectedPaths(paths: ArrayList<String>)
fun searchQueryChanged(text: String)
fun setupDateTimeFormat()
fun setupFontSize()
fun toggleFilenameVisibility()
fun increaseColumnCount()
fun reduceColumnCount()
fun finishActMode()
} }