refactor: switches and view apperance

Co-authored-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
auth 2023-06-03 18:49:14 +02:00 committed by GitHub
parent 8932129bfd
commit cfb0ba5d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 9 deletions

View File

@ -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
}
}
}

View File

@ -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
}