mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-04-25 07:28:47 +02:00
keep updating a single fragment instead of creating new ones
This commit is contained in:
parent
c4ee6f868f
commit
72fb8256d1
@ -3,74 +3,66 @@ package com.simplemobiletools.filemanager.activities
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Parcelable
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection
|
||||||
|
import com.simplemobiletools.commons.extensions.storeStoragePaths
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
|
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
|
||||||
|
import com.simplemobiletools.commons.helpers.LICENSE_PATTERN
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import com.simplemobiletools.commons.views.Breadcrumbs
|
|
||||||
import com.simplemobiletools.filemanager.BuildConfig
|
import com.simplemobiletools.filemanager.BuildConfig
|
||||||
import com.simplemobiletools.filemanager.PATH
|
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.SCROLL_STATE
|
|
||||||
import com.simplemobiletools.filemanager.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.filemanager.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.filemanager.extensions.config
|
import com.simplemobiletools.filemanager.extensions.config
|
||||||
import com.simplemobiletools.filemanager.fragments.ItemsFragment
|
import com.simplemobiletools.filemanager.fragments.ItemsFragment
|
||||||
import com.simplemobiletools.filemanager.helpers.RootHelpers
|
import com.simplemobiletools.filemanager.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 java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
|
class MainActivity : SimpleActivity() {
|
||||||
private val BACK_PRESS_TIMEOUT = 5000
|
private val BACK_PRESS_TIMEOUT = 5000
|
||||||
|
|
||||||
private var latestFragment: ItemsFragment? = null
|
|
||||||
private var scrollStates = HashMap<String, Parcelable>()
|
|
||||||
private var storedTextColor = 0
|
|
||||||
private var currentPath = ""
|
|
||||||
private var wasBackJustPressed = false
|
private var wasBackJustPressed = false
|
||||||
|
|
||||||
|
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)
|
||||||
storeStoragePaths()
|
storeStoragePaths()
|
||||||
storeConfigVariables()
|
|
||||||
breadcrumbs.listener = this
|
fragment = fragment_holder as ItemsFragment
|
||||||
tryInitFileManager()
|
tryInitFileManager()
|
||||||
checkWhatsNewDialog()
|
checkWhatsNewDialog()
|
||||||
checkIfRootAvailable()
|
checkIfRootAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
updateTextColors(main_screen)
|
|
||||||
if (storedTextColor != config.textColor) {
|
|
||||||
storedTextColor = config.textColor
|
|
||||||
breadcrumbs.textColor = storedTextColor
|
|
||||||
openPath(currentPath)
|
|
||||||
}
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
storeConfigVariables()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
config.temporarilyShowHidden = false
|
config.temporarilyShowHidden = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeConfigVariables() {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
storedTextColor = config.textColor
|
menuInflater.inflate(R.menu.menu, menu)
|
||||||
|
|
||||||
|
val favorites = config.favorites
|
||||||
|
menu.apply {
|
||||||
|
findItem(R.id.add_favorite).isVisible = !favorites.contains(fragment.currentPath)
|
||||||
|
findItem(R.id.remove_favorite).isVisible = favorites.contains(fragment.currentPath)
|
||||||
|
findItem(R.id.go_to_favorite).isVisible = favorites.isNotEmpty()
|
||||||
|
|
||||||
|
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
|
||||||
|
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryInitFileManager() {
|
private fun tryInitFileManager() {
|
||||||
@ -89,44 +81,10 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openPath(path: String) {
|
private fun openPath(path: String) {
|
||||||
val realPath = if (path.length > 1) path.trimEnd('/') else path
|
(fragment_holder as ItemsFragment).openPath(path)
|
||||||
breadcrumbs.setBreadcrumb(realPath)
|
|
||||||
val bundle = Bundle()
|
|
||||||
bundle.putString(PATH, realPath)
|
|
||||||
|
|
||||||
if (scrollStates.containsKey(realPath)) {
|
|
||||||
bundle.putParcelable(SCROLL_STATE, scrollStates[realPath])
|
|
||||||
}
|
|
||||||
|
|
||||||
if (latestFragment != null) {
|
|
||||||
scrollStates.put(latestFragment!!.mPath.trimEnd('/'), latestFragment!!.getScrollState())
|
|
||||||
}
|
|
||||||
|
|
||||||
latestFragment = ItemsFragment().apply {
|
|
||||||
arguments = bundle
|
|
||||||
setListener(this@MainActivity)
|
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, this).addToBackStack(realPath).commitAllowingStateLoss()
|
|
||||||
}
|
|
||||||
currentPath = realPath
|
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
||||||
menuInflater.inflate(R.menu.menu, menu)
|
|
||||||
|
|
||||||
val favorites = config.favorites
|
|
||||||
menu.apply {
|
|
||||||
findItem(R.id.add_favorite).isVisible = !favorites.contains(currentPath)
|
|
||||||
findItem(R.id.remove_favorite).isVisible = favorites.contains(currentPath)
|
|
||||||
findItem(R.id.go_to_favorite).isVisible = favorites.isNotEmpty()
|
|
||||||
|
|
||||||
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
|
|
||||||
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.go_home -> goHome()
|
R.id.go_home -> goHome()
|
||||||
@ -145,27 +103,23 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun goHome() {
|
private fun goHome() {
|
||||||
if (config.homeFolder != currentPath)
|
if (config.homeFolder != fragment.currentPath)
|
||||||
openPath(config.homeFolder)
|
openPath(config.homeFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
ChangeSortingDialog(this, currentPath) {
|
ChangeSortingDialog(this, fragment.currentPath) {
|
||||||
if (latestFragment != null) {
|
fragment.refreshItems()
|
||||||
latestFragment!!.fillItems()
|
|
||||||
} else {
|
|
||||||
openPath(currentPath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFavorite() {
|
private fun addFavorite() {
|
||||||
config.addFavorite(currentPath)
|
config.addFavorite(fragment.currentPath)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeFavorite() {
|
private fun removeFavorite() {
|
||||||
config.removeFavorite(currentPath)
|
config.removeFavorite(fragment.currentPath)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +130,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||||||
|
|
||||||
favorites.forEachIndexed { index, path ->
|
favorites.forEachIndexed { index, path ->
|
||||||
items.add(RadioItem(index, path, path))
|
items.add(RadioItem(index, path, path))
|
||||||
if (path == currentPath) {
|
if (path == fragment.currentPath) {
|
||||||
currFavoriteIndex = index
|
currFavoriteIndex = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,7 +141,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setAsHome() {
|
private fun setAsHome() {
|
||||||
config.homeFolder = currentPath
|
config.homeFolder = fragment.currentPath
|
||||||
toast(R.string.home_folder_updated)
|
toast(R.string.home_folder_updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,16 +157,16 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||||||
|
|
||||||
private fun toggleTemporarilyShowHidden(show: Boolean) {
|
private fun toggleTemporarilyShowHidden(show: Boolean) {
|
||||||
config.temporarilyShowHidden = show
|
config.temporarilyShowHidden = show
|
||||||
openPath(currentPath)
|
openPath(fragment.currentPath)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME)
|
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_PATTERN, BuildConfig.VERSION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (breadcrumbs.childCount <= 1) {
|
if (fragment.breadcrumbs.childCount <= 1) {
|
||||||
if (!wasBackJustPressed) {
|
if (!wasBackJustPressed) {
|
||||||
wasBackJustPressed = true
|
wasBackJustPressed = true
|
||||||
toast(R.string.press_back_again)
|
toast(R.string.press_back_again)
|
||||||
@ -221,23 +175,8 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
breadcrumbs.removeBreadcrumb()
|
fragment.breadcrumbs.removeBreadcrumb()
|
||||||
openPath(breadcrumbs.lastItem.path)
|
openPath(fragment.breadcrumbs.lastItem.path)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun itemClicked(item: FileDirItem) {
|
|
||||||
openPath(item.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun breadcrumbClicked(id: Int) {
|
|
||||||
if (id == 0) {
|
|
||||||
StoragePickerDialog(this@MainActivity, currentPath) {
|
|
||||||
openPath(it)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val item = breadcrumbs.getChildAt(id).tag as FileDirItem
|
|
||||||
openPath(item.path)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,25 +40,26 @@ import java.util.zip.ZipOutputStream
|
|||||||
|
|
||||||
class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDirItem>, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) :
|
class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDirItem>, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) :
|
||||||
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
|
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
|
||||||
val multiSelector = MultiSelector()
|
private var textColor = activity.config.textColor
|
||||||
val config = activity.config
|
|
||||||
|
|
||||||
var actMode: ActionMode? = null
|
private val multiSelector = MultiSelector()
|
||||||
var itemViews = SparseArray<View>()
|
private val config = activity.config
|
||||||
val selectedPositions = HashSet<Int>()
|
|
||||||
|
|
||||||
var textColor = activity.config.textColor
|
private var actMode: ActionMode? = null
|
||||||
|
private var itemViews = SparseArray<View>()
|
||||||
|
private val selectedPositions = HashSet<Int>()
|
||||||
|
|
||||||
private val folderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder, textColor)
|
lateinit private var folderDrawable: Drawable
|
||||||
private val fileDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_file, textColor)
|
lateinit private var fileDrawable: Drawable
|
||||||
|
|
||||||
fun toggleItemSelection(select: Boolean, pos: Int) {
|
fun toggleItemSelection(select: Boolean, pos: Int) {
|
||||||
itemViews[pos]?.item_frame?.isSelected = select
|
itemViews[pos]?.item_frame?.isSelected = select
|
||||||
|
|
||||||
if (select)
|
if (select) {
|
||||||
selectedPositions.add(pos)
|
selectedPositions.add(pos)
|
||||||
else
|
} else {
|
||||||
selectedPositions.remove(pos)
|
selectedPositions.remove(pos)
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedPositions.isEmpty()) {
|
if (selectedPositions.isEmpty()) {
|
||||||
actMode?.finish()
|
actMode?.finish()
|
||||||
@ -74,6 +75,17 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
initDrawables()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateTextColor(color: Int) {
|
||||||
|
textColor = color
|
||||||
|
initDrawables()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initDrawables() {
|
||||||
|
folderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder, textColor)
|
||||||
|
fileDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_file, textColor)
|
||||||
folderDrawable.alpha = 180
|
folderDrawable.alpha = 180
|
||||||
fileDrawable.alpha = 180
|
fileDrawable.alpha = 180
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.fragments
|
|||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
@ -13,12 +12,15 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
||||||
|
import com.simplemobiletools.commons.extensions.deleteFiles
|
||||||
|
import com.simplemobiletools.commons.extensions.getFilenameExtension
|
||||||
|
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
import com.simplemobiletools.commons.views.Breadcrumbs
|
||||||
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||||
import com.simplemobiletools.filemanager.PATH
|
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.SCROLL_STATE
|
|
||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
||||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
||||||
@ -29,43 +31,47 @@ import com.stericson.RootTools.RootTools
|
|||||||
import kotlinx.android.synthetic.main.items_fragment.*
|
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.HashMap
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
|
||||||
private var mListener: ItemInteractionListener? = null
|
var currentPath = ""
|
||||||
private var mStoredTextColor = 0
|
|
||||||
private var mShowHidden = false
|
|
||||||
private var mItems = ArrayList<FileDirItem>()
|
|
||||||
private var fragmentView: View? = null
|
|
||||||
|
|
||||||
var mPath = ""
|
private var storedTextColor = 0
|
||||||
|
private var showHidden = false
|
||||||
|
private var storedItems = ArrayList<FileDirItem>()
|
||||||
|
private var scrollStates = HashMap<String, Parcelable>()
|
||||||
|
|
||||||
|
private lateinit var mView: View
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
fragmentView = inflater!!.inflate(R.layout.items_fragment, container, false)!!
|
mView = inflater!!.inflate(R.layout.items_fragment, container, false)!!
|
||||||
storeConfigVariables()
|
storeConfigVariables()
|
||||||
return fragmentView!!
|
return mView
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
fillItems()
|
mView.apply {
|
||||||
|
items_swipe_refresh.setOnRefreshListener({ refreshItems() })
|
||||||
items_swipe_refresh.setOnRefreshListener({ fillItems() })
|
items_fab.setOnClickListener { createNewItem() }
|
||||||
items_fab.setOnClickListener { createNewItem() }
|
breadcrumbs.listener = this@ItemsFragment
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
val config = context.config
|
val config = context.config
|
||||||
if (mShowHidden != config.shouldShowHidden) {
|
if (showHidden != config.shouldShowHidden) {
|
||||||
mShowHidden = !mShowHidden
|
showHidden = !showHidden
|
||||||
fillItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
context.updateTextColors(items_holder)
|
|
||||||
if (mStoredTextColor != config.textColor) {
|
if (storedTextColor != config.textColor) {
|
||||||
mItems = ArrayList()
|
storedItems = ArrayList()
|
||||||
fillItems()
|
(items_list.adapter as ItemsAdapter).updateTextColor(config.textColor)
|
||||||
mStoredTextColor = config.textColor
|
refreshItems()
|
||||||
|
storedTextColor = config.textColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,64 +81,72 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun storeConfigVariables() {
|
private fun storeConfigVariables() {
|
||||||
mShowHidden = context.config.shouldShowHidden
|
showHidden = context.config.shouldShowHidden
|
||||||
mStoredTextColor = context.config.textColor
|
storedTextColor = context.config.textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fillItems() {
|
fun openPath(path: String) {
|
||||||
if (activity == null || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed))
|
var realPath = path.trimEnd('/')
|
||||||
return
|
if (realPath.isEmpty())
|
||||||
|
realPath = "/"
|
||||||
|
|
||||||
mPath = arguments.getString(PATH)
|
scrollStates.put(currentPath, getScrollState())
|
||||||
getItems(mPath) {
|
currentPath = realPath
|
||||||
|
showHidden = context.config.shouldShowHidden
|
||||||
|
getItems(currentPath) {
|
||||||
if (!isAdded)
|
if (!isAdded)
|
||||||
return@getItems
|
return@getItems
|
||||||
|
|
||||||
val newItems = it
|
FileDirItem.sorting = context.config.getFolderSorting(currentPath)
|
||||||
FileDirItem.sorting = context.config.getFolderSorting(mPath)
|
it.sort()
|
||||||
newItems.sort()
|
activity.runOnUiThread {
|
||||||
|
addItems(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fragmentView.apply {
|
private fun addItems(items: ArrayList<FileDirItem>) {
|
||||||
activity?.runOnUiThread {
|
mView.apply {
|
||||||
items_swipe_refresh?.isRefreshing = false
|
activity?.runOnUiThread {
|
||||||
if (newItems.hashCode() == mItems.hashCode()) {
|
items_swipe_refresh?.isRefreshing = false
|
||||||
return@runOnUiThread
|
if (items.hashCode() == storedItems.hashCode()) {
|
||||||
}
|
return@runOnUiThread
|
||||||
|
}
|
||||||
|
|
||||||
mItems = newItems
|
mView.breadcrumbs.setBreadcrumb(currentPath)
|
||||||
|
storedItems = items
|
||||||
val currAdapter = items_list.adapter
|
val currAdapter = items_list.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
items_list.apply {
|
items_list.apply {
|
||||||
this.adapter = ItemsAdapter(activity as SimpleActivity, mItems, this@ItemsFragment) {
|
this.adapter = ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment) {
|
||||||
itemClicked(it)
|
itemClicked(it)
|
||||||
}
|
|
||||||
|
|
||||||
DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply {
|
|
||||||
setDrawable(context.resources.getDrawable(com.simplemobiletools.commons.R.drawable.divider))
|
|
||||||
addItemDecoration(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
isDragSelectionEnabled = true
|
|
||||||
}
|
}
|
||||||
items_fastscroller.setViews(items_list, items_swipe_refresh)
|
|
||||||
setupRecyclerViewListener()
|
|
||||||
} else {
|
|
||||||
val state = (items_list.layoutManager as LinearLayoutManager).onSaveInstanceState()
|
|
||||||
(currAdapter as ItemsAdapter).updateItems(mItems)
|
|
||||||
(items_list.layoutManager as LinearLayoutManager).onRestoreInstanceState(state)
|
|
||||||
}
|
|
||||||
|
|
||||||
getRecyclerLayoutManager().onRestoreInstanceState(arguments.getParcelable<Parcelable>(SCROLL_STATE))
|
DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply {
|
||||||
|
setDrawable(context.resources.getDrawable(com.simplemobiletools.commons.R.drawable.divider))
|
||||||
|
addItemDecoration(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
isDragSelectionEnabled = true
|
||||||
|
}
|
||||||
|
items_fastscroller.setViews(items_list, items_swipe_refresh)
|
||||||
|
setupRecyclerViewListener()
|
||||||
|
} else {
|
||||||
|
(currAdapter as ItemsAdapter).updateItems(storedItems)
|
||||||
|
|
||||||
|
val savedState = scrollStates[currentPath]
|
||||||
|
if (savedState != null) {
|
||||||
|
getRecyclerLayoutManager().onRestoreInstanceState(savedState)
|
||||||
|
} else {
|
||||||
|
getRecyclerLayoutManager().scrollToPosition(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRecyclerLayoutManager() = (fragmentView?.items_list?.layoutManager as LinearLayoutManager)
|
|
||||||
|
|
||||||
private fun setupRecyclerViewListener() {
|
private fun setupRecyclerViewListener() {
|
||||||
fragmentView?.items_list?.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener {
|
mView.items_list?.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener {
|
||||||
override fun zoomIn() {
|
override fun zoomIn() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -155,16 +169,14 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
|
|
||||||
fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
|
fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
|
||||||
|
|
||||||
fun setListener(listener: ItemInteractionListener) {
|
private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as LinearLayoutManager)
|
||||||
mListener = listener
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
||||||
Thread({
|
Thread({
|
||||||
if (!context.config.enableRootAccess || !context.isPathOnRoot(path)) {
|
if (!context.config.enableRootAccess || !context.isPathOnRoot(path)) {
|
||||||
getRegularItemsOf(path, callback)
|
getRegularItemsOf(path, callback)
|
||||||
} else {
|
} else {
|
||||||
getRootItemsOf(path, callback)
|
RootHelpers().getFiles(activity as SimpleActivity, path, callback)
|
||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
@ -176,7 +188,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
for (file in files) {
|
for (file in files) {
|
||||||
val curPath = file.absolutePath
|
val curPath = file.absolutePath
|
||||||
val curName = curPath.getFilenameFromPath()
|
val curName = curPath.getFilenameFromPath()
|
||||||
if (!mShowHidden && curName.startsWith("."))
|
if (!showHidden && curName.startsWith("."))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val children = getChildren(file)
|
val children = getChildren(file)
|
||||||
@ -188,18 +200,11 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
callback(items)
|
callback(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRootItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
|
||||||
var wantedPath = path.trimEnd('/')
|
|
||||||
if (wantedPath.isEmpty())
|
|
||||||
wantedPath = "/"
|
|
||||||
RootHelpers().getFiles(activity as SimpleActivity, wantedPath, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getChildren(file: File): Int {
|
private fun getChildren(file: File): Int {
|
||||||
val fileList: Array<out String>? = file.list() ?: return 0
|
val fileList: Array<out String>? = file.list() ?: return 0
|
||||||
|
|
||||||
if (file.isDirectory) {
|
if (file.isDirectory) {
|
||||||
return if (mShowHidden) {
|
return if (showHidden) {
|
||||||
fileList!!.size
|
fileList!!.size
|
||||||
} else {
|
} else {
|
||||||
fileList!!.count { fileName -> fileName[0] != '.' }
|
fileList!!.count { fileName -> fileName[0] != '.' }
|
||||||
@ -208,9 +213,9 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun itemClicked(item: FileDirItem) {
|
private fun itemClicked(item: FileDirItem) {
|
||||||
if (item.isDirectory) {
|
if (item.isDirectory) {
|
||||||
mListener?.itemClicked(item)
|
openPath(item.path)
|
||||||
} else {
|
} else {
|
||||||
val path = item.path
|
val path = item.path
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
@ -244,9 +249,9 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createNewItem() {
|
private fun createNewItem() {
|
||||||
CreateNewItemDialog(activity as SimpleActivity, mPath) {
|
CreateNewItemDialog(activity as SimpleActivity, currentPath) {
|
||||||
if (it) {
|
if (it) {
|
||||||
fillItems()
|
refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,8 +264,19 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
return "$type/*"
|
return "$type/*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun breadcrumbClicked(id: Int) {
|
||||||
|
if (id == 0) {
|
||||||
|
StoragePickerDialog(activity, currentPath) {
|
||||||
|
openPath(it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val item = breadcrumbs.getChildAt(id).tag as FileDirItem
|
||||||
|
openPath(item.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
fillItems()
|
openPath(currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteFiles(files: ArrayList<File>) {
|
override fun deleteFiles(files: ArrayList<File>) {
|
||||||
@ -283,8 +299,4 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||||||
override fun itemLongClicked(position: Int) {
|
override fun itemLongClicked(position: Int) {
|
||||||
items_list.setDragSelectActive(position)
|
items_list.setDragSelectActive(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ItemInteractionListener {
|
|
||||||
fun itemClicked(item: FileDirItem)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,10 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.Breadcrumbs
|
<fragment
|
||||||
android:id="@+id/breadcrumbs"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="@dimen/activity_margin"/>
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/fragment_holder"
|
android:id="@+id/fragment_holder"
|
||||||
|
android:name="com.simplemobiletools.filemanager.fragments.ItemsFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"/>
|
||||||
android:layout_below="@+id/breadcrumbs"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -16,10 +16,17 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.Breadcrumbs
|
||||||
|
android:id="@+id/breadcrumbs"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/activity_margin"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyScalableRecyclerView
|
<com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||||
android:id="@+id/items_list"
|
android:id="@+id/items_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/breadcrumbs"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user