mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-04-29 22:24:35 +02:00
refactor: switches and view apperance
Co-authored-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
parent
8932129bfd
commit
cfb0ba5d65
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user