diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-22 23:50:26 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-22 23:54:41 +0200 |
commit | e72b4fc144e642eb99328d637549d805c14d9033 (patch) | |
tree | 1c9a4fe9c409ecc18f86f71b41d30660a21deaa7 | |
parent | 03189e7b20b326b83ab484c436214f1610334c73 (diff) |
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 <Jason@zx2c4.com>
-rw-r--r-- | ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt | 4 | ||||
-rw-r--r-- | ui/src/main/res/layout/tv_tunnel_list_item.xml | 10 | ||||
-rw-r--r-- | ui/src/main/res/values/tv_colors.xml | 1 |
3 files changed, 11 insertions, 4 deletions
diff --git a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt index 2b12d545..1528ac95 100644 --- a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt @@ -79,6 +79,10 @@ class TvMainActivity : AppCompatActivity() { binding.rowConfigurationHandler = object : ObservableKeyedRecyclerViewAdapter.RowConfigurationHandler<TvTunnelListItemBinding, ObservableTunnel> { override fun onConfigureRow(binding: TvTunnelListItemBinding, item: ObservableTunnel, position: Int) { binding.isDeleting = isDeleting + binding.isFocused = ObservableBoolean() + binding.root.setOnFocusChangeListener { _, focused -> + binding.isFocused?.set(focused) + } binding.root.setOnClickListener { lifecycleScope.launch { if (isDeleting.get()) { diff --git a/ui/src/main/res/layout/tv_tunnel_list_item.xml b/ui/src/main/res/layout/tv_tunnel_list_item.xml index 0eedd87c..c45abd08 100644 --- a/ui/src/main/res/layout/tv_tunnel_list_item.xml +++ b/ui/src/main/res/layout/tv_tunnel_list_item.xml @@ -16,6 +16,10 @@ type="androidx.databinding.ObservableBoolean" /> <variable + name="isFocused" + type="androidx.databinding.ObservableBoolean" /> + + <variable name="key" type="String" /> @@ -24,16 +28,15 @@ type="com.wireguard.android.model.ObservableTunnel" /> </data> - <!-- Rather than changing the background tint to red for deleting mode, it should instead just change the selection color --> <com.google.android.material.card.MaterialCardView android:layout_width="225dp" android:layout_height="110dp" android:layout_margin="8dp" android:layout_marginTop="4dp" android:layout_marginBottom="0dp" - android:backgroundTint="@{isDeleting ? @color/error_tag_color : item.state == State.UP ? @color/secondary_dark_color : @color/tv_card_background}" android:checkable="true" android:focusable="true" + android:backgroundTint="@{(item.state == State.UP && !isDeleting) ? @color/secondary_dark_color : (isDeleting && isFocused) ? @color/tv_card_delete_background : @color/tv_card_background}" app:contentPadding="8dp"> <androidx.constraintlayout.widget.ConstraintLayout @@ -61,13 +64,12 @@ app:layout_constraintStart_toStartOf="parent" tools:text="rx: 200 MB, tx: 100 MB" /> - <!-- TODO: replace the "&& true" stuff with && isSelected() --> <com.google.android.material.textview.MaterialTextView android:id="@+id/tunnel_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_delete" - android:visibility="@{isDeleting && true ? View.VISIBLE : View.GONE}" + android:visibility="@{(isDeleting && isFocused) ? View.VISIBLE : View.GONE}" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" tools:visibility="gone" /> diff --git a/ui/src/main/res/values/tv_colors.xml b/ui/src/main/res/values/tv_colors.xml index b202d2a2..f330bedc 100644 --- a/ui/src/main/res/values/tv_colors.xml +++ b/ui/src/main/res/values/tv_colors.xml @@ -2,4 +2,5 @@ <resources> <color name="tv_primary_color">#ff212121</color> <color name="tv_card_background">@color/tv_primary_color</color> + <color name="tv_card_delete_background">#b00020</color> </resources> |