mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57: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.adapters.DirectoryAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, GetDirectoriesAsynctask.GetDirectoriesListener {
|
class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, GetDirectoriesAsynctask.GetDirectoriesListener, DirectoryAdapter.DirOperationsListener {
|
||||||
companion object {
|
companion object {
|
||||||
private val STORAGE_PERMISSION = 1
|
private val STORAGE_PERMISSION = 1
|
||||||
private val PICK_MEDIA = 2
|
private val PICK_MEDIA = 2
|
||||||
|
@ -208,7 +207,7 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updatedFiles.add(dir)
|
updatedFiles.add(dir)
|
||||||
if (dir.listFiles().size == 0)
|
if (dir.listFiles().isEmpty())
|
||||||
deleteItem(dir)
|
deleteItem(dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,32 +251,8 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun editDirectory() {
|
override fun refreshItems() {
|
||||||
/*val items = directories_grid.checkedItemPositions
|
getDirectories()
|
||||||
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) }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayCopyDialog() {
|
private fun displayCopyDialog() {
|
||||||
|
@ -490,15 +465,6 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
||||||
return selectedPaths*/
|
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() {
|
override fun onRefresh() {
|
||||||
getDirectories()
|
getDirectories()
|
||||||
directories_holder.isRefreshing = false
|
directories_holder.isRefreshing = false
|
||||||
|
@ -511,7 +477,7 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
|
||||||
}
|
}
|
||||||
mDirs = dirs
|
mDirs = dirs
|
||||||
|
|
||||||
val adapter = DirectoryAdapter(this, mDirs) {
|
val adapter = DirectoryAdapter(this, mDirs, this) {
|
||||||
itemClicked(it.path)
|
itemClicked(it.path)
|
||||||
}
|
}
|
||||||
directories_grid.adapter = adapter
|
directories_grid.adapter = adapter
|
||||||
|
|
|
@ -10,14 +10,19 @@ import com.bignerdranch.android.multiselector.SwappingHolder
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.signature.StringSignature
|
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.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import kotlinx.android.synthetic.main.directory_item.view.*
|
import kotlinx.android.synthetic.main.directory_item.view.*
|
||||||
import kotlinx.android.synthetic.main.directory_tmb.view.*
|
import kotlinx.android.synthetic.main.directory_tmb.view.*
|
||||||
|
import java.io.File
|
||||||
import java.util.*
|
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>() {
|
RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {
|
||||||
|
|
||||||
val multiSelector = MultiSelector()
|
val multiSelector = MultiSelector()
|
||||||
|
@ -38,6 +43,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.cab_edit -> {
|
R.id.cab_edit -> {
|
||||||
|
editDirectory()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> false
|
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) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
views.add(holder.bindView(activity, multiSelectorMode, multiSelector, dirs[position]))
|
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>) {
|
override fun gotDirectories(dirs: ArrayList<Directory>) {
|
||||||
DirectoryAdapter(activity, dirs) {
|
DirectoryAdapter(activity, dirs, null) {
|
||||||
listener.onSuccess(it.path)
|
listener.onSuccess(it.path)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue