File tree Expand file tree Collapse file tree 12 files changed +80
-53
lines changed
java/com/wireguard/android Expand file tree Collapse file tree 12 files changed +80
-53
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ import androidx.datastore.preferences.core.PreferenceDataStoreFactory
17
17
import androidx.datastore.preferences.core.Preferences
18
18
import androidx.datastore.preferences.preferencesDataStoreFile
19
19
import com.google.android.material.color.DynamicColors
20
- import com.google.android.material.color.DynamicColorsOptions
21
- import com.wireguard.android.activity.TvMainActivity
22
20
import com.wireguard.android.backend.Backend
23
21
import com.wireguard.android.backend.GoBackend
24
22
import com.wireguard.android.backend.WgQuickBackend
@@ -89,9 +87,7 @@ class Application : android.app.Application() {
89
87
override fun onCreate () {
90
88
Log .i(TAG , USER_AGENT )
91
89
super .onCreate()
92
- DynamicColors .applyToActivitiesIfAvailable(this ,
93
- // TODO: Remove this second argument once the TV theme has a proper M3 color palette.
94
- DynamicColorsOptions .Builder ().setPrecondition { activity, _ -> activity !is TvMainActivity }.build())
90
+ DynamicColors .applyToActivitiesIfAvailable(this )
95
91
rootShell = RootShell (applicationContext)
96
92
toolsInstaller = ToolsInstaller (applicationContext, rootShell)
97
93
preferencesDataStore = PreferenceDataStoreFactory .create { applicationContext.preferencesDataStoreFile(" settings" ) }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import com.wireguard.android.R
23
23
import com.wireguard.android.databinding.ObservableKeyedRecyclerViewAdapter.RowConfigurationHandler
24
24
import com.wireguard.android.widget.ToggleSwitch
25
25
import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener
26
+ import com.wireguard.android.widget.TvCardView
26
27
import com.wireguard.config.Attribute
27
28
import com.wireguard.config.InetNetwork
28
29
import java.net.InetAddress
@@ -168,4 +169,16 @@ object BindingAdapters {
168
169
0
169
170
}
170
171
}
172
+
173
+ @JvmStatic
174
+ @BindingAdapter(" isUp" )
175
+ fun setIsUp (card : TvCardView , up : Boolean ) {
176
+ card.isUp = up
177
+ }
178
+
179
+ @JvmStatic
180
+ @BindingAdapter(" isDeleting" )
181
+ fun setIsDeleting (card : TvCardView , deleting : Boolean ) {
182
+ card.isDeleting = deleting
183
+ }
171
184
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © 2017-2023 WireGuard LLC. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ package com.wireguard.android.widget
7
+
8
+ import android.content.Context
9
+ import android.util.AttributeSet
10
+ import android.view.View
11
+ import com.google.android.material.card.MaterialCardView
12
+ import com.wireguard.android.R
13
+
14
+ class TvCardView (context : Context ? , attrs : AttributeSet ? ) : MaterialCardView(context, attrs) {
15
+ var isUp: Boolean = false
16
+ set(value) {
17
+ field = value
18
+ refreshDrawableState()
19
+ }
20
+ var isDeleting: Boolean = false
21
+ set(value) {
22
+ field = value
23
+ refreshDrawableState()
24
+ }
25
+
26
+ override fun onCreateDrawableState (extraSpace : Int ): IntArray {
27
+ if (isUp || isDeleting) {
28
+ val drawableState = super .onCreateDrawableState(extraSpace + (if (isUp) 1 else 0 ) + (if (isDeleting) 1 else 0 ))
29
+ if (isUp) {
30
+ View .mergeDrawableStates(drawableState, STATE_IS_UP )
31
+ }
32
+ if (isDeleting) {
33
+ View .mergeDrawableStates(drawableState, STATE_IS_DELETING )
34
+ }
35
+ return drawableState
36
+ }
37
+ return super .onCreateDrawableState(extraSpace)
38
+ }
39
+
40
+ companion object {
41
+ private val STATE_IS_UP = intArrayOf(R .attr.state_isUp)
42
+ private val STATE_IS_DELETING = intArrayOf(R .attr.state_isDeleting)
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <selector xmlns : android =" http://schemas.android.com/apk/res/android"
3
+ xmlns : app =" http://schemas.android.com/apk/res-auto" >
4
+ <item app : state_isUp =" true" app : state_isDeleting =" false" android : color =" ?attr/colorPrimaryInverse" />
5
+ <item android : state_focused =" true" app : state_isDeleting =" true" android : color =" ?attr/colorErrorContainer" />
6
+ <item android : color =" ?attr/colorOnSurfaceInverse" />
7
+ </selector >
Original file line number Diff line number Diff line change 135
135
android : visibility =" @{isDeleting ? View.GONE : View.VISIBLE}"
136
136
app : icon =" @{filesRoot.isEmpty ? @drawable/ic_action_add_white : @drawable/ic_arrow_back}"
137
137
app : iconPadding =" 0dp"
138
- app : iconTint =" ?attr/colorOnPrimary"
139
138
app : layout_constraintBottom_toBottomOf =" parent"
140
139
app : layout_constraintEnd_toEndOf =" parent" />
141
140
149
148
android : visibility =" @{((tunnels.isEmpty && !isDeleting) || !filesRoot.isEmpty) ? View.GONE : View.VISIBLE}"
150
149
app : icon =" @{isDeleting ? @drawable/ic_arrow_back : @drawable/ic_action_delete}"
151
150
app : iconPadding =" 0dp"
152
- app : iconTint =" ?attr/colorOnPrimary"
153
151
app : layout_constraintBottom_toBottomOf =" parent"
154
152
app : layout_constraintStart_toStartOf =" parent" />
155
153
</androidx .constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change 21
21
android : layout_margin =" 8dp"
22
22
android : layout_marginTop =" 4dp"
23
23
android : layout_marginBottom =" 0dp"
24
- android : backgroundTint =" @color/tv_card_background"
25
24
android : checkable =" true"
26
25
android : focusable =" true"
27
26
app : contentPadding =" 8dp" >
35
34
android : layout_height =" wrap_content"
36
35
android : text =" @{key}"
37
36
android : textAppearance =" ?attr/textAppearanceTitleLarge"
38
- android : textColor =" ?attr/colorOnPrimary"
39
37
app : layout_constraintStart_toStartOf =" parent"
40
38
app : layout_constraintTop_toTopOf =" parent" />
41
39
Original file line number Diff line number Diff line change 28
28
type =" com.wireguard.android.model.ObservableTunnel" />
29
29
</data >
30
30
31
- <com .google .android.material.card.MaterialCardView
31
+ <com .wireguard .android.widget.TvCardView
32
32
android : layout_width =" 225dp"
33
33
android : layout_height =" 110dp"
34
34
android : layout_margin =" 8dp"
35
35
android : layout_marginTop =" 4dp"
36
36
android : layout_marginBottom =" 0dp"
37
+ android : backgroundTint =" @color/tv_list_item_tint"
37
38
android : checkable =" true"
38
39
android : focusable =" true"
39
40
app : contentPadding =" 8dp"
40
- android : backgroundTint =" @{(item.state == State.UP && !isDeleting) ? @color/tv_secondary_dark_color : (isDeleting && isFocused) ? @color/tv_card_delete_background : @color/tv_card_background}" >
41
+ app : isDeleting =" @{isDeleting}"
42
+ app : isUp =" @{item.state == State.UP}" >
41
43
42
44
<androidx .constraintlayout.widget.ConstraintLayout
43
45
android : layout_width =" match_parent"
49
51
android : layout_height =" wrap_content"
50
52
android : text =" @{item.name}"
51
53
android : textAppearance =" ?attr/textAppearanceTitleLarge"
52
- android : textColor =" ?attr/colorOnPrimary"
53
54
app : layout_constraintStart_toStartOf =" parent"
54
55
app : layout_constraintTop_toTopOf =" parent"
55
56
tools : text =" @sample/interface_names.json/names/names/name" />
76
77
77
78
</androidx .constraintlayout.widget.ConstraintLayout>
78
79
79
- </com .google .android.material.card.MaterialCardView >
80
+ </com .wireguard .android.widget.TvCardView >
80
81
81
82
</layout >
Original file line number Diff line number Diff line change 4
4
<attr name =" state_multiselected" format =" boolean" />
5
5
<attr name =" colorMultiselectActiveBackground" format =" reference|color" />
6
6
</declare-styleable >
7
+ <declare-styleable name =" TvCardView" >
8
+ <attr name =" state_isUp" format =" boolean" />
9
+ <attr name =" state_isDeleting" format =" boolean" />
10
+ </declare-styleable >
7
11
</resources >
File renamed without changes.
Original file line number Diff line number Diff line change 12
12
</style >
13
13
14
14
<!-- Various additional API-specific features in values-v*/styles.xml -->
15
- <style name =" AppTheme" parent =" AppThemeBase" />
15
+ <style name =" AppTheme" parent =" AppThemeBase" />
16
16
17
17
<style name =" WireGuardTheme.MaterialCardView" parent =" Widget.Material3.CardView.Elevated" >
18
18
<item name =" cornerRadius" >4dp</item >
36
36
<item name =" android:windowEnterAnimation" >@android:anim/fade_in</item >
37
37
<item name =" android:windowExitAnimation" >@android:anim/fade_out</item >
38
38
</style >
39
+
40
+ <style name =" TvTheme" parent =" AppTheme" >
41
+ <item name =" windowActionBar" >false</item >
42
+ <item name =" windowNoTitle" >true</item >
43
+ </style >
39
44
</resources >
You can’t perform that action at this time.
0 commit comments