mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
allow renaming dirs
This commit is contained in:
parent
cc7c6a1e24
commit
06c3645bf9
3 changed files with 38 additions and 41 deletions
|
@ -22,13 +22,12 @@ import com.simplemobiletools.gallery.Utils
|
|||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, GetDirectoriesAsynctask.GetDirectoriesListener {
|
||||
class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, GetDirectoriesAsynctask.GetDirectoriesListener, DirectoryAdapter.DirOperationsListener {
|
||||
companion object {
|
||||
private val STORAGE_PERMISSION = 1
|
||||
private val PICK_MEDIA = 2
|
||||
|
@ -208,7 +207,7 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
|||
}
|
||||
}
|
||||
updatedFiles.add(dir)
|
||||
if (dir.listFiles().size == 0)
|
||||
if (dir.listFiles().isEmpty())
|
||||
deleteItem(dir)
|
||||
}
|
||||
}
|
||||
|
@ -252,32 +251,8 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
|||
}*/
|
||||
}
|
||||
|
||||
private fun editDirectory() {
|
||||
/*val items = directories_grid.checkedItemPositions
|
||||
val cnt = items.size()
|
||||
for (i in 0..cnt - 1) {
|
||||
if (items.valueAt(i)) {
|
||||
val id = items.keyAt(i)
|
||||
val path = mDirs[id].path
|
||||
renameDir(path)
|
||||
break
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun renameDir(path: String) {
|
||||
val dir = File(path)
|
||||
if (isAStorageRootFolder(path)) {
|
||||
toast(R.string.rename_folder_root)
|
||||
return
|
||||
}
|
||||
|
||||
RenameDirectoryDialog(this, dir, object : RenameDirectoryDialog.OnRenameDirListener {
|
||||
override fun onRenameDirSuccess(changedPaths: ArrayList<String>) {
|
||||
mActionMode!!.finish()
|
||||
applicationContext.scanPaths(changedPaths) { scanCompleted(path) }
|
||||
}
|
||||
})
|
||||
override fun refreshItems() {
|
||||
getDirectories()
|
||||
}
|
||||
|
||||
private fun displayCopyDialog() {
|
||||
|
@ -490,15 +465,6 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
|||
return selectedPaths*/
|
||||
}
|
||||
|
||||
private fun scanCompleted(path: String) {
|
||||
val dir = File(path)
|
||||
if (dir.isDirectory) {
|
||||
getDirectories()
|
||||
|
||||
runOnUiThread { toast(R.string.rename_folder_ok) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
getDirectories()
|
||||
directories_holder.isRefreshing = false
|
||||
|
@ -511,7 +477,7 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
|||
}
|
||||
mDirs = dirs
|
||||
|
||||
val adapter = DirectoryAdapter(this, mDirs) {
|
||||
val adapter = DirectoryAdapter(this, mDirs, this) {
|
||||
itemClicked(it.path)
|
||||
}
|
||||
directories_grid.adapter = adapter
|
||||
|
|
|
@ -10,14 +10,19 @@ import com.bignerdranch.android.multiselector.SwappingHolder
|
|||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.signature.StringSignature
|
||||
import com.simplemobiletools.filepicker.extensions.isAStorageRootFolder
|
||||
import com.simplemobiletools.filepicker.extensions.scanPaths
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import kotlinx.android.synthetic.main.directory_item.view.*
|
||||
import kotlinx.android.synthetic.main.directory_tmb.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Directory>, val itemClick: (Directory) -> Unit) :
|
||||
class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Directory>, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) :
|
||||
RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {
|
||||
|
||||
val multiSelector = MultiSelector()
|
||||
|
@ -38,6 +43,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.cab_edit -> {
|
||||
editDirectory()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
|
@ -63,6 +69,27 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
}
|
||||
}
|
||||
|
||||
private fun editDirectory() {
|
||||
val path = dirs[multiSelector.selectedPositions[0]].path
|
||||
val dir = File(path)
|
||||
if (activity.isAStorageRootFolder(dir.absolutePath)) {
|
||||
activity.toast(R.string.rename_folder_root)
|
||||
return
|
||||
}
|
||||
|
||||
RenameDirectoryDialog(activity, dir, object : RenameDirectoryDialog.OnRenameDirListener {
|
||||
override fun onRenameDirSuccess(changedPaths: ArrayList<String>) {
|
||||
activity.scanPaths(changedPaths) {
|
||||
activity.runOnUiThread {
|
||||
actMode?.finish()
|
||||
listener?.refreshItems()
|
||||
activity.toast(R.string.rename_folder_ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
views.add(holder.bindView(activity, multiSelectorMode, multiSelector, dirs[position]))
|
||||
}
|
||||
|
@ -120,4 +147,8 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface DirOperationsListener {
|
||||
fun refreshItems()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class PickAlbumDialog(val activity: SimpleActivity, val listener: OnPickAlbumLis
|
|||
}
|
||||
|
||||
override fun gotDirectories(dirs: ArrayList<Directory>) {
|
||||
DirectoryAdapter(activity, dirs) {
|
||||
DirectoryAdapter(activity, dirs, null) {
|
||||
listener.onSuccess(it.path)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue