use the RenameItemDialog of shared lib
This commit is contained in:
parent
56cd0bb14f
commit
58de66a253
|
@ -14,6 +14,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.formatSize
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.extensions.isGif
|
||||
|
@ -22,7 +23,6 @@ import com.simplemobiletools.commons.models.FileDirItem
|
|||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||
import com.simplemobiletools.filemanager.dialogs.CopyDialog
|
||||
import com.simplemobiletools.filemanager.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.filemanager.extensions.config
|
||||
import kotlinx.android.synthetic.main.list_item.view.*
|
||||
import java.io.File
|
||||
|
@ -96,9 +96,11 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
}
|
||||
|
||||
private fun displayRenameDialog() {
|
||||
RenameItemDialog(activity, getSelectedMedia()[0]) {
|
||||
listener?.refreshItems()
|
||||
actMode?.finish()
|
||||
RenameItemDialog(activity, getSelectedMedia()[0].path) {
|
||||
activity.runOnUiThread {
|
||||
listener?.refreshItems()
|
||||
actMode?.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
package com.simplemobiletools.filemanager.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_rename_item.view.*
|
||||
import java.io.File
|
||||
|
||||
class RenameItemDialog(val activity: Activity, val item: FileDirItem, val callback: () -> Unit) {
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_item, null)
|
||||
view.item_name.setText(item.name)
|
||||
|
||||
val path = File(item.path).parent
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.rename)
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||
val newName = view.item_name.value
|
||||
if (!newName.isAValidFilename()) {
|
||||
context.toast(R.string.invalid_name)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val currFile = File(path, item.name)
|
||||
val newFile = File(path, newName)
|
||||
|
||||
if (newFile.exists()) {
|
||||
context.toast(R.string.name_taken)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (context.needsStupidWritePermissions(path)) {
|
||||
val document = context.getFileDocument(currFile.absolutePath, context.config.treeUri) ?: return@setOnClickListener
|
||||
if (document.canWrite())
|
||||
document.renameTo(newName)
|
||||
sendSuccess(newFile)
|
||||
dismiss()
|
||||
} else {
|
||||
if (currFile.renameTo(newFile)) {
|
||||
sendSuccess(newFile)
|
||||
dismiss()
|
||||
} else {
|
||||
context.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendSuccess(newFile: File) {
|
||||
activity.scanFiles(arrayListOf(newFile)) {}
|
||||
callback.invoke()
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/item_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:inputType="textCapSentences"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue