diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt new file mode 100644 index 000000000..830c839de --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt @@ -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?, val callback: (aspectRatio: Pair) -> 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() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt index 60cd259b6..4fe770c8c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt @@ -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) { callback(pair) dialog.dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt index 7326ec044..96ef3b50b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeDialog.kt @@ -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() } diff --git a/app/src/main/res/layout/dialog_custom_aspect_ratio.xml b/app/src/main/res/layout/dialog_custom_aspect_ratio.xml new file mode 100644 index 000000000..3f9180ae0 --- /dev/null +++ b/app/src/main/res/layout/dialog_custom_aspect_ratio.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_other_aspect_ratio.xml b/app/src/main/res/layout/dialog_other_aspect_ratio.xml index 76fbb1b4a..61487c688 100644 --- a/app/src/main/res/layout/dialog_other_aspect_ratio.xml +++ b/app/src/main/res/layout/dialog_other_aspect_ratio.xml @@ -84,6 +84,16 @@ android:text="19:9" android:textSize="@dimen/bigger_text_size"/> + +