From 283b0650a702f57f052024c4ff82bef5cb7e7318 Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: fragments: remove usage of kotlin view synthetics --- .../org/pacien/tincapp/activities/BaseFragment.kt | 12 +---------- .../activities/start/NetworkListFragment.kt | 23 +++++++++++----------- .../activities/status/nodes/NodeListFragment.kt | 22 +++++++++++---------- .../status/subnets/SubnetListFragment.kt | 15 +++++++------- 4 files changed, 33 insertions(+), 39 deletions(-) (limited to 'app') diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt index dda783b..7306d4b 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt @@ -18,19 +18,9 @@ package org.pacien.tincapp.activities -import androidx.annotation.LayoutRes import androidx.fragment.app.Fragment -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import kotlinx.android.synthetic.main.base_activity.* /** * @author euxane */ -abstract class BaseFragment : Fragment() { - private val rootView by lazy { base_activity_frame } - - fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, rootView, false)!! - fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(layoutInflater, rootView, false) -} +abstract class BaseFragment : Fragment() 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 fe7d3ee..9a25a0c 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 @@ -26,10 +26,9 @@ import android.view.ViewGroup import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.TextView -import kotlinx.android.synthetic.main.start_network_list.* import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseFragment -import org.pacien.tincapp.context.AppPaths +import org.pacien.tincapp.databinding.StartNetworkListBinding import org.pacien.tincapp.extensions.hideBottomSeparator import org.pacien.tincapp.extensions.setElements @@ -39,6 +38,7 @@ import org.pacien.tincapp.extensions.setElements 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 } override fun onCreate(savedInstanceState: Bundle?) { @@ -47,16 +47,17 @@ class NetworkListFragment : BaseFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.start_network_list, container, false) + startNetworkListBinding = StartNetworkListBinding.inflate(inflater, container, false) + return startNetworkListBinding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val listHeaderView = layoutInflater.inflate(R.layout.start_network_list_header, start_network_list, false) - start_network_list.addHeaderView(listHeaderView, null, false) - start_network_list.hideBottomSeparator() - start_network_list.emptyView = start_network_list_placeholder - start_network_list.onItemClickListener = AdapterView.OnItemClickListener(this::onItemClick) - start_network_list.adapter = networkListAdapter + val listHeaderView = layoutInflater.inflate(R.layout.start_network_list_header, startNetworkListBinding.root, false) + startNetworkListBinding.startNetworkList.addHeaderView(listHeaderView, null, false) + startNetworkListBinding.startNetworkList.hideBottomSeparator() + startNetworkListBinding.startNetworkList.emptyView = startNetworkListBinding.startNetworkListPlaceholder + startNetworkListBinding.startNetworkList.onItemClickListener = AdapterView.OnItemClickListener(this::onItemClick) + startNetworkListBinding.startNetworkList.adapter = networkListAdapter } @Suppress("UNUSED_PARAMETER") @@ -71,8 +72,8 @@ class NetworkListFragment : BaseFragment() { } private fun updatePlaceholder() { - start_network_list_placeholder.post { - start_network_list_placeholder_text?.text = getString(R.string.start_network_list_empty_none_found) + startNetworkListBinding.startNetworkListPlaceholder.post { + startNetworkListBinding.startNetworkListPlaceholderText?.text = getString(R.string.start_network_list_empty_none_found) } } } 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 993c770..05c65d7 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 @@ -25,11 +25,11 @@ import androidx.appcompat.app.AlertDialog import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import kotlinx.android.synthetic.main.status_node_info_dialog.view.* -import kotlinx.android.synthetic.main.status_node_list_fragment.* import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseFragment import org.pacien.tincapp.commands.Tinc +import org.pacien.tincapp.databinding.StatusNodeInfoDialogBinding +import org.pacien.tincapp.databinding.StatusNodeListFragmentBinding import org.pacien.tincapp.extensions.hideBottomSeparator import org.pacien.tincapp.extensions.hideTopSeparator import org.pacien.tincapp.extensions.setElements @@ -45,6 +45,7 @@ class NodeListFragment : BaseFragment() { private val nodeListViewModel by lazy { ViewModelProviders.of(this).get(NodeListViewModel::class.java) } private val nodeListAdapter by lazy { NodeInfoArrayAdapter(requireContext(), this::onItemClick) } private val nodeListObserver by lazy { Observer> { nodeListAdapter.setElements(it) } } + private lateinit var statusNodeListFragmentBinding: StatusNodeListFragmentBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -52,30 +53,31 @@ class NodeListFragment : BaseFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - return inflater.inflate(R.layout.status_node_list_fragment, container, false) + statusNodeListFragmentBinding = StatusNodeListFragmentBinding.inflate(inflater, container, false) + return statusNodeListFragmentBinding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - status_node_list.hideTopSeparator() - status_node_list.hideBottomSeparator() - status_node_list.emptyView = status_node_list_placeholder - status_node_list.adapter = nodeListAdapter + statusNodeListFragmentBinding.statusNodeList.hideTopSeparator() + statusNodeListFragmentBinding.statusNodeList.hideBottomSeparator() + statusNodeListFragmentBinding.statusNodeList.emptyView = statusNodeListFragmentBinding.statusNodeListPlaceholder + statusNodeListFragmentBinding.statusNodeList.adapter = nodeListAdapter } private fun onItemClick(nodeInfo: NodeInfo) = showNodeInfo(nodeInfo.name) private fun showNodeInfo(nodeName: String) { - val dialogTextView = inflate(R.layout.status_node_info_dialog) + val dialogTextViewBinding = StatusNodeInfoDialogBinding.inflate(layoutInflater) AlertDialog.Builder(context!!) .setTitle(R.string.status_node_info_dialog_title) - .setView(dialogTextView) + .setView(dialogTextViewBinding.root) .setPositiveButton(R.string.status_node_info_dialog_close_action) { _, _ -> Unit } .show() tincCtl.info(netName, nodeName).thenAccept { nodeInfo -> - view?.post { dialogTextView.dialog_node_details.text = nodeInfo } + view?.post { dialogTextViewBinding.dialogNodeDetails.text = 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 9701e5e..c842323 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 @@ -24,9 +24,8 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import kotlinx.android.synthetic.main.status_subnet_list_fragment.* -import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseFragment +import org.pacien.tincapp.databinding.StatusSubnetListFragmentBinding import org.pacien.tincapp.extensions.hideBottomSeparator import org.pacien.tincapp.extensions.hideTopSeparator import org.pacien.tincapp.extensions.setElements @@ -38,6 +37,7 @@ class SubnetListFragment : BaseFragment() { private val subnetListViewModel by lazy { ViewModelProviders.of(this).get(SubnetListViewModel::class.java) } private val subnetListAdapter by lazy { SubnetInfoArrayAdapter(requireContext()) } private val subnetListObserver by lazy { Observer> { subnetListAdapter.setElements(it) } } + private lateinit var statusSubnetListFragmentBinding: StatusSubnetListFragmentBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,13 +45,14 @@ class SubnetListFragment : BaseFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - return inflater.inflate(R.layout.status_subnet_list_fragment, container, false) + statusSubnetListFragmentBinding = StatusSubnetListFragmentBinding.inflate(inflater, container, false) + return statusSubnetListFragmentBinding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - status_subnet_list.hideTopSeparator() - status_subnet_list.hideBottomSeparator() - status_subnet_list.onItemClickListener = null - status_subnet_list.adapter = subnetListAdapter + statusSubnetListFragmentBinding.statusSubnetList.hideTopSeparator() + statusSubnetListFragmentBinding.statusSubnetList.hideBottomSeparator() + statusSubnetListFragmentBinding.statusSubnetList.onItemClickListener = null + statusSubnetListFragmentBinding.statusSubnetList.adapter = subnetListAdapter } } -- cgit v1.2.3