From 197d504326e375aa4a19025ca40a6b32d7273a36 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 4 Aug 2019 11:03:23 +0200 Subject: [PATCH] do some preparations for allowing decimals at aspect ratios --- .../gallery/pro/activities/EditActivity.kt | 18 +++---- .../pro/activities/SettingsActivity.kt | 4 +- .../pro/dialogs/CustomAspectRatioDialog.kt | 10 ++-- .../pro/dialogs/OtherAspectRatioDialog.kt | 52 +++++++++---------- .../gallery/pro/helpers/Config.kt | 12 ++--- .../gallery/pro/helpers/Constants.kt | 4 +- 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index 9d4889219..ae8b82750 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -78,7 +78,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener private var resizeWidth = 0 private var resizeHeight = 0 private var drawColor = 0 - private var lastOtherAspectRatio: Pair? = null + private var lastOtherAspectRatio: Pair? = null private var currPrimaryAction = PRIMARY_ACTION_NONE private var currCropRotateAction = CROP_ROTATE_ASPECT_RATIO private var currAspectRatio = ASPECT_RATIO_FREE @@ -177,12 +177,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener setupBottomActions() if (config.lastEditorCropAspectRatio == ASPECT_RATIO_OTHER) { - if (config.lastEditorCropOtherAspectRatioX == 0) { - config.lastEditorCropOtherAspectRatioX = 1 + if (config.lastEditorCropOtherAspectRatioX == 0f) { + config.lastEditorCropOtherAspectRatioX = 1f } - if (config.lastEditorCropOtherAspectRatioY == 0) { - config.lastEditorCropOtherAspectRatioY = 1 + if (config.lastEditorCropOtherAspectRatioY == 0f) { + config.lastEditorCropOtherAspectRatioY = 1f } lastOtherAspectRatio = Pair(config.lastEditorCropOtherAspectRatioX, config.lastEditorCropOtherAspectRatioY) @@ -654,13 +654,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener setFixedAspectRatio(false) } else { val newAspectRatio = when (aspectRatio) { - ASPECT_RATIO_ONE_ONE -> Pair(1, 1) - ASPECT_RATIO_FOUR_THREE -> Pair(4, 3) - ASPECT_RATIO_SIXTEEN_NINE -> Pair(16, 9) + ASPECT_RATIO_ONE_ONE -> Pair(1f, 1f) + ASPECT_RATIO_FOUR_THREE -> Pair(4f, 3f) + ASPECT_RATIO_SIXTEEN_NINE -> Pair(16f, 9f) else -> Pair(lastOtherAspectRatio!!.first, lastOtherAspectRatio!!.second) } - setAspectRatio(newAspectRatio.first, newAspectRatio.second) + setAspectRatio(newAspectRatio.first.toInt(), newAspectRatio.second.toInt()) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt index 2e9cc0a84..320cfbf1a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt @@ -790,8 +790,8 @@ class SettingsActivity : SimpleActivity() { SLIDESHOW_MOVE_BACKWARDS -> config.slideshowMoveBackwards = value.toBoolean() SLIDESHOW_LOOP -> config.loopSlideshow = value.toBoolean() LAST_EDITOR_CROP_ASPECT_RATIO -> config.lastEditorCropAspectRatio = value.toInt() - LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X -> config.lastEditorCropOtherAspectRatioX = value.toInt() - LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y -> config.lastEditorCropOtherAspectRatioY = value.toInt() + LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X -> config.lastEditorCropOtherAspectRatioX = value.toString().toFloat() + LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y -> config.lastEditorCropOtherAspectRatioY = value.toString().toFloat() LAST_EDITOR_DRAW_COLOR -> config.lastEditorDrawColor = value.toInt() LAST_EDITOR_BRUSH_SIZE -> config.lastEditorBrushSize = value.toInt() LAST_CONFLICT_RESOLUTION -> config.lastConflictResolution = value.toInt() 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 index 830c839de..47df4b89e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/CustomAspectRatioDialog.kt @@ -9,11 +9,11 @@ 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) { +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() ?: "") + aspect_ratio_width.setText(defaultCustomAspectRatio?.first?.toInt()?.toString() ?: "") + aspect_ratio_height.setText(defaultCustomAspectRatio?.second?.toInt()?.toString() ?: "") } AlertDialog.Builder(activity) @@ -32,8 +32,8 @@ class CustomAspectRatioDialog(val activity: BaseSimpleActivity, val defaultCusto } } - private fun getViewValue(view: EditText): Int { + private fun getViewValue(view: EditText): Float { val textValue = view.value - return if (textValue.isEmpty()) 0 else textValue.toInt() + return if (textValue.isEmpty()) 0f else textValue.toFloat() } } 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 4fe770c8c..76f7e7e78 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 @@ -6,44 +6,44 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.dialog_other_aspect_ratio.view.* -class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspectRatio: Pair?, val callback: (aspectRatio: Pair) -> Unit) { +class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspectRatio: Pair?, val callback: (aspectRatio: Pair) -> Unit) { private val dialog: AlertDialog init { val view = activity.layoutInflater.inflate(R.layout.dialog_other_aspect_ratio, null).apply { - other_aspect_ratio_2_1.setOnClickListener { ratioPicked(Pair(2, 1)) } - other_aspect_ratio_3_2.setOnClickListener { ratioPicked(Pair(3, 2)) } - other_aspect_ratio_4_3.setOnClickListener { ratioPicked(Pair(4, 3)) } - 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_2_1.setOnClickListener { ratioPicked(Pair(2f, 1f)) } + other_aspect_ratio_3_2.setOnClickListener { ratioPicked(Pair(3f, 2f)) } + other_aspect_ratio_4_3.setOnClickListener { ratioPicked(Pair(4f, 3f)) } + other_aspect_ratio_5_3.setOnClickListener { ratioPicked(Pair(5f, 3f)) } + other_aspect_ratio_16_9.setOnClickListener { ratioPicked(Pair(16f, 9f)) } + other_aspect_ratio_19_9.setOnClickListener { ratioPicked(Pair(19f, 9f)) } 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)) } - other_aspect_ratio_3_4.setOnClickListener { ratioPicked(Pair(3, 4)) } - other_aspect_ratio_3_5.setOnClickListener { ratioPicked(Pair(3, 5)) } - other_aspect_ratio_9_16.setOnClickListener { ratioPicked(Pair(9, 16)) } - other_aspect_ratio_9_19.setOnClickListener { ratioPicked(Pair(9, 19)) } + other_aspect_ratio_1_2.setOnClickListener { ratioPicked(Pair(1f, 2f)) } + other_aspect_ratio_2_3.setOnClickListener { ratioPicked(Pair(2f, 3f)) } + other_aspect_ratio_3_4.setOnClickListener { ratioPicked(Pair(3f, 4f)) } + other_aspect_ratio_3_5.setOnClickListener { ratioPicked(Pair(3f, 5f)) } + other_aspect_ratio_9_16.setOnClickListener { ratioPicked(Pair(9f, 16f)) } + other_aspect_ratio_9_19.setOnClickListener { ratioPicked(Pair(9f, 19f)) } val radio1SelectedItemId = when (lastOtherAspectRatio) { - Pair(2, 1) -> other_aspect_ratio_2_1.id - Pair(3, 2) -> other_aspect_ratio_3_2.id - Pair(4, 3) -> other_aspect_ratio_4_3.id - Pair(5, 3) -> other_aspect_ratio_5_3.id - Pair(16, 9) -> other_aspect_ratio_16_9.id - Pair(19, 9) -> other_aspect_ratio_19_9.id + Pair(2f, 1f) -> other_aspect_ratio_2_1.id + Pair(3f, 2f) -> other_aspect_ratio_3_2.id + Pair(4f, 3f) -> other_aspect_ratio_4_3.id + Pair(5f, 3f) -> other_aspect_ratio_5_3.id + Pair(16f, 9f) -> other_aspect_ratio_16_9.id + Pair(19f, 9f) -> other_aspect_ratio_19_9.id else -> 0 } other_aspect_ratio_dialog_radio_1.check(radio1SelectedItemId) val radio2SelectedItemId = when (lastOtherAspectRatio) { - Pair(1, 2) -> other_aspect_ratio_1_2.id - Pair(2, 3) -> other_aspect_ratio_2_3.id - Pair(3, 4) -> other_aspect_ratio_3_4.id - Pair(3, 5) -> other_aspect_ratio_3_5.id - Pair(9, 16) -> other_aspect_ratio_9_16.id - Pair(9, 19) -> other_aspect_ratio_9_19.id + Pair(1f, 2f) -> other_aspect_ratio_1_2.id + Pair(2f, 3f) -> other_aspect_ratio_2_3.id + Pair(3f, 4f) -> other_aspect_ratio_3_4.id + Pair(3f, 5f) -> other_aspect_ratio_3_5.id + Pair(9f, 16f) -> other_aspect_ratio_9_16.id + Pair(9f, 19f) -> other_aspect_ratio_9_19.id else -> 0 } other_aspect_ratio_dialog_radio_2.check(radio2SelectedItemId) @@ -67,7 +67,7 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe } } - private fun ratioPicked(pair: Pair) { + private fun ratioPicked(pair: Pair) { callback(pair) dialog.dismiss() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index f4f514705..7b435e810 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -447,13 +447,13 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(LAST_EDITOR_CROP_ASPECT_RATIO, ASPECT_RATIO_FREE) set(lastEditorCropAspectRatio) = prefs.edit().putInt(LAST_EDITOR_CROP_ASPECT_RATIO, lastEditorCropAspectRatio).apply() - var lastEditorCropOtherAspectRatioX: Int - get() = prefs.getInt(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X, 2) - set(lastEditorCropOtherAspectRatioX) = prefs.edit().putInt(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X, lastEditorCropOtherAspectRatioX).apply() + var lastEditorCropOtherAspectRatioX: Float + get() = prefs.getFloat(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X, 2f) + set(lastEditorCropOtherAspectRatioX) = prefs.edit().putFloat(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X, lastEditorCropOtherAspectRatioX).apply() - var lastEditorCropOtherAspectRatioY: Int - get() = prefs.getInt(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y, 1) - set(lastEditorCropOtherAspectRatioY) = prefs.edit().putInt(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y, lastEditorCropOtherAspectRatioY).apply() + var lastEditorCropOtherAspectRatioY: Float + get() = prefs.getFloat(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y, 1f) + set(lastEditorCropOtherAspectRatioY) = prefs.edit().putFloat(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y, lastEditorCropOtherAspectRatioY).apply() var groupDirectSubfolders: Boolean get() = prefs.getBoolean(GROUP_DIRECT_SUBFOLDERS, false) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index c7957b0bb..8e92b07f3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -67,8 +67,8 @@ const val LAST_BIN_CHECK = "last_bin_check" const val SHOW_HIGHEST_QUALITY = "show_highest_quality" const val ALLOW_DOWN_GESTURE = "allow_down_gesture" const val LAST_EDITOR_CROP_ASPECT_RATIO = "last_editor_crop_aspect_ratio" -const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X = "last_editor_crop_other_aspect_ratio_x" -const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y = "last_editor_crop_other_aspect_ratio_y" +const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X = "last_editor_crop_other_aspect_ratio_x_2" +const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y = "last_editor_crop_other_aspect_ratio_y_2" const val GROUP_DIRECT_SUBFOLDERS = "group_direct_subfolders" const val SHOW_WIDGET_FOLDER_NAME = "show_widget_folder_name" const val ALLOW_ONE_TO_ONE_ZOOM = "allow_one_to_one_zoom"