mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
rewriting the fragment to work like in other apps
This commit is contained in:
@ -20,15 +20,16 @@ import com.simplemobiletools.commons.models.RadioItem
|
|||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import com.simplemobiletools.filemanager.pro.BuildConfig
|
import com.simplemobiletools.filemanager.pro.BuildConfig
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
|
import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter
|
||||||
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
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.MAX_COLUMN_COUNT
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
||||||
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.view.*
|
import kotlinx.android.synthetic.main.items_fragment.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -42,20 +43,12 @@ class MainActivity : SimpleActivity() {
|
|||||||
private var mWasProtectionHandled = false
|
private var mWasProtectionHandled = false
|
||||||
private var searchMenuItem: MenuItem? = null
|
private var searchMenuItem: MenuItem? = null
|
||||||
|
|
||||||
private lateinit var fragment: ItemsFragment
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched(BuildConfig.APPLICATION_ID)
|
appLaunched(BuildConfig.APPLICATION_ID)
|
||||||
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
||||||
|
|
||||||
fragment = (fragment_holder as ItemsFragment).apply {
|
|
||||||
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
|
||||||
isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
|
|
||||||
isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
handleAppPasswordProtection {
|
handleAppPasswordProtection {
|
||||||
mWasProtectionHandled = it
|
mWasProtectionHandled = it
|
||||||
@ -86,6 +79,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||||
val favorites = config.favorites
|
val favorites = config.favorites
|
||||||
|
val fragment = getCurrentFragment() ?: return true
|
||||||
|
|
||||||
menu!!.apply {
|
menu!!.apply {
|
||||||
findItem(R.id.add_favorite).isVisible = !favorites.contains(fragment.currentPath)
|
findItem(R.id.add_favorite).isVisible = !favorites.contains(fragment.currentPath)
|
||||||
findItem(R.id.remove_favorite).isVisible = favorites.contains(fragment.currentPath)
|
findItem(R.id.remove_favorite).isVisible = favorites.contains(fragment.currentPath)
|
||||||
@ -112,13 +107,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
R.id.sort -> showSortingDialog()
|
R.id.sort -> showSortingDialog()
|
||||||
R.id.add_favorite -> addFavorite()
|
R.id.add_favorite -> addFavorite()
|
||||||
R.id.remove_favorite -> removeFavorite()
|
R.id.remove_favorite -> removeFavorite()
|
||||||
R.id.toggle_filename -> fragment.toggleFilenameVisibility()
|
R.id.toggle_filename -> getCurrentFragment().toggleFilenameVisibility()
|
||||||
R.id.set_as_home -> setAsHome()
|
R.id.set_as_home -> setAsHome()
|
||||||
R.id.change_view_type -> changeViewType()
|
R.id.change_view_type -> changeViewType()
|
||||||
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
||||||
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
||||||
R.id.increase_column_count -> fragment.increaseColumnCount()
|
R.id.increase_column_count -> getCurrentFragment().increaseColumnCount()
|
||||||
R.id.reduce_column_count -> fragment.reduceColumnCount()
|
R.id.reduce_column_count -> getCurrentFragment().reduceColumnCount()
|
||||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
R.id.about -> launchAbout()
|
R.id.about -> launchAbout()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
@ -128,7 +123,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
outState.putString(PICKED_PATH, (fragment_holder as ItemsFragment).currentPath)
|
outState.putString(PICKED_PATH, getCurrentFragment().currentPath)
|
||||||
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
|
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +132,17 @@ class MainActivity : SimpleActivity() {
|
|||||||
mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
|
mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
|
||||||
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
|
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
|
||||||
|
|
||||||
|
if (main_view_pager.adapter == null) {
|
||||||
|
main_view_pager.adapter = ViewPagerAdapter(this)
|
||||||
|
main_view_pager.onGlobalLayout {
|
||||||
|
restorePath(path)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restorePath(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun restorePath(path: String) {
|
||||||
if (!mWasProtectionHandled) {
|
if (!mWasProtectionHandled) {
|
||||||
handleAppPasswordProtection {
|
handleAppPasswordProtection {
|
||||||
mWasProtectionHandled = it
|
mWasProtectionHandled = it
|
||||||
@ -164,7 +170,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
fragment.searchQueryChanged(newText)
|
getCurrentFragment().searchQueryChanged(newText)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -174,13 +180,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||||
isSearchOpen = true
|
isSearchOpen = true
|
||||||
fragment.searchOpened()
|
getCurrentFragment().searchOpened()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||||
isSearchOpen = false
|
isSearchOpen = false
|
||||||
fragment.searchClosed()
|
getCurrentFragment().searchClosed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -190,7 +196,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
checkOTGPath()
|
checkOTGPath()
|
||||||
if (it) {
|
if (it) {
|
||||||
initFileManager()
|
if (main_view_pager.adapter == null) {
|
||||||
|
main_view_pager.adapter = ViewPagerAdapter(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_view_pager.onGlobalLayout {
|
||||||
|
initFileManager()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_storage_permissions)
|
toast(R.string.no_storage_permissions)
|
||||||
finish()
|
finish()
|
||||||
@ -218,6 +230,12 @@ class MainActivity : SimpleActivity() {
|
|||||||
} else {
|
} else {
|
||||||
openPath(config.homeFolder)
|
openPath(config.homeFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCurrentFragment()?.apply {
|
||||||
|
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
||||||
|
isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
|
||||||
|
isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkOTGPath() {
|
private fun checkOTGPath() {
|
||||||
@ -246,27 +264,27 @@ class MainActivity : SimpleActivity() {
|
|||||||
newPath = internalStoragePath
|
newPath = internalStoragePath
|
||||||
}
|
}
|
||||||
|
|
||||||
(fragment_holder as ItemsFragment).openPath(newPath, forceRefresh)
|
getCurrentFragment()?.openPath(newPath, forceRefresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goHome() {
|
private fun goHome() {
|
||||||
if (config.homeFolder != fragment.currentPath) {
|
if (config.homeFolder != getCurrentFragment().currentPath) {
|
||||||
openPath(config.homeFolder)
|
openPath(config.homeFolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
ChangeSortingDialog(this, fragment.currentPath) {
|
ChangeSortingDialog(this, getCurrentFragment().currentPath) {
|
||||||
fragment.refreshItems()
|
getCurrentFragment().refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFavorite() {
|
private fun addFavorite() {
|
||||||
config.addFavorite(fragment.currentPath)
|
config.addFavorite(getCurrentFragment().currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeFavorite() {
|
private fun removeFavorite() {
|
||||||
config.removeFavorite(fragment.currentPath)
|
config.removeFavorite(getCurrentFragment().currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goToFavorite() {
|
private fun goToFavorite() {
|
||||||
@ -277,7 +295,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
favorites.forEachIndexed { index, path ->
|
favorites.forEachIndexed { index, path ->
|
||||||
val visiblePath = humanizePath(path).replace("/", " / ")
|
val visiblePath = humanizePath(path).replace("/", " / ")
|
||||||
items.add(RadioItem(index, visiblePath, path))
|
items.add(RadioItem(index, visiblePath, path))
|
||||||
if (path == fragment.currentPath) {
|
if (path == getCurrentFragment().currentPath) {
|
||||||
currFavoriteIndex = index
|
currFavoriteIndex = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,13 +306,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setAsHome() {
|
private fun setAsHome() {
|
||||||
config.homeFolder = fragment.currentPath
|
config.homeFolder = getCurrentFragment().currentPath
|
||||||
toast(R.string.home_folder_updated)
|
toast(R.string.home_folder_updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun changeViewType() {
|
private fun changeViewType() {
|
||||||
ChangeViewTypeDialog(this, fragment.currentPath) {
|
ChangeViewTypeDialog(this, getCurrentFragment().currentPath) {
|
||||||
fragment.refreshItems()
|
getCurrentFragment().refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +328,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun toggleTemporarilyShowHidden(show: Boolean) {
|
private fun toggleTemporarilyShowHidden(show: Boolean) {
|
||||||
config.temporarilyShowHidden = show
|
config.temporarilyShowHidden = show
|
||||||
openPath(fragment.currentPath)
|
openPath(getCurrentFragment().currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
@ -329,7 +347,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (fragment.mView.breadcrumbs.childCount <= 1) {
|
if (getCurrentFragment().breadcrumbs.childCount <= 1) {
|
||||||
if (!wasBackJustPressed && config.pressBackTwice) {
|
if (!wasBackJustPressed && config.pressBackTwice) {
|
||||||
wasBackJustPressed = true
|
wasBackJustPressed = true
|
||||||
toast(R.string.press_back_again)
|
toast(R.string.press_back_again)
|
||||||
@ -340,8 +358,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fragment.mView.breadcrumbs.removeBreadcrumb()
|
getCurrentFragment().breadcrumbs.removeBreadcrumb()
|
||||||
openPath(fragment.mView.breadcrumbs.getLastItem().path)
|
openPath(getCurrentFragment().breadcrumbs.getLastItem().path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,6 +428,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCurrentFragment() = items_fragment
|
||||||
|
|
||||||
private fun checkWhatsNewDialog() {
|
private fun checkWhatsNewDialog() {
|
||||||
arrayListOf<Release>().apply {
|
arrayListOf<Release>().apply {
|
||||||
add(Release(26, R.string.release_26))
|
add(Release(26, R.string.release_26))
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.simplemobiletools.filemanager.pro.adapters
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.viewpager.widget.PagerAdapter
|
||||||
|
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||||
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
|
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
|
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
|
||||||
|
|
||||||
|
class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||||
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||||
|
val layout = getFragment(position)
|
||||||
|
val view = activity.layoutInflater.inflate(layout, container, false)
|
||||||
|
container.addView(view)
|
||||||
|
|
||||||
|
(view as ItemsFragment).apply {
|
||||||
|
setupFragment(activity)
|
||||||
|
setupColors(activity.config.textColor, activity.getAdjustedPrimaryColor())
|
||||||
|
}
|
||||||
|
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun destroyItem(container: ViewGroup, position: Int, item: Any) {
|
||||||
|
container.removeView(item as View)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCount() = 1
|
||||||
|
|
||||||
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||||
|
|
||||||
|
private fun getFragment(position: Int) = R.layout.items_fragment
|
||||||
|
}
|
@ -1,11 +1,9 @@
|
|||||||
package com.simplemobiletools.filemanager.pro.fragments
|
package com.simplemobiletools.filemanager.pro.fragments
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.content.Context
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.LayoutInflater
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
||||||
@ -24,7 +22,6 @@ import com.simplemobiletools.filemanager.pro.extensions.config
|
|||||||
import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot
|
import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
|
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.helpers.RootHelpers
|
||||||
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
||||||
import com.simplemobiletools.filemanager.pro.models.ListItem
|
import com.simplemobiletools.filemanager.pro.models.ListItem
|
||||||
@ -33,12 +30,13 @@ import java.io.File
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
|
class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
|
||||||
var currentPath = ""
|
var currentPath = ""
|
||||||
var isGetContentIntent = false
|
var isGetContentIntent = false
|
||||||
var isGetRingtonePicker = false
|
var isGetRingtonePicker = false
|
||||||
var isPickMultipleIntent = false
|
var isPickMultipleIntent = false
|
||||||
|
|
||||||
|
private var activity: SimpleActivity? = null
|
||||||
private var isFirstResume = true
|
private var isFirstResume = true
|
||||||
private var showHidden = false
|
private var showHidden = false
|
||||||
private var skipItemUpdating = false
|
private var skipItemUpdating = false
|
||||||
@ -49,68 +47,51 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
private var zoomListener: MyRecyclerView.MyZoomListener? = null
|
private var zoomListener: MyRecyclerView.MyZoomListener? = null
|
||||||
|
|
||||||
private var storedItems = ArrayList<ListItem>()
|
private var storedItems = ArrayList<ListItem>()
|
||||||
private var storedTextColor = 0
|
|
||||||
private var storedFontSize = 0
|
private var storedFontSize = 0
|
||||||
private var storedDateFormat = ""
|
private var storedDateFormat = ""
|
||||||
private var storedTimeFormat = ""
|
private var storedTimeFormat = ""
|
||||||
|
|
||||||
lateinit var mView: View
|
fun setupFragment(activity: SimpleActivity) {
|
||||||
|
if (this.activity == null) {
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
this.activity = activity
|
||||||
mView = inflater.inflate(R.layout.items_fragment, container, false)!!
|
|
||||||
storeStateVariables()
|
|
||||||
return mView
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
mView.apply {
|
|
||||||
items_swipe_refresh.setOnRefreshListener { refreshItems() }
|
items_swipe_refresh.setOnRefreshListener { refreshItems() }
|
||||||
items_fab.setOnClickListener { createNewItem() }
|
items_fab.setOnClickListener { createNewItem() }
|
||||||
breadcrumbs.listener = this@ItemsFragment
|
breadcrumbs.listener = this@ItemsFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
private fun storeStateVariables() {
|
||||||
outState.putString(PATH, currentPath)
|
context!!.config.apply {
|
||||||
super.onSaveInstanceState(outState)
|
storedFontSize = fontSize
|
||||||
}
|
storedDateFormat = dateFormat
|
||||||
|
storedTimeFormat = context.getTimeFormat()
|
||||||
override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
|
||||||
super.onViewStateRestored(savedInstanceState)
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
currentPath = savedInstanceState.getString(PATH)!!
|
|
||||||
storedItems.clear()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {
|
||||||
super.onResume()
|
context!!.updateTextColors(this)
|
||||||
context!!.updateTextColors(mView as ViewGroup)
|
items_fastscroller.updatePrimaryColor()
|
||||||
mView.items_fastscroller.updatePrimaryColor()
|
storedItems = ArrayList()
|
||||||
val newTextColor = context!!.config.textColor
|
getRecyclerAdapter()?.apply {
|
||||||
if (storedTextColor != newTextColor) {
|
updateTextColor(textColor)
|
||||||
storedItems = ArrayList()
|
initDrawables()
|
||||||
getRecyclerAdapter()?.apply {
|
|
||||||
updateTextColor(newTextColor)
|
|
||||||
initDrawables()
|
|
||||||
}
|
|
||||||
mView.breadcrumbs.updateColor(newTextColor)
|
|
||||||
storedTextColor = newTextColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
breadcrumbs.updateColor(textColor)
|
||||||
|
|
||||||
|
items_fastscroller.updateBubbleColors()
|
||||||
|
|
||||||
val configFontSize = context!!.config.fontSize
|
val configFontSize = context!!.config.fontSize
|
||||||
if (storedFontSize != configFontSize) {
|
if (storedFontSize != configFontSize) {
|
||||||
getRecyclerAdapter()?.updateFontSizes()
|
getRecyclerAdapter()?.updateFontSizes()
|
||||||
storedFontSize = configFontSize
|
storedFontSize = configFontSize
|
||||||
mView.breadcrumbs.updateFontSize(context!!.getTextSize())
|
breadcrumbs.updateFontSize(context!!.getTextSize())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storedDateFormat != context!!.config.dateFormat || storedTimeFormat != context!!.getTimeFormat()) {
|
if (storedDateFormat != context!!.config.dateFormat || storedTimeFormat != context!!.getTimeFormat()) {
|
||||||
getRecyclerAdapter()?.updateDateTimeFormat()
|
getRecyclerAdapter()?.updateDateTimeFormat()
|
||||||
}
|
}
|
||||||
|
|
||||||
mView.items_fastscroller.updateBubbleColors()
|
|
||||||
if (!isFirstResume) {
|
if (!isFirstResume) {
|
||||||
refreshItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
@ -118,22 +99,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
isFirstResume = false
|
isFirstResume = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
storeStateVariables()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
|
||||||
context!!.config.apply {
|
|
||||||
storedTextColor = textColor
|
|
||||||
storedFontSize = fontSize
|
|
||||||
storedDateFormat = dateFormat
|
|
||||||
storedTimeFormat = context.getTimeFormat()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun openPath(path: String, forceRefresh: Boolean = false) {
|
fun openPath(path: String, forceRefresh: Boolean = false) {
|
||||||
if (!isAdded || (activity as? BaseSimpleActivity)?.isAskingPermissions == true) {
|
if ((activity as? BaseSimpleActivity)?.isAskingPermissions == true) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +113,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
currentPath = realPath
|
currentPath = realPath
|
||||||
showHidden = context!!.config.shouldShowHidden
|
showHidden = context!!.config.shouldShowHidden
|
||||||
getItems(currentPath) { originalPath, listItems ->
|
getItems(currentPath) { originalPath, listItems ->
|
||||||
if (currentPath != originalPath || !isAdded) {
|
if (currentPath != originalPath) {
|
||||||
return@getItems
|
return@getItems
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,50 +131,48 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
|
|
||||||
private fun addItems(items: ArrayList<ListItem>, forceRefresh: Boolean = false) {
|
private fun addItems(items: ArrayList<ListItem>, forceRefresh: Boolean = false) {
|
||||||
skipItemUpdating = false
|
skipItemUpdating = false
|
||||||
mView.apply {
|
activity?.runOnUiThread {
|
||||||
activity?.runOnUiThread {
|
items_swipe_refresh?.isRefreshing = false
|
||||||
items_swipe_refresh?.isRefreshing = false
|
breadcrumbs.setBreadcrumb(currentPath)
|
||||||
breadcrumbs.setBreadcrumb(currentPath)
|
if (!forceRefresh && items.hashCode() == storedItems.hashCode()) {
|
||||||
if (!forceRefresh && items.hashCode() == storedItems.hashCode()) {
|
return@runOnUiThread
|
||||||
return@runOnUiThread
|
}
|
||||||
}
|
|
||||||
|
|
||||||
storedItems = items
|
storedItems = items
|
||||||
if (items_list.adapter == null) {
|
if (items_list.adapter == null) {
|
||||||
breadcrumbs.updateFontSize(context!!.getTextSize())
|
breadcrumbs.updateFontSize(context!!.getTextSize())
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller,
|
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller,
|
||||||
items_swipe_refresh) {
|
items_swipe_refresh) {
|
||||||
if ((it as? ListItem)?.isSectionTitle == true) {
|
if ((it as? ListItem)?.isSectionTitle == true) {
|
||||||
openDirectory(it.mPath)
|
openDirectory(it.mPath)
|
||||||
searchClosed()
|
searchClosed()
|
||||||
} else {
|
} else {
|
||||||
itemClicked(it as FileDirItem)
|
itemClicked(it as FileDirItem)
|
||||||
}
|
|
||||||
}.apply {
|
|
||||||
setupZoomListener(zoomListener)
|
|
||||||
items_list.adapter = this
|
|
||||||
}
|
}
|
||||||
|
}.apply {
|
||||||
|
setupZoomListener(zoomListener)
|
||||||
|
items_list.adapter = this
|
||||||
|
}
|
||||||
|
|
||||||
items_list.scheduleLayoutAnimation()
|
items_list.scheduleLayoutAnimation()
|
||||||
items_fastscroller.setViews(items_list, items_swipe_refresh) {
|
items_fastscroller.setViews(items_list, items_swipe_refresh) {
|
||||||
val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it)
|
val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it)
|
||||||
items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, storedDateFormat, storedTimeFormat) ?: "")
|
items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, storedDateFormat, storedTimeFormat) ?: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath])
|
getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath])
|
||||||
items_list.onGlobalLayout {
|
items_list.onGlobalLayout {
|
||||||
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
||||||
calculateContentHeight(storedItems)
|
calculateContentHeight(storedItems)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
|
private fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
|
||||||
|
|
||||||
private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyGridLayoutManager)
|
private fun getRecyclerLayoutManager() = (items_list.layoutManager as MyGridLayoutManager)
|
||||||
|
|
||||||
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
||||||
skipItemUpdating = false
|
skipItemUpdating = false
|
||||||
@ -314,7 +279,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
activity?.toast(R.string.select_audio_file)
|
activity?.toast(R.string.select_audio_file)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
activity!!.tryOpenPathIntent(path, false)
|
activity?.tryOpenPathIntent(path, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,19 +302,15 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
searchText.isEmpty() -> activity?.runOnUiThread {
|
searchText.isEmpty() -> activity?.runOnUiThread {
|
||||||
mView.apply {
|
items_list.beVisible()
|
||||||
items_list.beVisible()
|
getRecyclerAdapter()?.updateItems(storedItems)
|
||||||
getRecyclerAdapter()?.updateItems(storedItems)
|
items_placeholder.beGone()
|
||||||
items_placeholder.beGone()
|
items_placeholder_2.beGone()
|
||||||
items_placeholder_2.beGone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
searchText.length == 1 -> activity?.runOnUiThread {
|
searchText.length == 1 -> activity?.runOnUiThread {
|
||||||
mView.apply {
|
items_list.beGone()
|
||||||
items_list.beGone()
|
items_placeholder.beVisible()
|
||||||
items_placeholder.beVisible()
|
items_placeholder_2.beVisible()
|
||||||
items_placeholder_2.beVisible()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val files = searchFiles(searchText, currentPath)
|
val files = searchFiles(searchText, currentPath)
|
||||||
@ -383,15 +344,13 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
getRecyclerAdapter()?.updateItems(listItems, text)
|
getRecyclerAdapter()?.updateItems(listItems, text)
|
||||||
mView.apply {
|
items_list.beVisibleIf(listItems.isNotEmpty())
|
||||||
items_list.beVisibleIf(listItems.isNotEmpty())
|
items_placeholder.beVisibleIf(listItems.isEmpty())
|
||||||
items_placeholder.beVisibleIf(listItems.isEmpty())
|
items_placeholder_2.beGone()
|
||||||
items_placeholder_2.beGone()
|
|
||||||
|
|
||||||
items_list.onGlobalLayout {
|
items_list.onGlobalLayout {
|
||||||
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
||||||
calculateContentHeight(listItems)
|
calculateContentHeight(listItems)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,7 +396,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
fun searchOpened() {
|
fun searchOpened() {
|
||||||
isSearchOpen = true
|
isSearchOpen = true
|
||||||
lastSearchedText = ""
|
lastSearchedText = ""
|
||||||
mView.items_swipe_refresh.isEnabled = false
|
items_swipe_refresh.isEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun searchClosed() {
|
fun searchClosed() {
|
||||||
@ -449,12 +408,10 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
skipItemUpdating = false
|
skipItemUpdating = false
|
||||||
lastSearchedText = ""
|
lastSearchedText = ""
|
||||||
|
|
||||||
mView.apply {
|
items_swipe_refresh.isEnabled = true
|
||||||
items_swipe_refresh.isEnabled = true
|
items_list.beVisible()
|
||||||
items_list.beVisible()
|
items_placeholder.beGone()
|
||||||
items_placeholder.beGone()
|
items_placeholder_2.beGone()
|
||||||
items_placeholder_2.beGone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNewItem() {
|
private fun createNewItem() {
|
||||||
@ -467,7 +424,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRecyclerAdapter() = mView.items_list.adapter as? ItemsAdapter
|
private fun getRecyclerAdapter() = items_list.adapter as? ItemsAdapter
|
||||||
|
|
||||||
private fun setupLayoutManager() {
|
private fun setupLayoutManager() {
|
||||||
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
|
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
|
||||||
@ -478,13 +435,13 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
setupListLayoutManager()
|
setupListLayoutManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
mView.items_list.adapter = null
|
items_list.adapter = null
|
||||||
initZoomListener()
|
initZoomListener()
|
||||||
addItems(storedItems, true)
|
addItems(storedItems, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupGridLayoutManager() {
|
private fun setupGridLayoutManager() {
|
||||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
val layoutManager = items_list.layoutManager as MyGridLayoutManager
|
||||||
layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3
|
layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3
|
||||||
|
|
||||||
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||||
@ -499,14 +456,14 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupListLayoutManager() {
|
private fun setupListLayoutManager() {
|
||||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
val layoutManager = items_list.layoutManager as MyGridLayoutManager
|
||||||
layoutManager.spanCount = 1
|
layoutManager.spanCount = 1
|
||||||
zoomListener = null
|
zoomListener = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initZoomListener() {
|
private fun initZoomListener() {
|
||||||
if (context?.config?.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
|
if (context?.config?.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
|
||||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
val layoutManager = items_list.layoutManager as MyGridLayoutManager
|
||||||
zoomListener = object : MyRecyclerView.MyZoomListener {
|
zoomListener = object : MyRecyclerView.MyZoomListener {
|
||||||
override fun zoomIn() {
|
override fun zoomIn() {
|
||||||
if (layoutManager.spanCount > 1) {
|
if (layoutManager.spanCount > 1) {
|
||||||
@ -528,20 +485,20 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateContentHeight(items: MutableList<ListItem>) {
|
private fun calculateContentHeight(items: MutableList<ListItem>) {
|
||||||
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
|
val layoutManager = items_list.layoutManager as MyGridLayoutManager
|
||||||
val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0
|
val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0
|
||||||
val fullHeight = ((items.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight
|
val fullHeight = ((items.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight
|
||||||
mView.items_fastscroller.setContentHeight(fullHeight)
|
items_fastscroller.setContentHeight(fullHeight)
|
||||||
mView.items_fastscroller.setScrollToY(mView.items_list.computeVerticalScrollOffset())
|
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun increaseColumnCount() {
|
fun increaseColumnCount() {
|
||||||
context?.config?.fileColumnCnt = ++(mView.items_list.layoutManager as MyGridLayoutManager).spanCount
|
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||||
columnCountChanged()
|
columnCountChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reduceColumnCount() {
|
fun reduceColumnCount() {
|
||||||
context?.config?.fileColumnCnt = --(mView.items_list.layoutManager as MyGridLayoutManager).spanCount
|
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||||
columnCountChanged()
|
columnCountChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +522,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
openPath(it)
|
openPath(it)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val item = mView.breadcrumbs.getChildAt(id).tag as FileDirItem
|
val item = breadcrumbs.getChildAt(id).tag as FileDirItem
|
||||||
openPath(item.path)
|
openPath(item.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<fragment
|
<com.simplemobiletools.commons.views.MyViewPager
|
||||||
android:id="@+id/fragment_holder"
|
android:id="@+id/main_view_pager"
|
||||||
android:name="com.simplemobiletools.filemanager.pro.fragments.ItemsFragment"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.simplemobiletools.filemanager.pro.fragments.ItemsFragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/items_holder"
|
android:id="@+id/items_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -83,4 +83,4 @@
|
|||||||
android:layout_margin="@dimen/activity_margin"
|
android:layout_margin="@dimen/activity_margin"
|
||||||
android:src="@drawable/ic_plus_vector" />
|
android:src="@drawable/ic_plus_vector" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</com.simplemobiletools.filemanager.pro.fragments.ItemsFragment>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/recents_wrapper"
|
android:id="@+id/recents_wrapper"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/recents_placeholder"
|
android:id="@+id/recents_placeholder"
|
||||||
|
Reference in New Issue
Block a user