mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
return both the resolution and path from the new dialog
This commit is contained in:
parent
787a672c7f
commit
8ba998d3ae
2 changed files with 33 additions and 6 deletions
|
@ -921,7 +921,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private fun resizeImage() {
|
private fun resizeImage() {
|
||||||
val currentPath = getCurrentPath()
|
val currentPath = getCurrentPath()
|
||||||
val originalSize = currentPath.getImageResolution() ?: return
|
val originalSize = currentPath.getImageResolution() ?: return
|
||||||
ResizeWithPathDialog(this, originalSize, currentPath) {
|
ResizeWithPathDialog(this, originalSize, currentPath) { newSize, newPath ->
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,14 @@ import android.graphics.Point
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.extensions.config
|
import com.simplemobiletools.gallery.pro.extensions.config
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_image.view.image_height
|
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_image.view.image_width
|
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_image_with_path.view.*
|
import kotlinx.android.synthetic.main.dialog_resize_image_with_path.view.*
|
||||||
|
|
||||||
class ResizeWithPathDialog(val activity: BaseSimpleActivity, val size: Point, val path: String, val callback: (newSize: Point) -> Unit) {
|
class ResizeWithPathDialog(val activity: BaseSimpleActivity, val size: Point, val path: String, val callback: (newSize: Point, newPath: String) -> Unit) {
|
||||||
init {
|
init {
|
||||||
var realPath = path.getParentPath()
|
var realPath = path.getParentPath()
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_resize_image_with_path, null).apply {
|
val view = activity.layoutInflater.inflate(R.layout.dialog_resize_image_with_path, null).apply {
|
||||||
|
@ -84,9 +83,37 @@ class ResizeWithPathDialog(val activity: BaseSimpleActivity, val size: Point, va
|
||||||
}
|
}
|
||||||
|
|
||||||
val newSize = Point(getViewValue(widthView), getViewValue(heightView))
|
val newSize = Point(getViewValue(widthView), getViewValue(heightView))
|
||||||
callback(newSize)
|
|
||||||
|
val filename = view.image_name.value
|
||||||
|
val extension = view.image_extension.value
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
activity.toast(R.string.filename_cannot_be_empty)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extension.isEmpty()) {
|
||||||
|
activity.toast(R.string.extension_cannot_be_empty)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
val newFilename = "$filename.$extension"
|
||||||
|
val newPath = "${realPath.trimEnd('/')}/$newFilename"
|
||||||
|
if (!newFilename.isAValidFilename()) {
|
||||||
|
activity.toast(R.string.filename_invalid_characters)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activity.getDoesFilePathExist(newPath)) {
|
||||||
|
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
|
||||||
|
ConfirmationDialog(activity, title) {
|
||||||
|
callback(newSize, newPath)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
callback(newSize, newPath)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue