summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/main/java/com/wireguard/android')
-rw-r--r--ui/src/main/java/com/wireguard/android/Application.kt6
-rw-r--r--ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt13
-rw-r--r--ui/src/main/java/com/wireguard/android/widget/TvCardView.kt44
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