diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 4feaade51..4a297ae97 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -73,17 +73,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener if (result.error == null) { if (uri.scheme == "file") { SaveAsDialog(this, uri.path) { - val parent = File(uri.path).parent - val path = File(parent, it).absolutePath - saveBitmapToFile(result.bitmap, path) + saveBitmapToFile(result.bitmap, it) } } else if (uri.scheme == "content") { val newPath = applicationContext.getRealPathFromURI(uri) ?: "" if (!newPath.isEmpty()) { SaveAsDialog(this, newPath) { - val parent = File(uri.path).parent - val path = File(parent, it).absolutePath - saveBitmapToFile(result.bitmap, path) + saveBitmapToFile(result.bitmap, it) } } else { toast(R.string.image_editing_failed) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt index f568d81be..1cfc52470 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt @@ -4,18 +4,33 @@ import android.app.Activity import android.app.AlertDialog import android.view.LayoutInflater import android.view.WindowManager +import com.simplemobiletools.filepicker.dialogs.FilePickerDialog import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.gallery.R import kotlinx.android.synthetic.main.rename_file.view.* import java.io.File -class SaveAsDialog(val activity: Activity, val path: String, val callback: (filename: String) -> Unit) { +class SaveAsDialog(val activity: Activity, val path: String, val callback: (savePath: String) -> Unit) { init { + var realPath = File(path).parent.trimEnd('/') val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null) - val realPath = File(path).parent.trimEnd('/') - view.file_path.text = activity.humanizePath(realPath) - view.file_name.setText(path.getFilenameFromPath()) + view.apply { + file_path.text = activity.humanizePath(realPath) + file_name.setText(path.getFilenameFromPath()) + + file_path.setOnClickListener { + FilePickerDialog(activity, realPath, false, false, listener = object : FilePickerDialog.OnFilePickerListener { + override fun onSuccess(pickedPath: String) { + file_path.text = activity.humanizePath(pickedPath) + realPath = pickedPath + } + + override fun onFail(error: FilePickerDialog.FilePickerResult) { + } + }) + } + } AlertDialog.Builder(activity) .setTitle(activity.resources.getString(R.string.save_as)) @@ -39,7 +54,8 @@ class SaveAsDialog(val activity: Activity, val path: String, val callback: (file return@setOnClickListener } - callback.invoke(filename) + val newPath = File(realPath, filename).absolutePath + callback.invoke(newPath) dismiss() }) }