From 286bd6c17baa050854f4354c502f89b2e16e59bd Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: treewide: apply trivial lints --- app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt | 4 ++-- .../main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt | 2 +- .../org/pacien/tincapp/activities/common/RecentCrashHandler.kt | 2 +- .../activities/configure/tools/ConfigurationToolDialogFragment.kt | 4 ++-- .../java/org/pacien/tincapp/activities/start/ConnectionStarter.kt | 2 +- .../pacien/tincapp/activities/start/ErrorNotificationFragment.kt | 4 ++-- .../org/pacien/tincapp/activities/start/NetworkListFragment.kt | 7 +++---- .../status/networkinfo/VpnInterfaceConfigurationFormatter.kt | 2 +- .../org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt | 4 ++-- .../pacien/tincapp/activities/status/subnets/SubnetListFragment.kt | 2 +- .../java/org/pacien/tincapp/activities/viewlog/ViewLogActivity.kt | 2 +- app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 6 +++--- .../main/java/org/pacien/tincapp/context/AppNotificationManager.kt | 2 +- 13 files changed, 21 insertions(+), 22 deletions(-) (limited to 'app') 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 6f18565..4e9f983 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -87,7 +87,7 @@ abstract class BaseActivity : AppCompatActivity() { resources.getString(R.string.about_app_license) + "\n\n" + AppInfo.all()) .setNeutralButton(R.string.about_app_open_project_website) { _, _ -> App.openURL(resources.getString(R.string.about_app_website_url)) } - .setPositiveButton(R.string.generic_action_close) { _, _ -> Unit } + .setPositiveButton(R.string.generic_action_close) { _, _ -> } .show() } @@ -104,7 +104,7 @@ abstract class BaseActivity : AppCompatActivity() { fun showErrorDialog(msg: String, docTopic: String? = null): AlertDialog = AlertDialog.Builder(this) .setTitle(R.string.generic_title_error).setMessage(msg) - .setPositiveButton(R.string.generic_action_close) { _, _ -> Unit } + .setPositiveButton(R.string.generic_action_close) { _, _ -> } .apply { if (docTopic != null) setNeutralButton(R.string.notification_error_action_open_manual) { _, _ -> 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 4888cd0..05eadd5 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseDialogFragment.kt @@ -28,5 +28,5 @@ import android.view.LayoutInflater abstract class BaseDialogFragment : DialogFragment() { protected val parentActivity by lazy { activity as BaseActivity } // getLayoutInflater() calls onCreateDialog. See https://stackoverflow.com/a/15152788 - protected val dialogLayoutInflater by lazy { activity!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater } + protected val dialogLayoutInflater by lazy { requireActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater } } diff --git a/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt index 8f53e08..92f82c2 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt @@ -42,7 +42,7 @@ class RecentCrashHandler(private val parentActivity: BaseActivity) { .setTitle(R.string.crash_modal_title) .setMessage(makeMessage()) .setNeutralButton(R.string.crash_modal_action_send_report) { _, _ -> sendReportMail() } - .setPositiveButton(R.string.generic_action_close) { _, _ -> Unit } + .setPositiveButton(R.string.generic_action_close) { _, _ -> } .show() } 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 533faa9..c146c24 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 @@ -39,8 +39,8 @@ abstract class ConfigurationToolDialogFragment : BaseDialogFragment() { .setTitle(title) .setView(viewBinding.root) .setPositiveButton(applyButton) { _, _ -> applyAction(viewBinding) } - .setNegativeButton(R.string.generic_action_cancel) { _, _ -> Unit } - .create()!! + .setNegativeButton(R.string.generic_action_cancel) { _, _ -> } + .create() protected fun execAction(@StringRes label: Int, action: CompletableFuture) { ProgressModal.show(parentActivity, getString(label)).let { progressDialog -> 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 05df357..ef94489 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 @@ -59,7 +59,7 @@ class ConnectionStarter(private val parentActivity: StartActivity) { .setTitle(R.string.decrypt_key_modal_title) .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 } + .setNegativeButton(R.string.decrypt_key_modal_action_cancel) { _, _ -> } .create() dialogViewBinding.passphrase.on(EditorInfo.IME_ACTION_DONE) { diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/ErrorNotificationFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/start/ErrorNotificationFragment.kt index fdfa8f6..08dab8d 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/start/ErrorNotificationFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/start/ErrorNotificationFragment.kt @@ -32,11 +32,11 @@ import org.pacien.tincapp.databinding.StartErrorNotificationBinding * @author euxane */ class ErrorNotificationFragment : BaseFragment() { - private val notificationManager by lazy { AppNotificationManager(context!!) } + private val notificationManager by lazy { AppNotificationManager(requireContext()) } private val notificationListener = OnSharedPreferenceChangeListener { _, _ -> updateView() } private lateinit var viewBinding: StartErrorNotificationBinding - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { viewBinding = StartErrorNotificationBinding.inflate(inflater, container, false) updateView() return viewBinding.root diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt index fc5b6ff..988e877 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt @@ -18,7 +18,6 @@ package org.pacien.tincapp.activities.start -import androidx.lifecycle.Observer import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -40,14 +39,14 @@ class NetworkListFragment : BaseFragment() { private val networkListViewModel by lazy { NetworkListViewModel() } private val networkListAdapter by lazy { ArrayAdapter(requireContext(), R.layout.start_network_list_item) } private lateinit var startNetworkListBinding: StartNetworkListBinding - var connectToNetworkAction = { _: String -> Unit } + var connectToNetworkAction = { _: String -> } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - networkListViewModel.networkList.observe(this, Observer { updateNetworkList(it.orEmpty()) }) + networkListViewModel.networkList.observe(this) { updateNetworkList(it.orEmpty()) } } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { startNetworkListBinding = StartNetworkListBinding.inflate(inflater, container, false) return startNetworkListBinding.root } diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/VpnInterfaceConfigurationFormatter.kt b/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/VpnInterfaceConfigurationFormatter.kt index 92d6312..c8a6c0e 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/VpnInterfaceConfigurationFormatter.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/VpnInterfaceConfigurationFormatter.kt @@ -29,7 +29,7 @@ object VpnInterfaceConfigurationFormatter { private val resources by lazy { App.getResources() } fun formatList(list: List?) = when { - list != null && list.isNotEmpty() -> list.joinToString("\n", transform = this::formatListElement) + !list.isNullOrEmpty() -> list.joinToString("\n", transform = this::formatListElement) else -> resources.getString(R.string.status_network_info_value_none) } diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt index b96e5fb..627cae4 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt @@ -42,7 +42,7 @@ class NodeListFragment : BaseFragment() { private val vpnService = TincVpnService private val tincCtl = Tinc private val netName by lazy { vpnService.getCurrentNetName()!! } - private val nodeListViewModel by lazy { ViewModelProvider(this).get(NodeListViewModel::class.java) } + private val nodeListViewModel by lazy { ViewModelProvider(this)[NodeListViewModel::class.java] } private val nodeListAdapter by lazy { NodeInfoArrayAdapter(requireContext(), this::onItemClick) } private lateinit var statusNodeListFragmentBinding: StatusNodeListFragmentBinding @@ -79,7 +79,7 @@ class NodeListFragment : BaseFragment() { AlertDialog.Builder(requireContext()) .setTitle(R.string.status_node_info_dialog_title) .setView(dialogTextViewBinding.root) - .setPositiveButton(R.string.status_node_info_dialog_close_action) { _, _ -> Unit } + .setPositiveButton(R.string.status_node_info_dialog_close_action) { _, _ -> } .show() tincCtl.info(netName, nodeName).thenAccept { nodeInfo -> diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt index c842323..edc0e0f 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt @@ -34,7 +34,7 @@ import org.pacien.tincapp.extensions.setElements * @author euxane */ class SubnetListFragment : BaseFragment() { - private val subnetListViewModel by lazy { ViewModelProviders.of(this).get(SubnetListViewModel::class.java) } + private val subnetListViewModel by lazy { ViewModelProviders.of(this)[SubnetListViewModel::class.java] } private val subnetListAdapter by lazy { SubnetInfoArrayAdapter(requireContext()) } private val subnetListObserver by lazy { Observer> { subnetListAdapter.setElements(it) } } private lateinit var statusSubnetListFragmentBinding: StatusSubnetListFragmentBinding 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 d0446f8..d559334 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 @@ -35,7 +35,7 @@ import org.pacien.tincapp.databinding.ViewLogActivityBinding */ 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 viewModel by lazy { ViewModelProviders.of(this)[LogViewModel::class.java] } private val logObserver: Observer> = Observer { showLog(it) } private var toggleButton: MenuItem? = null diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index 883430c..b9860fb 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt @@ -53,7 +53,7 @@ object Tinc { fun info(netName: String, node: String): CompletableFuture = Executor.call(newCommand(netName).withArguments("info", node)) - .thenApply { it.joinToString("\n") } + .thenApply { it.joinToString("\n") } fun init(netName: String, nodeName: String): CompletableFuture = if (netName.isBlank()) @@ -62,7 +62,7 @@ object Tinc { Executor.call(Command(AppPaths.tinc().absolutePath) .withOption("config", AppPaths.confDir(netName).absolutePath) .withArguments("init", nodeName)) - .thenApply { it.joinToString("\n") } + .thenApply { it.joinToString("\n") } fun join(netName: String, invitationUrl: String): CompletableFuture = if (netName.isBlank()) @@ -71,7 +71,7 @@ object Tinc { Executor.call(Command(AppPaths.tinc().absolutePath) .withOption("config", AppPaths.confDir(netName).absolutePath) .withArguments("join", invitationUrl)) - .thenApply { it.joinToString("\n") } + .thenApply { it.joinToString("\n") } fun log(netName: String, level: Int? = null): Process = Executor.run(newCommand(netName) diff --git a/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt b/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt index 907a948..c7a5ade 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt @@ -41,7 +41,7 @@ class AppNotificationManager(private val context: Context) { private val store by lazy { context.getSharedPreferences(STORE_NAME, Context.MODE_PRIVATE)!! } fun getError(): ErrorNotification? { - if (!store.contains(STORE_KEY_TITLE)) return null; + if (!store.contains(STORE_KEY_TITLE)) return null return ErrorNotification( store.getString(STORE_KEY_TITLE, null)!!, -- cgit v1.2.3