commit cfb0ba5d65e435f622e7408d21c32d9f5855ded0
parent 8932129bfd6d029872c0d5a8a04c6b42bacfe6a2
Author: auth <64337177+authorisation@users.noreply.github.com>
Date: Sat, 3 Jun 2023 18:49:14 +0200
refactor: switches and view apperance
Co-authored-by: rhunk <101876869+rhunk@users.noreply.github.com>
Diffstat:
2 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/ViewAppearanceHelper.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/ViewAppearanceHelper.kt
@@ -4,13 +4,16 @@ import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.graphics.Color
import android.view.Gravity
+import android.view.MotionEvent
import android.view.View
import android.widget.Switch
import android.widget.TextView
import me.rhunk.snapenhance.Constants
object ViewAppearanceHelper {
- @SuppressLint("UseSwitchCompatOrMaterialCode", "RtlHardcoded", "DiscouragedApi")
+ @SuppressLint("UseSwitchCompatOrMaterialCode", "RtlHardcoded", "DiscouragedApi",
+ "ClickableViewAccessibility"
+ )
fun applyTheme(viewModel: View, view: TextView) {
val snapchatFontResId = view.context.resources.getIdentifier("avenir_next_medium", "font", "com.snapchat.android")
//remove the shadow
@@ -24,25 +27,44 @@ object ViewAppearanceHelper {
//DPI Calculator
val scalingFactor = view.context.resources.displayMetrics.densityDpi.toDouble() / 400
view.height = (150 * scalingFactor).toInt()
- view.setPadding((40 * scalingFactor).toInt(), 0, (25 * scalingFactor).toInt(), 0)
+ view.setPadding((40 * scalingFactor).toInt(), 0, (40 * scalingFactor).toInt(), 0)
view.isAllCaps = false
view.textSize = 16f
view.typeface = view.context.resources.getFont(snapchatFontResId)
-
- //remove click effect
- if (view.javaClass == TextView::class.java) {
- view.setBackgroundColor(0)
+
+ //FIXME: wrong color, shouldn't be that much noticeable though
+ view.setOnTouchListener { _, event ->
+ when (event.action) {
+ MotionEvent.ACTION_DOWN -> {
+ view.setBackgroundColor(0x5395026)
+ }
+ MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
+ view.setBackgroundColor(0x00000000)
+ }
+ }
+ false
}
+
if (view is Switch) {
+ with(viewModel.resources) {
+ view.switchMinWidth = getDimension(getIdentifier("v11_switch_min_width", "dimen", Constants.SNAPCHAT_PACKAGE_NAME)).toInt()
+ }
val colorStateList = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)
), intArrayOf(
- Color.parseColor("#3d3d3d"),
- Color.parseColor("#2196F3")
+ Color.parseColor("#1d1d1d"),
+ Color.parseColor("#26bd49")
+ )
+ )
+ val thumbStateList = ColorStateList(
+ arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)
+ ), intArrayOf(
+ Color.parseColor("#F5F5F5"),
+ Color.parseColor("#26bd49")
)
)
view.trackTintList = colorStateList
- view.thumbTintList = colorStateList
+ view.thumbTintList = thumbStateList
}
}
}
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt
@@ -21,12 +21,14 @@ import me.rhunk.snapenhance.features.impl.ui.menus.AbstractMenu
import me.rhunk.snapenhance.features.impl.ui.menus.ViewAppearanceHelper
class SettingsMenu : AbstractMenu() {
+ @SuppressLint("ClickableViewAccessibility")
private fun createCategoryTitle(viewModel: View, key: String): TextView {
val categoryText = TextView(viewModel.context)
categoryText.text = context.translation.get(key)
ViewAppearanceHelper.applyTheme(viewModel, categoryText)
categoryText.textSize = 20f
categoryText.typeface = categoryText.typeface?.let { Typeface.create(it, Typeface.BOLD) }
+ categoryText.setOnTouchListener { _, _ -> true }
return categoryText
}