Browse Source

Prefill text field with current name when renaming a volume

master
Hardcore Sushi 2 months ago
parent
commit
55b0ac0daa
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
  1. 7
      app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt
  2. 5
      app/src/main/java/sushi/hardcore/droidfs/adapters/VolumeAdapter.kt
  3. 10
      app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt
  4. 7
      app/src/main/java/sushi/hardcore/droidfs/widgets/EditTextDialog.kt

7
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

5
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) {

10
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

7
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)

Loading…
Cancel
Save