update directories instantly after renaming, do not refetch everything

This commit is contained in:
tibbi 2018-04-08 23:14:25 +02:00
parent f1fe2028d5
commit 0271af9c55
3 changed files with 22 additions and 6 deletions

View file

@ -36,7 +36,6 @@ import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.Directory
import kotlinx.android.synthetic.main.activity_main.*
import java.io.*
import java.util.*
class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private val PICK_MEDIA = 2
@ -682,6 +681,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
gotDirectories(movePinnedDirectoriesToFront(mDirs), true)
}
override fun updateDirectories(directories: ArrayList<Directory>) {
gotDirectories(directories, true)
}
private fun checkWhatsNewDialog() {
arrayListOf<Release>().apply {
add(Release(46, R.string.release_46))

View file

@ -27,6 +27,7 @@ import com.simplemobiletools.gallery.models.Directory
import kotlinx.android.synthetic.main.directory_item_list.view.*
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, recyclerView: MyRecyclerView,
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
@ -153,8 +154,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
}
private fun renameDir() {
val path = dirs[selectedPositions.first()].path
val dir = File(path)
val sourcePath = dirs[selectedPositions.first()].path
val dir = File(sourcePath)
if (activity.isAStorageRootFolder(dir.absolutePath)) {
activity.toast(R.string.rename_folder_root)
return
@ -162,8 +163,18 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
RenameItemDialog(activity, dir.absolutePath) {
activity.runOnUiThread {
listener?.refreshItems()
finishActMode()
if (selectedPositions.isEmpty()) {
return@runOnUiThread
}
dirs[selectedPositions.first()].apply {
path = it
name = it.getFilenameFromPath()
val tmbFile = tmb.getFilenameFromPath()
tmb = File(it, tmbFile).absolutePath
}
listener?.updateDirectories(dirs.toList() as ArrayList)
}
}
}
@ -386,5 +397,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
fun deleteFolders(folders: ArrayList<File>)
fun recheckPinnedFolders()
fun updateDirectories(directories: ArrayList<Directory>)
}
}

View file

@ -5,7 +5,7 @@ import com.simplemobiletools.commons.extensions.formatSize
import com.simplemobiletools.commons.helpers.*
import java.io.Serializable
data class Directory(val path: String, val tmb: String, val name: String, var mediaCnt: Int, val modified: Long, val taken: Long,
data class Directory(var path: String, var tmb: String, var name: String, var mediaCnt: Int, val modified: Long, val taken: Long,
val size: Long, val isOnSDCard: Boolean) : Serializable, Comparable<Directory> {
companion object {
private val serialVersionUID = -6553345863555455L