Prefill text field with current name when renaming a volume

This commit is contained in:
Matéo Duparc 2022-04-18 14:49:35 +02:00
parent 53f28e9475
commit 55b0ac0daa
Signed by untrusted user: hardcoresushi
GPG Key ID: AFE384344A45E13A
4 changed files with 18 additions and 11 deletions

View File

@ -411,7 +411,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
} }
private fun renameVolume(volume: Volume, position: Int) { 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 srcPath = File(volume.getFullPath(filesDir.path))
val dstPath = File(srcPath.parent, newName).canonicalFile val dstPath = File(srcPath.parent, newName).canonicalFile
val newDBName: String val newDBName: String
@ -440,7 +440,10 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
} else { } else {
Toast.makeText(this, R.string.volume_rename_failed, Toast.LENGTH_SHORT).show() 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 @SuppressLint("NewApi") // fingerprintProtector is non-null only when SDK_INT >= 23

View File

@ -1,5 +1,6 @@
package sushi.hardcore.droidfs.adapters package sushi.hardcore.droidfs.adapters
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -66,9 +67,11 @@ class VolumeAdapter(
notifyItemChanged(position) notifyItemChanged(position)
} }
@SuppressLint("NotifyDataSetChanged")
fun refresh() { fun refresh() {
reloadVolumes() reloadVolumes()
unSelectAll(true) unSelectAll(false)
notifyDataSetChanged()
} }
inner class VolumeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { inner class VolumeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

View File

@ -417,10 +417,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
} }
checkPathOverwrite(items, dstDirectoryPath, callback) checkPathOverwrite(items, dstDirectoryPath, callback)
}) { }) {
with (binding.dialogEditText) { setSelectedText(items[i].explorerElement.name)
setText(items[i].explorerElement.name)
selectAll()
}
setOnCancelListener{ setOnCancelListener{
callback(null) callback(null)
} }
@ -558,10 +555,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
with(EditTextDialog(this, R.string.rename_title) { with(EditTextDialog(this, R.string.rename_title) {
rename(oldName, it) rename(oldName, it)
}) { }) {
with(binding.dialogEditText) { setSelectedText(oldName)
setText(oldName)
selectAll()
}
show() show()
} }
true true

View File

@ -13,6 +13,13 @@ class EditTextDialog(
): CustomAlertDialogBuilder(activity, activity.themeValue) { ): CustomAlertDialogBuilder(activity, activity.themeValue) {
val binding = DialogEditTextBinding.inflate(activity.layoutInflater) val binding = DialogEditTextBinding.inflate(activity.layoutInflater)
fun setSelectedText(text: CharSequence) {
with (binding.dialogEditText) {
setText(text)
selectAll()
}
}
override fun create(): AlertDialog { override fun create(): AlertDialog {
setTitle(titleId) setTitle(titleId)
setView(binding.root) setView(binding.root)