aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreuxane2024-09-18 23:41:13 +0200
committereuxane2024-09-18 23:41:13 +0200
commitb39b80dc58b75ee5e2b32f4c8d112bb242074ecd (patch)
tree4eed0e85018c544523a6b390441009df084b2369
parentcc8c04bc72b97a66bac60f5c87892fea5fd804ae (diff)
downloadtincapp-b39b80dc58b75ee5e2b32f4c8d112bb242074ecd.tar.gz
dialogs: remove usage of kotlin synthetics
-rw-r--r--app/build.gradle1
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt8
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/configure/tools/ConfigurationToolDialogFragment.kt12
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/configure/tools/EncryptDecryptPrivateKeysToolDialogFragment.kt10
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/configure/tools/GenerateConfigToolDialogFragment.kt10
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkToolDialogFragment.kt19
6 files changed, 23 insertions, 37 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 7433b49..6fe715c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -69,6 +69,7 @@ android {
69 69
70 buildFeatures { 70 buildFeatures {
71 dataBinding = true 71 dataBinding = true
72 viewBinding = true
72 } 73 }
73 74
74 namespace 'org.pacien.tincapp' 75 namespace 'org.pacien.tincapp'
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt
index 12c2630..4888cd0 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt
@@ -19,11 +19,8 @@
19package org.pacien.tincapp.activities 19package org.pacien.tincapp.activities
20 20
21import android.content.Context 21import android.content.Context
22import androidx.annotation.LayoutRes
23import androidx.fragment.app.DialogFragment 22import androidx.fragment.app.DialogFragment
24import android.view.LayoutInflater 23import android.view.LayoutInflater
25import android.view.View
26import android.view.ViewGroup
27 24
28/** 25/**
29 * @author euxane 26 * @author euxane
@@ -31,8 +28,5 @@ import android.view.ViewGroup
31abstract class BaseDialogFragment : DialogFragment() { 28abstract class BaseDialogFragment : DialogFragment() {
32 protected val parentActivity by lazy { activity as BaseActivity } 29 protected val parentActivity by lazy { activity as BaseActivity }
33 // getLayoutInflater() calls onCreateDialog. See https://stackoverflow.com/a/15152788 30 // getLayoutInflater() calls onCreateDialog. See https://stackoverflow.com/a/15152788
34 private val inflater by lazy { activity!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater } 31 protected val dialogLayoutInflater by lazy { activity!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater }
35
36 fun inflate(@LayoutRes layout: Int) = inflater.inflate(layout, null)!!
37 fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(inflater, null, false)
38} 32}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/ConfigurationToolDialogFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/ConfigurationToolDialogFragment.kt
index 18e403a..533faa9 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/ConfigurationToolDialogFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/ConfigurationToolDialogFragment.kt
@@ -18,10 +18,9 @@
18 18
19package org.pacien.tincapp.activities.configure.tools 19package org.pacien.tincapp.activities.configure.tools
20 20
21import androidx.annotation.LayoutRes
22import androidx.annotation.StringRes 21import androidx.annotation.StringRes
23import androidx.appcompat.app.AlertDialog 22import androidx.appcompat.app.AlertDialog
24import android.view.View 23import androidx.viewbinding.ViewBinding
25import java8.util.concurrent.CompletableFuture 24import java8.util.concurrent.CompletableFuture
26import org.pacien.tincapp.R 25import org.pacien.tincapp.R
27import org.pacien.tincapp.activities.BaseDialogFragment 26import org.pacien.tincapp.activities.BaseDialogFragment
@@ -35,14 +34,11 @@ import java.util.regex.Pattern
35abstract class ConfigurationToolDialogFragment : BaseDialogFragment() { 34abstract class ConfigurationToolDialogFragment : BaseDialogFragment() {
36 private val networkNamePattern by lazy { Pattern.compile("^[^\\x00/]*$") } 35 private val networkNamePattern by lazy { Pattern.compile("^[^\\x00/]*$") }
37 36
38 protected fun makeDialog(@LayoutRes layout: Int, @StringRes title: Int, @StringRes applyButton: Int, applyAction: (View) -> Unit) = 37 protected fun <ViewBindingT: ViewBinding> makeDialog(viewBinding: ViewBindingT, @StringRes title: Int, @StringRes applyButton: Int, applyAction: (ViewBindingT) -> Unit) =
39 makeDialog(inflate(layout), title, applyButton, applyAction)
40
41 protected fun makeDialog(view: View, @StringRes title: Int, @StringRes applyButton: Int, applyAction: (View) -> Unit) =
42 AlertDialog.Builder(parentActivity) 38 AlertDialog.Builder(parentActivity)
43 .setTitle(title) 39 .setTitle(title)
44 .setView(view) 40 .setView(viewBinding.root)
45 .setPositiveButton(applyButton) { _, _ -> applyAction(view) } 41 .setPositiveButton(applyButton) { _, _ -> applyAction(viewBinding) }
46 .setNegativeButton(R.string.generic_action_cancel) { _, _ -> Unit } 42 .setNegativeButton(R.string.generic_action_cancel) { _, _ -> Unit }
47 .create()!! 43 .create()!!
48 44
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/EncryptDecryptPrivateKeysToolDialogFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/EncryptDecryptPrivateKeysToolDialogFragment.kt
index b58ace4..c583272 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/EncryptDecryptPrivateKeysToolDialogFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/EncryptDecryptPrivateKeysToolDialogFragment.kt
@@ -19,7 +19,7 @@
19package org.pacien.tincapp.activities.configure.tools 19package org.pacien.tincapp.activities.configure.tools
20 20
21import android.os.Bundle 21import android.os.Bundle
22import kotlinx.android.synthetic.main.configure_tools_dialog_encrypt_decrypt_keys.view.* 22import org.pacien.tincapp.databinding.ConfigureToolsDialogEncryptDecryptKeysBinding
23import org.pacien.tincapp.R 23import org.pacien.tincapp.R
24import org.pacien.tincapp.commands.TincApp 24import org.pacien.tincapp.commands.TincApp
25 25
@@ -29,14 +29,14 @@ import org.pacien.tincapp.commands.TincApp
29class EncryptDecryptPrivateKeysToolDialogFragment : ConfigurationToolDialogFragment() { 29class EncryptDecryptPrivateKeysToolDialogFragment : ConfigurationToolDialogFragment() {
30 override fun onCreateDialog(savedInstanceState: Bundle?) = 30 override fun onCreateDialog(savedInstanceState: Bundle?) =
31 makeDialog( 31 makeDialog(
32 R.layout.configure_tools_dialog_encrypt_decrypt_keys, 32 ConfigureToolsDialogEncryptDecryptKeysBinding.inflate(dialogLayoutInflater),
33 R.string.configure_tools_private_keys_encryption_title, 33 R.string.configure_tools_private_keys_encryption_title,
34 R.string.configure_tools_private_keys_encryption_action 34 R.string.configure_tools_private_keys_encryption_action
35 ) { dialog -> 35 ) { dialog ->
36 encryptDecryptPrivateKeys( 36 encryptDecryptPrivateKeys(
37 dialog.enc_dec_net_name.text.toString(), 37 dialog.encDecNetName.text.toString(),
38 dialog.enc_dec_current_passphrase.text.toString(), 38 dialog.encDecCurrentPassphrase.text.toString(),
39 dialog.enc_dec_new_passphrase.text.toString() 39 dialog.encDecNewPassphrase.text.toString()
40 ) 40 )
41 } 41 }
42 42
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/GenerateConfigToolDialogFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/GenerateConfigToolDialogFragment.kt
index 2440e21..62d3890 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/GenerateConfigToolDialogFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/GenerateConfigToolDialogFragment.kt
@@ -19,7 +19,7 @@
19package org.pacien.tincapp.activities.configure.tools 19package org.pacien.tincapp.activities.configure.tools
20 20
21import android.os.Bundle 21import android.os.Bundle
22import kotlinx.android.synthetic.main.configure_tools_dialog_network_generate.view.* 22import org.pacien.tincapp.databinding.ConfigureToolsDialogNetworkGenerateBinding
23import org.pacien.tincapp.R 23import org.pacien.tincapp.R
24import org.pacien.tincapp.commands.Tinc 24import org.pacien.tincapp.commands.Tinc
25import org.pacien.tincapp.commands.TincApp 25import org.pacien.tincapp.commands.TincApp
@@ -32,14 +32,14 @@ import org.pacien.tincapp.utils.makePublic
32class GenerateConfigToolDialogFragment : ConfigurationToolDialogFragment() { 32class GenerateConfigToolDialogFragment : ConfigurationToolDialogFragment() {
33 override fun onCreateDialog(savedInstanceState: Bundle?) = 33 override fun onCreateDialog(savedInstanceState: Bundle?) =
34 makeDialog( 34 makeDialog(
35 R.layout.configure_tools_dialog_network_generate, 35 ConfigureToolsDialogNetworkGenerateBinding.inflate(dialogLayoutInflater),
36 R.string.configure_tools_generate_config_title, 36 R.string.configure_tools_generate_config_title,
37 R.string.configure_tools_generate_config_action 37 R.string.configure_tools_generate_config_action
38 ) { dialog -> 38 ) { dialog ->
39 generateConf( 39 generateConf(
40 dialog.new_net_name.text.toString(), 40 dialog.newNetName.text.toString(),
41 dialog.new_node_name.text.toString(), 41 dialog.newNodeName.text.toString(),
42 dialog.new_passphrase.text.toString() 42 dialog.newPassphrase.text.toString()
43 ) 43 )
44 } 44 }
45 45
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkToolDialogFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkToolDialogFragment.kt
index 4460ddc..a7283bd 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkToolDialogFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkToolDialogFragment.kt
@@ -20,10 +20,8 @@ package org.pacien.tincapp.activities.configure.tools
20 20
21import android.content.Intent 21import android.content.Intent
22import android.os.Bundle 22import android.os.Bundle
23import android.view.View
24import com.google.zxing.integration.android.IntentIntegrator 23import com.google.zxing.integration.android.IntentIntegrator
25import com.google.zxing.integration.android.IntentResult