humanize the paths displayed at the copy dialog

This commit is contained in:
tibbi 2016-11-11 18:29:53 +01:00
parent 5b29615cef
commit 0f3bb7334e

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.filemanager.extensions.rescanItem
import com.simplemobiletools.filemanager.extensions.toast import com.simplemobiletools.filemanager.extensions.toast
import com.simplemobiletools.filemanager.extensions.value import com.simplemobiletools.filemanager.extensions.value
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
import com.simplemobiletools.filepicker.extensions.humanizePath
import kotlinx.android.synthetic.main.copy_item.view.* import kotlinx.android.synthetic.main.copy_item.view.*
import java.io.File import java.io.File
@ -24,17 +25,19 @@ class CopyDialog(val activity: Activity, val files: List<File>, val copyListener
init { init {
val context = activity val context = activity
val view = LayoutInflater.from(context).inflate(R.layout.copy_item, null) val view = LayoutInflater.from(context).inflate(R.layout.copy_item, null)
val path = files[0].parent val path = files[0].parent.trimEnd('/')
view.source.text = "${path.trimEnd('/')}/" var destinationPath = ""
view.source.text = "${context.humanizePath(path)}/"
view.destination.setOnClickListener { view.destination.setOnClickListener {
val config = Config.newInstance(context) val config = Config.newInstance(context)
FilePickerDialog(activity, path, false, config.showHidden, object : FilePickerDialog.OnFilePickerListener { FilePickerDialog(activity, destinationPath, false, config.showHidden, object : FilePickerDialog.OnFilePickerListener {
override fun onFail(error: FilePickerDialog.FilePickerResult) { override fun onFail(error: FilePickerDialog.FilePickerResult) {
} }
override fun onSuccess(pickedPath: String) { override fun onSuccess(pickedPath: String) {
view.destination.text = pickedPath destinationPath = pickedPath
view.destination.text = context.humanizePath(pickedPath)
} }
}) })
} }
@ -48,8 +51,7 @@ class CopyDialog(val activity: Activity, val files: List<File>, val copyListener
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
show() show()
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val destinationPath = view.destination.value if (destinationPath == context.resources.getString(R.string.select_destination) || destinationPath.isEmpty()) {
if (destinationPath == context.resources.getString(R.string.select_destination)) {
context.toast(R.string.please_select_destination) context.toast(R.string.please_select_destination)
return@setOnClickListener return@setOnClickListener
} }