From 58de66a25359dbb6d061026de701ba7de552b017 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 15 Mar 2017 22:22:14 +0100 Subject: [PATCH] use the RenameItemDialog of shared lib --- .../filemanager/adapters/ItemsAdapter.kt | 10 +-- .../filemanager/dialogs/RenameItemDialog.kt | 64 ------------------- .../main/res/layout/dialog_rename_item.xml | 19 ------ 3 files changed, 6 insertions(+), 87 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/RenameItemDialog.kt delete mode 100644 app/src/main/res/layout/dialog_rename_item.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 275290d2..fa802b9c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -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 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() - } -} diff --git a/app/src/main/res/layout/dialog_rename_item.xml b/app/src/main/res/layout/dialog_rename_item.xml deleted file mode 100644 index 06cbcfa4..00000000 --- a/app/src/main/res/layout/dialog_rename_item.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - -