From b49cf2a4de94fce709ed961432b6aa6202f21010 Mon Sep 17 00:00:00 2001 From: authorisation <64337177+authorisation@users.noreply.github.com> Date: Sun, 6 Aug 2023 22:52:16 +0200 Subject: [PATCH] chore: improvements * check if loc spoof is on * allow manual update check on debug * remove some unused code * update deps --- app/build.gradle.kts | 4 +- .../rhunk/snapenhance/action/impl/OpenMap.kt | 7 + .../snapenhance/manager/impl/ActionManager.kt | 7 +- .../snapenhance/ui/menu/impl/SettingsMenu.kt | 171 +----------------- gradle/wrapper/gradle-wrapper.properties | 6 +- 5 files changed, 15 insertions(+), 180 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ee530e3f..02969cbd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -31,8 +31,8 @@ android { buildTypes { release { - isMinifyEnabled = false - isShrinkResources = false + isMinifyEnabled = true + isShrinkResources = true } } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/action/impl/OpenMap.kt b/app/src/main/kotlin/me/rhunk/snapenhance/action/impl/OpenMap.kt index 9ba340ca..f9bc04dd 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/action/impl/OpenMap.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/action/impl/OpenMap.kt @@ -2,6 +2,7 @@ package me.rhunk.snapenhance.action.impl import android.content.Intent import android.os.Bundle +import android.widget.Toast import me.rhunk.snapenhance.BuildConfig import me.rhunk.snapenhance.action.AbstractAction import me.rhunk.snapenhance.config.ConfigProperty @@ -10,6 +11,12 @@ import me.rhunk.snapenhance.ui.map.MapActivity class OpenMap: AbstractAction("action.open_map", dependsOnProperty = ConfigProperty.LOCATION_SPOOF) { override fun run() { context.runOnUiThread { + if(!context.config.bool(ConfigProperty.LOCATION_SPOOF)) { + //TODO: i18n? + Toast.makeText(context.mainActivity, "Location Spoofer is not enabled!", Toast.LENGTH_SHORT).show() + return@runOnUiThread + } + val mapActivityIntent = Intent() mapActivityIntent.setClassName(BuildConfig.APPLICATION_ID, MapActivity::class.java.name) mapActivityIntent.putExtra("location", Bundle().apply { diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/ActionManager.kt b/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/ActionManager.kt index 0c7ed9ce..c35d5e1d 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/ActionManager.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/ActionManager.kt @@ -26,11 +26,8 @@ class ActionManager( load(CleanCache::class) load(ExportChatMessages::class) load(OpenMap::class) - - if(!BuildConfig.DEBUG) { - load(CheckForUpdates::class) - } - else { + load(CheckForUpdates::class) + if(BuildConfig.DEBUG) { load(ClearMessageLogger::class) load(RefreshMappings::class) } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/SettingsMenu.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/SettingsMenu.kt index 365f2844..9b07bf7f 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/SettingsMenu.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/SettingsMenu.kt @@ -21,182 +21,13 @@ import me.rhunk.snapenhance.ui.menu.AbstractMenu import me.rhunk.snapenhance.ui.ViewAppearanceHelper class SettingsMenu : AbstractMenu() { - @SuppressLint("ClickableViewAccessibility") - private fun createCategoryTitle(key: String): TextView { - val categoryText = TextView(context.androidContext) - categoryText.text = context.translation[key] - ViewAppearanceHelper.applyTheme(categoryText) - categoryText.textSize = 20f - categoryText.typeface = categoryText.typeface?.let { Typeface.create(it, Typeface.BOLD) } - categoryText.setOnTouchListener { _, _ -> true } - return categoryText - } - - @SuppressLint("SetTextI18n") - private fun createPropertyView(property: ConfigProperty): View { - val propertyName = context.translation["property.${property.translationKey}.name"] - val updateButtonText: (TextView, String) -> Unit = { textView, text -> - textView.text = "$propertyName${if (text.isEmpty()) "" else ": $text"}" - } - - val updateLocalizedText: (TextView, String) -> Unit = { textView, value -> - updateButtonText(textView, value.let { - if (it.isEmpty()) { - "(empty)" - } - else { - if (property.disableValueLocalization) { - it - } else { - context.translation[property.getOptionTranslationKey(it)] - } - } - }) - } - - val textEditor: ((String) -> Unit) -> Unit = { updateValue -> - val builder = ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity!!) - builder.setTitle(propertyName) - - val input = EditText(context.androidContext) - input.inputType = InputType.TYPE_CLASS_TEXT - input.setText(property.valueContainer.value().toString()) - - builder.setView(input) - builder.setPositiveButton("OK") { _, _ -> - updateValue(input.text.toString()) - } - - builder.setNegativeButton("Cancel") { dialog, _ -> dialog.cancel() } - builder.show() - } - - val resultView: View = when (property.valueContainer) { - is ConfigStringValue -> { - val textView = TextView(context.androidContext) - updateButtonText(textView, property.valueContainer.let { - if (it.isHidden) it.hiddenValue() - else it.value() - }) - ViewAppearanceHelper.applyTheme(textView) - textView.setOnClickListener { - textEditor { value -> - property.valueContainer.writeFrom(value) - updateButtonText(textView, property.valueContainer.let { - if (it.isHidden) it.hiddenValue() - else it.value() - }) - } - } - textView - } - is ConfigIntegerValue -> { - val button = Button(context.androidContext) - updateButtonText(button, property.valueContainer.value().toString()) - button.setOnClickListener { - textEditor { value -> - runCatching { - property.valueContainer.writeFrom(value) - updateButtonText(button, value) - }.onFailure { - context.shortToast("Invalid value") - } - } - } - ViewAppearanceHelper.applyTheme(button) - button - } - is ConfigStateValue -> { - val switch = Switch(context.androidContext) - switch.text = propertyName - switch.isChecked = property.valueContainer.value() - switch.setOnCheckedChangeListener { _, isChecked -> - property.valueContainer.writeFrom(isChecked.toString()) - } - ViewAppearanceHelper.applyTheme(switch) - switch - } - is ConfigStateSelection -> { - val button = Button(context.androidContext) - updateLocalizedText(button, property.valueContainer.value()) - - button.setOnClickListener {_ -> - val builder = ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity!!) - builder.setTitle(propertyName) - - builder.setSingleChoiceItems( - property.valueContainer.keys().toTypedArray().map { - if (property.disableValueLocalization) it - else context.translation[property.getOptionTranslationKey(it)] - }.toTypedArray(), - property.valueContainer.keys().indexOf(property.valueContainer.value()) - ) { _, which -> - property.valueContainer.writeFrom(property.valueContainer.keys()[which]) - } - - builder.setPositiveButton("OK") { _, _ -> - updateLocalizedText(button, property.valueContainer.value()) - } - - builder.show() - } - ViewAppearanceHelper.applyTheme(button) - button - } - is ConfigStateListValue -> { - val button = Button(context.androidContext) - updateButtonText(button, "(${property.valueContainer.value().count { it.value }})") - - button.setOnClickListener {_ -> - val builder = ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity!!) - builder.setTitle(propertyName) - - val sortedStates = property.valueContainer.value().toSortedMap() - - builder.setMultiChoiceItems( - sortedStates.toSortedMap().map { - if (property.disableValueLocalization) it.key - else context.translation[property.getOptionTranslationKey(it.key)] - }.toTypedArray(), - sortedStates.map { it.value }.toBooleanArray() - ) { _, which, isChecked -> - sortedStates.keys.toList()[which].let { key -> - property.valueContainer.setKey(key, isChecked) - } - } - - builder.setPositiveButton("OK") { _, _ -> - updateButtonText(button, "(${property.valueContainer.value().count { it.value }})") - } - - builder.show() - } - ViewAppearanceHelper.applyTheme(button) - button - } - else -> { - TextView(context.androidContext) - } - } - return resultView - } - - private fun newSeparator(thickness: Int, color: Int = Color.BLACK): View { - return LinearLayout(context.mainActivity).apply { - setPadding(0, 0, 0, thickness) - setBackgroundColor(color) - } - } - //TODO: quick settings @SuppressLint("SetTextI18n") fun inject(viewModel: View, addView: (View) -> Unit) { val actions = context.actionManager.getActions().map { Pair(it) { val button = Button(viewModel.context) - button.text = (it.dependsOnProperty?.let { property -> - "["+context.translation["property.${property.translationKey}.name"] + "] " - }?: "") + context.translation[it.nameKey] + button.text = context.translation[it.nameKey] button.setOnClickListener { _ -> it.run() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 93de0496..3bb51c99 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 12 21:23:16 CEST 2023 +#Sun Aug 06 22:08:26 CEST 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists