avoid loading folders twice at app start

This commit is contained in:
tibbi 2018-01-24 17:49:59 +01:00
parent acb4f63344
commit 9b957a7367
4 changed files with 28 additions and 15 deletions

View file

@ -42,7 +42,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.8.3'
implementation 'com.simplemobiletools:commons:3.8.7'
implementation files('../libs/RootTools.jar')

View file

@ -26,6 +26,7 @@ import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
import com.simplemobiletools.filemanager.extensions.*
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.list_item.view.*
import java.io.Closeable
@ -424,12 +425,4 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
val children = item.children
return activity.resources.getQuantityString(R.plurals.items, children, children)
}
interface ItemOperationsListener {
fun refreshItems()
fun deleteFiles(files: ArrayList<File>)
fun selectedPaths(paths: ArrayList<String>)
}
}

View file

@ -23,6 +23,7 @@ import com.simplemobiletools.filemanager.extensions.isPathOnRoot
import com.simplemobiletools.filemanager.extensions.openFile
import com.simplemobiletools.filemanager.helpers.PATH
import com.simplemobiletools.filemanager.helpers.RootHelpers
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.items_fragment.*
import kotlinx.android.synthetic.main.items_fragment.view.*
@ -30,11 +31,12 @@ import java.io.File
import java.util.HashMap
import kotlin.collections.ArrayList
class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
var currentPath = ""
var isGetContentIntent = false
var isGetRingtonePicker = false
var isPickMultipleIntent = false
var isFirstResume = true
private var showHidden = false
private var skipItemUpdating = false
@ -90,7 +92,10 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
items_fastscroller.updateBubbleColors()
items_fastscroller.allowBubbleDisplay = context!!.config.showInfoBubble
refreshItems()
if (!isFirstResume) {
refreshItems()
}
isFirstResume = false
}
override fun onPause() {
@ -110,15 +115,17 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
}
var realPath = path.trimEnd('/')
if (realPath.isEmpty())
if (realPath.isEmpty()) {
realPath = "/"
}
scrollStates.put(currentPath, getScrollState())
scrollStates[currentPath] = getScrollState()
currentPath = realPath
showHidden = context!!.config.shouldShowHidden
getItems(currentPath) {
if (!isAdded)
if (!isAdded) {
return@getItems
}
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
it.sort()
@ -183,8 +190,9 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
for (file in files) {
val curPath = file.absolutePath
val curName = curPath.getFilenameFromPath()
if (!showHidden && curName.startsWith("."))
if (!showHidden && curName.startsWith(".")) {
continue
}
val children = getChildrenCount(file)
val size = if (file.isDirectory && context?.config?.sorting == SORT_BY_SIZE) getDirectorySize(file) else file.length()

View file

@ -0,0 +1,12 @@
package com.simplemobiletools.filemanager.interfaces
import java.io.File
import java.util.*
interface ItemOperationsListener {
fun refreshItems()
fun deleteFiles(files: ArrayList<File>)
fun selectedPaths(paths: ArrayList<String>)
}