Skip to content

Commit e72b4fc

Browse files
committed
tv: hook up isFocused as observable property
This is kind of ridiculous, since the items own state should clearly be queryable, but it doesn't appear to be the case here, so just shuffle it around into kotlin and back. Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 03189e7 commit e72b4fc

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class TvMainActivity : AppCompatActivity() {
7979
binding.rowConfigurationHandler = object : ObservableKeyedRecyclerViewAdapter.RowConfigurationHandler<TvTunnelListItemBinding, ObservableTunnel> {
8080
override fun onConfigureRow(binding: TvTunnelListItemBinding, item: ObservableTunnel, position: Int) {
8181
binding.isDeleting = isDeleting
82+
binding.isFocused = ObservableBoolean()
83+
binding.root.setOnFocusChangeListener { _, focused ->
84+
binding.isFocused?.set(focused)
85+
}
8286
binding.root.setOnClickListener {
8387
lifecycleScope.launch {
8488
if (isDeleting.get()) {

ui/src/main/res/layout/tv_tunnel_list_item.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
name="isDeleting"
1616
type="androidx.databinding.ObservableBoolean" />
1717

18+
<variable
19+
name="isFocused"
20+
type="androidx.databinding.ObservableBoolean" />
21+
1822
<variable
1923
name="key"
2024
type="String" />
@@ -24,16 +28,15 @@
2428
type="com.wireguard.android.model.ObservableTunnel" />
2529
</data>
2630

27-
<!-- Rather than changing the background tint to red for deleting mode, it should instead just change the selection color -->
2831
<com.google.android.material.card.MaterialCardView
2932
android:layout_width="225dp"
3033
android:layout_height="110dp"
3134
android:layout_margin="8dp"
3235
android:layout_marginTop="4dp"
3336
android:layout_marginBottom="0dp"
34-
android:backgroundTint="@{isDeleting ? @color/error_tag_color : item.state == State.UP ? @color/secondary_dark_color : @color/tv_card_background}"
3537
android:checkable="true"
3638
android:focusable="true"
39+
android:backgroundTint="@{(item.state == State.UP &amp;&amp; !isDeleting) ? @color/secondary_dark_color : (isDeleting &amp;&amp; isFocused) ? @color/tv_card_delete_background : @color/tv_card_background}"
3740
app:contentPadding="8dp">
3841

3942
<androidx.constraintlayout.widget.ConstraintLayout
@@ -61,13 +64,12 @@
6164
app:layout_constraintStart_toStartOf="parent"
6265
tools:text="rx: 200 MB, tx: 100 MB" />
6366

64-
<!-- TODO: replace the "&amp;&amp; true" stuff with && isSelected() -->
6567
<com.google.android.material.textview.MaterialTextView
6668
android:id="@+id/tunnel_delete"
6769
android:layout_width="wrap_content"
6870
android:layout_height="wrap_content"
6971
android:text="@string/tv_delete"
70-
android:visibility="@{isDeleting &amp;&amp; true ? View.VISIBLE : View.GONE}"
72+
android:visibility="@{(isDeleting &amp;&amp; isFocused) ? View.VISIBLE : View.GONE}"
7173
app:layout_constraintBottom_toBottomOf="parent"
7274
app:layout_constraintStart_toStartOf="parent"
7375
tools:visibility="gone" />

ui/src/main/res/values/tv_colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<resources>
33
<color name="tv_primary_color">#ff212121</color>
44
<color name="tv_card_background">@color/tv_primary_color</color>
5+
<color name="tv_card_delete_background">#b00020</color>
56
</resources>

0 commit comments

Comments
 (0)