mirror of
https://github.com/SimpleMobileTools/Simple-Gallery.git
synced 2025-06-05 21:59:19 +02:00
fix #303, allow defining custom crop aspect ratio
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
package com.simplemobiletools.gallery.pro.dialogs
|
||||
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.showKeyboard
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import kotlinx.android.synthetic.main.dialog_custom_aspect_ratio.view.*
|
||||
|
||||
class CustomAspectRatioDialog(val activity: BaseSimpleActivity, val defaultCustomAspectRatio: Pair<Int, Int>?, val callback: (aspectRatio: Pair<Int, Int>) -> Unit) {
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_custom_aspect_ratio, null).apply {
|
||||
aspect_ratio_width.setText(defaultCustomAspectRatio?.first?.toString() ?: "")
|
||||
aspect_ratio_height.setText(defaultCustomAspectRatio?.second?.toString() ?: "")
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this) {
|
||||
showKeyboard(view.aspect_ratio_width)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val width = getViewValue(view.aspect_ratio_width)
|
||||
val height = getViewValue(view.aspect_ratio_height)
|
||||
callback(Pair(width, height))
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getViewValue(view: EditText): Int {
|
||||
val textValue = view.value
|
||||
return if (textValue.isEmpty()) 0 else textValue.toInt()
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe
|
||||
other_aspect_ratio_5_3.setOnClickListener { ratioPicked(Pair(5, 3)) }
|
||||
other_aspect_ratio_16_9.setOnClickListener { ratioPicked(Pair(16, 9)) }
|
||||
other_aspect_ratio_19_9.setOnClickListener { ratioPicked(Pair(19, 9)) }
|
||||
other_aspect_ratio_custom.setOnClickListener { customRatioPicked() }
|
||||
|
||||
other_aspect_ratio_1_2.setOnClickListener { ratioPicked(Pair(1, 2)) }
|
||||
other_aspect_ratio_2_3.setOnClickListener { ratioPicked(Pair(2, 3)) }
|
||||
@ -46,6 +47,10 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe
|
||||
else -> 0
|
||||
}
|
||||
other_aspect_ratio_dialog_radio_2.check(radio2SelectedItemId)
|
||||
|
||||
if (radio1SelectedItemId == 0 && radio2SelectedItemId == 0) {
|
||||
other_aspect_ratio_dialog_radio_1.check(other_aspect_ratio_custom.id)
|
||||
}
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
@ -55,6 +60,13 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe
|
||||
}
|
||||
}
|
||||
|
||||
private fun customRatioPicked() {
|
||||
CustomAspectRatioDialog(activity, lastOtherAspectRatio) {
|
||||
callback(it)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun ratioPicked(pair: Pair<Int, Int>) {
|
||||
callback(pair)
|
||||
dialog.dismiss()
|
||||
|
@ -69,7 +69,7 @@ class ResizeDialog(val activity: BaseSimpleActivity, val size: Point, val callba
|
||||
}
|
||||
}
|
||||
|
||||
fun getViewValue(view: EditText): Int {
|
||||
private fun getViewValue(view: EditText): Int {
|
||||
val textValue = view.value
|
||||
return if (textValue.isEmpty()) 0 else textValue.toInt()
|
||||
}
|
||||
|
Reference in New Issue
Block a user