From 4f6dc804176b038f84ef83550b774cb8dccd31c4 Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: activities: remove usage of kotlin view synthetics --- .../org/pacien/tincapp/activities/BaseActivity.kt | 14 +++++--------- .../tincapp/activities/start/ConnectionStarter.kt | 13 ++++++------- .../tincapp/activities/start/StartActivity.kt | 8 +++++--- .../tincapp/activities/status/StatusActivity.kt | 8 +++++--- .../tincapp/activities/viewlog/ViewLogActivity.kt | 21 +++++++++++---------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index f92c111..18787a8 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -20,27 +20,26 @@ package org.pacien.tincapp.activities import android.content.Intent import android.os.Bundle -import androidx.annotation.LayoutRes import androidx.annotation.StringRes import com.google.android.material.snackbar.Snackbar import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import android.view.* -import kotlinx.android.synthetic.main.base_activity.* import org.pacien.tincapp.R import org.pacien.tincapp.context.App import org.pacien.tincapp.context.AppInfo +import org.pacien.tincapp.databinding.BaseActivityBinding /** * @author euxane */ abstract class BaseActivity : AppCompatActivity() { - private val rootView by lazy { base_activity_frame!! } + val rootView by lazy { BaseActivityBinding.inflate(layoutInflater).root } private var active = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - super.setContentView(R.layout.base_activity) + super.setContentView(rootView) } override fun onCreateOptionsMenu(m: Menu): Boolean { @@ -96,11 +95,8 @@ abstract class BaseActivity : AppCompatActivity() { if (active) super.runOnUiThread(action) } - fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, rootView, false)!! - fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(layoutInflater, rootView, false) - - fun notify(@StringRes msg: Int) = Snackbar.make(base_activity_frame, msg, Snackbar.LENGTH_LONG).show() - fun notify(msg: String) = Snackbar.make(base_activity_frame, msg, Snackbar.LENGTH_LONG).show() + fun notify(@StringRes msg: Int) = Snackbar.make(rootView, msg, Snackbar.LENGTH_LONG).show() + fun notify(msg: String) = Snackbar.make(rootView, msg, Snackbar.LENGTH_LONG).show() fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) .setTitle(R.string.generic_title_error).setMessage(msg) diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt b/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt index 6ae3954..05df357 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt @@ -21,9 +21,8 @@ package org.pacien.tincapp.activities.start import android.net.VpnService import androidx.appcompat.app.AlertDialog import android.view.inputmethod.EditorInfo -import kotlinx.android.synthetic.main.base_activity.* -import kotlinx.android.synthetic.main.dialog_decrypt_keys.view.* import org.pacien.tincapp.R +import org.pacien.tincapp.databinding.DialogDecryptKeysBinding import org.pacien.tincapp.service.TincVpnService import org.pacien.tincapp.utils.TincKeyring import org.pacien.tincapp.extensions.View.on @@ -54,18 +53,18 @@ class ConnectionStarter(private val parentActivity: StartActivity) { } private fun askForPassphrase() { - val dialogView = parentActivity.layoutInflater.inflate(R.layout.dialog_decrypt_keys, parentActivity.base_activity_frame, false) + val dialogViewBinding = DialogDecryptKeysBinding.inflate(parentActivity.layoutInflater, parentActivity.rootView, false) val dialog = AlertDialog.Builder(parentActivity) .setTitle(R.string.decrypt_key_modal_title) - .setView(dialogView) - .setPositiveButton(R.string.decrypt_key_modal_action_unlock) { _, _ -> tryStart(passphrase = dialogView.passphrase.text.toString()) } + .setView(dialogViewBinding.root) + .setPositiveButton(R.string.decrypt_key_modal_action_unlock) { _, _ -> tryStart(passphrase = dialogViewBinding.passphrase.text.toString()) } .setNegativeButton(R.string.decrypt_key_modal_action_cancel) { _, _ -> Unit } .create() - dialogView.passphrase.on(EditorInfo.IME_ACTION_DONE) { + dialogViewBinding.passphrase.on(EditorInfo.IME_ACTION_DONE) { dialog.dismiss() - tryStart(passphrase = dialogView.passphrase.text.toString()) + tryStart(passphrase = dialogViewBinding.passphrase.text.toString()) } dialog.show() diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt index 300c106..8194cdb 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt @@ -24,7 +24,6 @@ import android.os.Bundle import androidx.appcompat.app.AlertDialog import android.view.Menu import android.view.MenuItem -import kotlinx.android.synthetic.main.start_activity.* import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseActivity import org.pacien.tincapp.activities.common.ProgressModal @@ -32,6 +31,7 @@ import org.pacien.tincapp.activities.common.RecentCrashHandler import org.pacien.tincapp.activities.configure.ConfigureActivity import org.pacien.tincapp.activities.status.StatusActivity import org.pacien.tincapp.context.App +import org.pacien.tincapp.databinding.StartActivityBinding import org.pacien.tincapp.intent.Actions import org.pacien.tincapp.intent.BroadcastMapper import org.pacien.tincapp.service.TincVpnService @@ -48,11 +48,13 @@ class StartActivity : BaseActivity() { Actions.EVENT_ABORTED to this::onVpnStartError )) + private val startActivityBinding by lazy { StartActivityBinding.inflate(layoutInflater) } + private var connectDialog: AlertDialog? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.start_activity) + setContentView(startActivityBinding.root) initNetworkListFragment() if (intent.action == Actions.ACTION_CONNECT && intent.data?.schemeSpecificPart != null) @@ -60,7 +62,7 @@ class StartActivity : BaseActivity() { } private fun initNetworkListFragment() { - val fragment = start_activity_network_list_fragment as NetworkListFragment + val fragment = supportFragmentManager.findFragmentById(R.id.start_activity_network_list_fragment) as NetworkListFragment fragment.connectToNetworkAction = { netName -> connectToNetworkAction(netName) } } diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt index 40a3974..9104c6e 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt @@ -23,7 +23,6 @@ import android.os.Bundle import androidx.appcompat.app.AlertDialog import android.view.Menu import android.view.MenuItem -import kotlinx.android.synthetic.main.status_activity.* import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseActivity import org.pacien.tincapp.activities.common.FragmentListPagerAdapter @@ -34,6 +33,7 @@ import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment import org.pacien.tincapp.activities.status.nodes.NodeListFragment import org.pacien.tincapp.activities.status.subnets.SubnetListFragment import org.pacien.tincapp.activities.viewlog.ViewLogActivity +import org.pacien.tincapp.databinding.StatusActivityBinding import org.pacien.tincapp.intent.Actions import org.pacien.tincapp.intent.BroadcastMapper import org.pacien.tincapp.service.TincVpnService @@ -53,13 +53,15 @@ class StatusActivity : BaseActivity() { R.string.status_activity_title_subnet_list to SubnetListFragment() ) + private val statusActivityBinding by lazy { StatusActivityBinding.inflate(layoutInflater) } + private var shutdownDialog: AlertDialog? = null private var listNetworksAfterExit = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.status_activity) - status_activity_pager.adapter = pagerAdapter + setContentView(statusActivityBinding.root) + statusActivityBinding.root.adapter = pagerAdapter supportActionBar.subtitle = getString(R.string.status_activity_state_connected_to_format, netName) handleStartIntentAction(intent.action) } diff --git a/app/src/main/java/org/pacien/tincapp/activities/viewlog/ViewLogActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/viewlog/ViewLogActivity.kt index 052f2fb..d0446f8 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/viewlog/ViewLogActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/viewlog/ViewLogActivity.kt @@ -26,14 +26,15 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.ScrollView -import kotlinx.android.synthetic.main.view_log_activity.* import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseActivity +import org.pacien.tincapp.databinding.ViewLogActivityBinding /** * @author euxane */ class ViewLogActivity : BaseActivity() { + private val viewLogActivityBinding by lazy { ViewLogActivityBinding.inflate(layoutInflater) } private val viewModel by lazy { ViewModelProviders.of(this).get(LogViewModel::class.java) } private val logObserver: Observer> = Observer { showLog(it) } private var toggleButton: MenuItem? = null @@ -41,7 +42,7 @@ class ViewLogActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) supportActionBar.setDisplayHomeAsUpEnabled(true) - setContentView(R.layout.view_log_activity) + setContentView(viewLogActivityBinding.root) enableLogging(viewModel.logging) } @@ -85,9 +86,9 @@ class ViewLogActivity : BaseActivity() { private fun showLog(logLines: List?) { val logSnippet = logLines?.joinToString("\n\n") ?: "" - log_view_text.post { - log_view_text.text = logSnippet - log_view_frame.scrollToBottom() + viewLogActivityBinding.logViewText.post { + viewLogActivityBinding.logViewText.text = logSnippet + viewLogActivityBinding.logViewFrame.scrollToBottom() } } @@ -109,13 +110,13 @@ class ViewLogActivity : BaseActivity() { private fun enableScrolling(enabled: Boolean) { if (enabled) - log_view_frame.setOnTouchListener(null) + viewLogActivityBinding.logViewFrame.setOnTouchListener(null) else - log_view_frame.setOnTouchListener { _, _ -> true } + viewLogActivityBinding.logViewFrame.setOnTouchListener { _, _ -> true } - log_view_frame.isSmoothScrollingEnabled = enabled - log_view_text.setTextIsSelectable(enabled) - log_view_frame.scrollToBottom() + viewLogActivityBinding.logViewFrame.isSmoothScrollingEnabled = enabled + viewLogActivityBinding.logViewText.setTextIsSelectable(enabled) + viewLogActivityBinding.logViewFrame.scrollToBottom() } private fun ScrollView.scrollToBottom() { -- cgit v1.2.3