allow changing the save path of edited image

This commit is contained in:
tibbi 2016-12-04 15:39:22 +01:00
parent 8ed6bff447
commit a66d72abde
2 changed files with 23 additions and 11 deletions

View file

@ -73,17 +73,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
if (result.error == null) { if (result.error == null) {
if (uri.scheme == "file") { if (uri.scheme == "file") {
SaveAsDialog(this, uri.path) { SaveAsDialog(this, uri.path) {
val parent = File(uri.path).parent saveBitmapToFile(result.bitmap, it)
val path = File(parent, it).absolutePath
saveBitmapToFile(result.bitmap, path)
} }
} else if (uri.scheme == "content") { } else if (uri.scheme == "content") {
val newPath = applicationContext.getRealPathFromURI(uri) ?: "" val newPath = applicationContext.getRealPathFromURI(uri) ?: ""
if (!newPath.isEmpty()) { if (!newPath.isEmpty()) {
SaveAsDialog(this, newPath) { SaveAsDialog(this, newPath) {
val parent = File(uri.path).parent saveBitmapToFile(result.bitmap, it)
val path = File(parent, it).absolutePath
saveBitmapToFile(result.bitmap, path)
} }
} else { } else {
toast(R.string.image_editing_failed) toast(R.string.image_editing_failed)

View file

@ -4,18 +4,33 @@ import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.WindowManager import android.view.WindowManager
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.filepicker.extensions.*
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import kotlinx.android.synthetic.main.rename_file.view.* import kotlinx.android.synthetic.main.rename_file.view.*
import java.io.File 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 { init {
var realPath = File(path).parent.trimEnd('/')
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null) val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null)
val realPath = File(path).parent.trimEnd('/') view.apply {
view.file_path.text = activity.humanizePath(realPath) file_path.text = activity.humanizePath(realPath)
view.file_name.setText(path.getFilenameFromPath()) 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) AlertDialog.Builder(activity)
.setTitle(activity.resources.getString(R.string.save_as)) .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 return@setOnClickListener
} }
callback.invoke(filename) val newPath = File(realPath, filename).absolutePath
callback.invoke(newPath)
dismiss() dismiss()
}) })
} }