From 55b0ac0daa8942051604f0dc974c31737a236cd2 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 18 Apr 2022 14:49:35 +0200 Subject: [PATCH] Prefill text field with current name when renaming a volume --- .../main/java/sushi/hardcore/droidfs/MainActivity.kt | 7 +++++-- .../sushi/hardcore/droidfs/adapters/VolumeAdapter.kt | 5 ++++- .../hardcore/droidfs/explorers/BaseExplorerActivity.kt | 10 ++-------- .../sushi/hardcore/droidfs/widgets/EditTextDialog.kt | 7 +++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt index 6d1b592..64c997e 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt @@ -411,7 +411,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener { } private fun renameVolume(volume: Volume, position: Int) { - EditTextDialog(this, R.string.new_volume_name) { newName -> + with (EditTextDialog(this, R.string.new_volume_name) { newName -> val srcPath = File(volume.getFullPath(filesDir.path)) val dstPath = File(srcPath.parent, newName).canonicalFile val newDBName: String @@ -440,7 +440,10 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener { } else { Toast.makeText(this, R.string.volume_rename_failed, Toast.LENGTH_SHORT).show() } - }.show() + }) { + setSelectedText(volume.shortName) + show() + } } @SuppressLint("NewApi") // fingerprintProtector is non-null only when SDK_INT >= 23 diff --git a/app/src/main/java/sushi/hardcore/droidfs/adapters/VolumeAdapter.kt b/app/src/main/java/sushi/hardcore/droidfs/adapters/VolumeAdapter.kt index 2938582..873d56b 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/adapters/VolumeAdapter.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/adapters/VolumeAdapter.kt @@ -1,5 +1,6 @@ package sushi.hardcore.droidfs.adapters +import android.annotation.SuppressLint import android.content.Context import android.view.LayoutInflater import android.view.View @@ -66,9 +67,11 @@ class VolumeAdapter( notifyItemChanged(position) } + @SuppressLint("NotifyDataSetChanged") fun refresh() { reloadVolumes() - unSelectAll(true) + unSelectAll(false) + notifyDataSetChanged() } inner class VolumeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt index 0e2662f..093a19d 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt @@ -417,10 +417,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene } checkPathOverwrite(items, dstDirectoryPath, callback) }) { - with (binding.dialogEditText) { - setText(items[i].explorerElement.name) - selectAll() - } + setSelectedText(items[i].explorerElement.name) setOnCancelListener{ callback(null) } @@ -558,10 +555,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene with(EditTextDialog(this, R.string.rename_title) { rename(oldName, it) }) { - with(binding.dialogEditText) { - setText(oldName) - selectAll() - } + setSelectedText(oldName) show() } true diff --git a/app/src/main/java/sushi/hardcore/droidfs/widgets/EditTextDialog.kt b/app/src/main/java/sushi/hardcore/droidfs/widgets/EditTextDialog.kt index 05c37df..cd1fb92 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/widgets/EditTextDialog.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/widgets/EditTextDialog.kt @@ -13,6 +13,13 @@ class EditTextDialog( ): CustomAlertDialogBuilder(activity, activity.themeValue) { val binding = DialogEditTextBinding.inflate(activity.layoutInflater) + fun setSelectedText(text: CharSequence) { + with (binding.dialogEditText) { + setText(text) + selectAll() + } + } + override fun create(): AlertDialog { setTitle(titleId) setView(binding.root)