diff options
Diffstat (limited to 'app')
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 @@ | |||
19 | package org.pacien.tincapp.activities | 19 | package org.pacien.tincapp.activities |
20 | 20 | ||
21 | import android.content.Context | 21 | import android.content.Context |
22 | import androidx.annotation.LayoutRes | ||
23 | import androidx.fragment.app.DialogFragment | 22 | import androidx.fragment.app.DialogFragment |
24 | import android.view.LayoutInflater | 23 | import android.view.LayoutInflater |
25 | import android.view.View | ||
26 | import android.view.ViewGroup | ||
27 | 24 | ||
28 | /** | 25 | /** |
29 | * @author euxane | 26 | * @author euxane |
@@ -31,8 +28,5 @@ import android.view.ViewGroup | |||
31 | abstract class BaseDialogFragment : DialogFragment() { | 28 | abstract 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 | ||
19 | package org.pacien.tincapp.activities.configure.tools | 19 | package org.pacien.tincapp.activities.configure.tools |
20 | 20 | ||
21 | import androidx.annotation.LayoutRes | ||
22 | import androidx.annotation.StringRes | 21 | import androidx.annotation.StringRes |
23 | import androidx.appcompat.app.AlertDialog | 22 | import androidx.appcompat.app.AlertDialog |
24 | import android.view.View | 23 | import androidx.viewbinding.ViewBinding |
25 | import java8.util.concurrent.CompletableFuture | 24 | import java8.util.concurrent.CompletableFuture |
26 | import org.pacien.tincapp.R | 25 | import org.pacien.tincapp.R |
27 | import org.pacien.tincapp.activities.BaseDialogFragment | 26 | import org.pacien.tincapp.activities.BaseDialogFragment |
@@ -35,14 +34,11 @@ import java.util.regex.Pattern | |||
35 | abstract class ConfigurationToolDialogFragment : BaseDialogFragment() { | 34 | abstract 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 @@ | |||
19 | package org.pacien.tincapp.activities.configure.tools | 19 | package org.pacien.tincapp.activities.configure.tools |
20 | 20 | ||
21 | import android.os.Bundle | 21 | import android.os.Bundle |
22 | import kotlinx.android.synthetic.main.configure_tools_dialog_encrypt_decrypt_keys.view.* | 22 | import org.pacien.tincapp.databinding.ConfigureToolsDialogEncryptDecryptKeysBinding |
23 | import org.pacien.tincapp.R | 23 | import org.pacien.tincapp.R |
24 | import org.pacien.tincapp.commands.TincApp | 24 | import org.pacien.tincapp.commands.TincApp |
25 | 25 | ||
@@ -29,14 +29,14 @@ import org.pacien.tincapp.commands.TincApp | |||
29 | class EncryptDecryptPrivateKeysToolDialogFragment : ConfigurationToolDialogFragment() { | 29 | class 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 @@ | |||
19 | package org.pacien.tincapp.activities.configure.tools | 19 | package org.pacien.tincapp.activities.configure.tools |
20 | 20 | ||
21 | import android.os.Bundle | 21 | import android.os.Bundle |
22 | import kotlinx.android.synthetic.main.configure_tools_dialog_network_generate.view.* | 22 | import org.pacien.tincapp.databinding.ConfigureToolsDialogNetworkGenerateBinding |
23 | import org.pacien.tincapp.R | 23 | import org.pacien.tincapp.R |
24 | import org.pacien.tincapp.commands.Tinc | 24 | import org.pacien.tincapp.commands.Tinc |
25 | import org.pacien.tincapp.commands.TincApp | 25 | import org.pacien.tincapp.commands.TincApp |
@@ -32,14 +32,14 @@ import org.pacien.tincapp.utils.makePublic | |||
32 | class GenerateConfigToolDialogFragment : ConfigurationToolDialogFragment() { | 32 | class 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 | ||
21 | import android.content.Intent | 21 | import android.content.Intent |
22 | import android.os.Bundle | 22 | import android.os.Bundle |
23 | import android.view.View | ||
24 | import com.google.zxing.integration.android.IntentIntegrator | 23 | import com.google.zxing.integration.android.IntentIntegrator |
25 | import com.google.zxing.integration.android.IntentResult | 24 | import com.google.zxing.integration.android.IntentResult |
26 | import kotlinx.android.synthetic.main.configure_tools_dialog_network_join.view.* | ||