diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-04-04 19:34:00 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-04-04 20:53:42 +0200 |
commit | 75899594c35e0bd055cedd40f695fd6583a6b2dd (patch) | |
tree | f433bcfdd3b66925186409912fa466ff1d53d424 /ui/src/main/java/com | |
parent | 4944762d7c167da620b92914350421e5fce493be (diff) |
ui: use real M3 themeing on TV
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com')
3 files changed, 58 insertions, 5 deletions
diff --git a/ui/src/main/java/com/wireguard/android/Application.kt b/ui/src/main/java/com/wireguard/android/Application.kt index 928ee346..94fb2ca7 100644 --- a/ui/src/main/java/com/wireguard/android/Application.kt +++ b/ui/src/main/java/com/wireguard/android/Application.kt @@ -17,8 +17,6 @@ import androidx.datastore.preferences.core.PreferenceDataStoreFactory import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.preferencesDataStoreFile import com.google.android.material.color.DynamicColors -import com.google.android.material.color.DynamicColorsOptions -import com.wireguard.android.activity.TvMainActivity import com.wireguard.android.backend.Backend import com.wireguard.android.backend.GoBackend import com.wireguard.android.backend.WgQuickBackend @@ -89,9 +87,7 @@ class Application : android.app.Application() { override fun onCreate() { Log.i(TAG, USER_AGENT) super.onCreate() - DynamicColors.applyToActivitiesIfAvailable(this, - // TODO: Remove this second argument once the TV theme has a proper M3 color palette. - DynamicColorsOptions.Builder().setPrecondition { activity, _ -> activity !is TvMainActivity }.build()) + DynamicColors.applyToActivitiesIfAvailable(this) rootShell = RootShell(applicationContext) toolsInstaller = ToolsInstaller(applicationContext, rootShell) preferencesDataStore = PreferenceDataStoreFactory.create { applicationContext.preferencesDataStoreFile("settings") } diff --git a/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt b/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt index d823fa8d..fd7bc72c 100644 --- a/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt +++ b/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt @@ -23,6 +23,7 @@ import com.wireguard.android.R import com.wireguard.android.databinding.ObservableKeyedRecyclerViewAdapter.RowConfigurationHandler import com.wireguard.android.widget.ToggleSwitch import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener +import com.wireguard.android.widget.TvCardView import com.wireguard.config.Attribute import com.wireguard.config.InetNetwork import java.net.InetAddress @@ -168,4 +169,16 @@ object BindingAdapters { 0 } } + + @JvmStatic + @BindingAdapter("isUp") + fun setIsUp(card: TvCardView, up: Boolean) { + card.isUp = up + } + + @JvmStatic + @BindingAdapter("isDeleting") + fun setIsDeleting(card: TvCardView, deleting: Boolean) { + card.isDeleting = deleting + } } diff --git a/ui/src/main/java/com/wireguard/android/widget/TvCardView.kt b/ui/src/main/java/com/wireguard/android/widget/TvCardView.kt new file mode 100644 index 00000000..9f7d7011 --- /dev/null +++ b/ui/src/main/java/com/wireguard/android/widget/TvCardView.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2017-2023 WireGuard LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.wireguard.android.widget + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import com.google.android.material.card.MaterialCardView +import com.wireguard.android.R + +class TvCardView(context: Context?, attrs: AttributeSet?) : MaterialCardView(context, attrs) { + var isUp: Boolean = false + set(value) { + field = value + refreshDrawableState() + } + var isDeleting: Boolean = false + set(value) { + field = value + refreshDrawableState() + } + + override fun onCreateDrawableState(extraSpace: Int): IntArray { + if (isUp || isDeleting) { + val drawableState = super.onCreateDrawableState(extraSpace + (if (isUp) 1 else 0) + (if (isDeleting) 1 else 0)) + if (isUp) { + View.mergeDrawableStates(drawableState, STATE_IS_UP) + } + if (isDeleting) { + View.mergeDrawableStates(drawableState, STATE_IS_DELETING) + } + return drawableState + } + return super.onCreateDrawableState(extraSpace) + } + + companion object { + private val STATE_IS_UP = intArrayOf(R.attr.state_isUp) + private val STATE_IS_DELETING = intArrayOf(R.attr.state_isDeleting) + } +}
\ No newline at end of file |