use the rename folder dialog from the Commons lib
This commit is contained in:
parent
a5bac9311e
commit
4bcdf68ff3
4 changed files with 7 additions and 106 deletions
|
@ -32,7 +32,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.10.5'
|
||||
compile 'com.simplemobiletools:commons:2.10.12'
|
||||
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
|
||||
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
|
||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||
|
|
|
@ -15,12 +15,12 @@ import com.bumptech.glide.signature.StringSignature
|
|||
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.dialogs.RenameFolderDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import kotlinx.android.synthetic.main.directory_item.view.*
|
||||
|
@ -165,13 +165,11 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
return
|
||||
}
|
||||
|
||||
RenameDirectoryDialog(activity, dir) {
|
||||
activity.scanPaths(it) {
|
||||
activity.runOnUiThread {
|
||||
actMode?.finish()
|
||||
listener?.refreshItems()
|
||||
activity.toast(R.string.rename_folder_ok)
|
||||
}
|
||||
RenameFolderDialog(activity, dir) {
|
||||
activity.runOnUiThread {
|
||||
actMode?.finish()
|
||||
listener?.refreshItems()
|
||||
activity.toast(R.string.rename_folder_ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
package com.simplemobiletools.gallery.dialogs
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import kotlinx.android.synthetic.main.rename_directory.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class RenameDirectoryDialog(val activity: SimpleActivity, val dir: File, val callback: (changedPaths: ArrayList<String>) -> Unit) {
|
||||
init {
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.rename_directory, null).apply {
|
||||
directory_name.setText(dir.name)
|
||||
directory_path.text = "${activity.humanizePath(dir.parent)}/"
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
activity.setupDialogStuff(view, this, R.string.rename_folder)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||
val newDirName = view.directory_name.value
|
||||
if (newDirName.isEmpty()) {
|
||||
context.toast(R.string.rename_folder_empty)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (!newDirName.isAValidFilename()) {
|
||||
context.toast(R.string.invalid_name)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val updatedFiles = ArrayList<String>()
|
||||
updatedFiles.add(dir.absolutePath)
|
||||
val newDir = File(dir.parent, newDirName)
|
||||
|
||||
if (newDir.exists()) {
|
||||
context.toast(R.string.rename_folder_exists)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (context.needsStupidWritePermissions(dir.absolutePath)) {
|
||||
activity.handleSAFDialog(dir) {
|
||||
val document = context.getFileDocument(dir.absolutePath, context.config.treeUri) ?: return@handleSAFDialog
|
||||
if (document.canWrite())
|
||||
document.renameTo(newDirName)
|
||||
sendSuccess(updatedFiles, newDir)
|
||||
dismiss()
|
||||
}
|
||||
} else if (dir.renameTo(newDir)) {
|
||||
sendSuccess(updatedFiles, newDir)
|
||||
dismiss()
|
||||
} else {
|
||||
context.toast(R.string.rename_folder_error)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendSuccess(updatedFiles: ArrayList<String>, newDir: File) {
|
||||
activity.toast(R.string.renaming_folder)
|
||||
val files = if (newDir.isDirectory) newDir.listFiles() else arrayOf<File>()
|
||||
files.mapTo(updatedFiles) { it.absolutePath }
|
||||
|
||||
updatedFiles.add(newDir.absolutePath)
|
||||
callback.invoke(updatedFiles)
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/rename_directory_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/directory_path"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/directory_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue