summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-09-22 14:33:04 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-22 23:53:32 +0200
commitdc002d77fa514eb6526516f23beb7093654c23db (patch)
tree8a25707dc38f37b754e5b4bbd3d8875336b91102 /ui/src/main
parentaaa55c0dccd14a02af7df66fecf02884d4a708b9 (diff)
tv: begin to wire up databindings
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main')
-rw-r--r--ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt22
-rw-r--r--ui/src/main/res/layout/tv_activity.xml64
-rw-r--r--ui/src/main/res/layout/tv_tunnel_list_item.xml9
3 files changed, 48 insertions, 47 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 4b110a30..16873642 100644
--- a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
+++ b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt
@@ -8,14 +8,14 @@ package com.wireguard.android.activity
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
+import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
-import com.google.android.material.button.MaterialButton
-import com.wireguard.android.R
-import com.wireguard.android.model.ObservableTunnel
+import com.wireguard.android.Application
+import com.wireguard.android.databinding.TvActivityBinding
import com.wireguard.android.util.TunnelImporter
import kotlinx.coroutines.launch
-class TvMainActivity : BaseActivity() {
+class TvMainActivity : AppCompatActivity() {
private val tunnelFileImportResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { data ->
lifecycleScope.launch {
TunnelImporter.importTunnel(contentResolver, data) {
@@ -24,18 +24,14 @@ class TvMainActivity : BaseActivity() {
}
}
- override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?) {
- }
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.tv_activity)
- findViewById<MaterialButton>(R.id.import_button).setOnClickListener {
+ val binding = TvActivityBinding.inflate(layoutInflater)
+ lifecycleScope.launch { binding.tunnels = Application.getTunnelManager().getTunnels() }
+ binding.importButton.setOnClickListener {
tunnelFileImportResultLauncher.launch("*/*")
}
- }
-
- companion object {
- const val TAG = "WireGuard/TvMainActivity"
+ binding.executePendingBindings()
+ setContentView(binding.root)
}
}
diff --git a/ui/src/main/res/layout/tv_activity.xml b/ui/src/main/res/layout/tv_activity.xml
index 03caa311..33f13a17 100644
--- a/ui/src/main/res/layout/tv_activity.xml
+++ b/ui/src/main/res/layout/tv_activity.xml
@@ -1,31 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
+ xmlns:tools="http://schemas.android.com/tools">
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/tunnel_list"
+ <data>
+
+ <import type="com.wireguard.android.model.ObservableTunnel" />
+
+ <variable
+ name="tunnels"
+ type="com.wireguard.android.databinding.ObservableKeyedArrayList&lt;String, ObservableTunnel&gt;" />
+ </data>
+
+ <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="16dp"
- android:orientation="horizontal"
- app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
- app:layout_constraintBottom_toTopOf="@id/import_button"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- tools:itemCount="10"
- tools:listitem="@layout/tv_tunnel_list_item" />
+ android:layout_height="match_parent">
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/tunnel_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginTop="16dp"
+ android:orientation="horizontal"
+ app:items="@{tunnels}"
+ app:layout="@{@layout/tv_tunnel_list_item}"
+ app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
+ app:layout_constraintBottom_toTopOf="@id/import_button"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ tools:itemCount="10"
+ tools:listitem="@layout/tv_tunnel_list_item" />
- <com.google.android.material.button.MaterialButton
- android:id="@+id/import_button"
- style="?attr/textAppearanceButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:text="@string/create_from_file"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent" />
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/import_button"
+ style="?attr/textAppearanceButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:text="@string/create_from_file"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent" />
-</androidx.constraintlayout.widget.ConstraintLayout>
+ </androidx.constraintlayout.widget.ConstraintLayout>
+</layout> \ No newline at end of file
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 a48b977b..5611d579 100644
--- a/ui/src/main/res/layout/tv_tunnel_list_item.xml
+++ b/ui/src/main/res/layout/tv_tunnel_list_item.xml
@@ -10,21 +10,12 @@
<import type="com.wireguard.android.backend.Tunnel.State" />
<variable
- name="collection"
- type="com.wireguard.android.databinding.ObservableKeyedArrayList&lt;String, ObservableTunnel&gt;" />
-
- <variable
name="key"
type="String" />
<variable
name="item"
type="com.wireguard.android.model.ObservableTunnel" />
-
- <!-- Unused on TV but we retain this so the existing Adapter and ViewHolder can be reused -->
- <variable
- name="fragment"
- type="com.wireguard.android.fragment.TunnelListFragment" />
</data>
<com.google.android.material.card.MaterialCardView