From 4dc9275dd2ad4a46afcc1232d607cd9ded582766 Mon Sep 17 00:00:00 2001 From: christianrowlands Date: Tue, 29 Oct 2024 16:14:49 -0400 Subject: [PATCH] WIP: Tower Map Fragment navigation --- .../fragments/MainCellularFragment.java | 46 +------------------ .../fragments/MainGnssFragment.kt | 27 +---------- .../fragments/NetworkDetailsFragment.java | 7 ++- .../fragments/TowerMapFragment.kt | 8 ++-- .../fragments/WifiNetworksFragment.java | 26 +---------- .../ui/cellular/TowerMapScreen.kt | 4 +- .../ui/cellular/model/TowerMapViewModel.kt | 8 ++-- .../networksurvey/ui/main/NsMainScreen.kt | 1 + .../networksurvey/ui/main/SharedViewModel.kt | 8 ++++ 9 files changed, 29 insertions(+), 106 deletions(-) diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainCellularFragment.java b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainCellularFragment.java index 02b3adb8..77d16919 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainCellularFragment.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainCellularFragment.java @@ -8,22 +8,16 @@ import android.os.Bundle; import android.telephony.SubscriptionInfo; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ScrollView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.view.MenuProvider; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.navigation.Navigation; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -32,7 +26,6 @@ import com.craxiom.networksurvey.databinding.FragmentMainTabsBinding; import com.craxiom.networksurvey.services.NetworkSurveyService; import com.craxiom.networksurvey.services.controller.CellularController; -import com.craxiom.networksurvey.ui.cellular.model.ServingCellInfo; import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; @@ -45,7 +38,7 @@ * * @since 0.0.10 */ -public class MainCellularFragment extends AServiceDataFragment implements MenuProvider +public class MainCellularFragment extends AServiceDataFragment { private List activeSubscriptionInfoList; @@ -116,12 +109,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c } }); - FragmentActivity activity = getActivity(); - if (activity != null) - { - activity.addMenuProvider(this, getViewLifecycleOwner()); - } - return binding.getRoot(); } @@ -179,24 +166,6 @@ protected void onSurveyServiceDisconnecting(NetworkSurveyService service) super.onSurveyServiceDisconnecting(service); } - @Override - public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) - { - menuInflater.inflate(R.menu.cellular_details_menu, menu); - } - - // TODO Delete the menu item stuff in all the fragments - @Override - public boolean onMenuItemSelected(@NonNull MenuItem menuItem) - { - if (menuItem.getItemId() == R.id.action_open_tower_map) - { - navigateToTowerMap(); - return true; - } - return false; - } - /** * An adapter that handles creating a new fragment when a tab is selected for the first time. */ @@ -274,17 +243,4 @@ private boolean isScrolledToBottom() int delta = bottom - scrollBounds.bottom; return delta == 0; } - - /** - * Navigates to the cell tower map screen. - */ - public void navigateToTowerMap() - { - FragmentActivity activity = getActivity(); - if (activity == null) return; - - // TODO Figure out a way to pass the serving cell information from the NetworkDetailsFragment that is currently in view when the button is clicked - Navigation.findNavController(activity, R.id.main_content) - .navigate(MainCellularFragmentDirections.actionMainCellularFragmentToTowerMapFragment(new ServingCellInfo(null, -1))); - } } diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainGnssFragment.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainGnssFragment.kt index 0173f4f7..fb3fd9c3 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainGnssFragment.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/MainGnssFragment.kt @@ -5,12 +5,9 @@ import android.content.pm.PackageManager import android.os.Bundle import android.view.LayoutInflater import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.core.app.ActivityCompat -import androidx.core.view.MenuProvider import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.LiveData @@ -20,8 +17,6 @@ import androidx.viewpager2.widget.ViewPager2 import com.craxiom.networksurvey.Application import com.craxiom.networksurvey.R import com.craxiom.networksurvey.ui.gnss.model.SignalInfoViewModel -import com.craxiom.networksurvey.util.SatelliteUtil -import com.craxiom.networksurvey.util.SortUtil import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -33,7 +28,7 @@ import timber.log.Timber * * @since 0.0.10 */ -class MainGnssFragment : Fragment(), MenuProvider { +class MainGnssFragment : Fragment() { private var menu: Menu? = null private var selectedTab: Int = 0 @@ -47,9 +42,6 @@ class MainGnssFragment : Fragment(), MenuProvider { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val activity = activity - activity?.addMenuProvider(this, getViewLifecycleOwner()) - return inflater.inflate(R.layout.fragment_main_gnss_tabs, container, false) } @@ -88,23 +80,6 @@ class MainGnssFragment : Fragment(), MenuProvider { super.onPause() } - override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { - menuInflater.inflate(R.menu.gnss_main_menu, menu) - this.menu = menu - if (selectedTab != 0) menu.setGroupVisible(R.id.gnss_status_group, false) - } - - override fun onMenuItemSelected(menuItem: MenuItem): Boolean { - if (menuItem.itemId == R.id.filter_sats) { - SatelliteUtil.showSatsFilterDialog(requireActivity()) - return true - } else if (menuItem.itemId == R.id.sort_sats) { - SortUtil.showSortByDialog(requireActivity()) - return true - } - return false - } - /** * @return True if the [Manifest.permission.ACCESS_FINE_LOCATION] permission has been granted. False otherwise. */ diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/NetworkDetailsFragment.java b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/NetworkDetailsFragment.java index ecd91b54..f94fba8a 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/NetworkDetailsFragment.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/NetworkDetailsFragment.java @@ -49,6 +49,8 @@ import com.craxiom.networksurvey.services.NetworkSurveyService; import com.craxiom.networksurvey.ui.cellular.CellularChartViewModel; import com.craxiom.networksurvey.ui.cellular.ComposeFunctions; +import com.craxiom.networksurvey.ui.cellular.model.ServingCellInfo; +import com.craxiom.networksurvey.ui.main.SharedViewModel; import com.craxiom.networksurvey.util.CalculationUtils; import com.craxiom.networksurvey.util.CellularUtils; import com.craxiom.networksurvey.util.ColorUtils; @@ -92,7 +94,7 @@ public class NetworkDetailsFragment extends AServiceDataFragment implements ICel private FragmentNetworkDetailsBinding binding; private CellularViewModel viewModel; private CellularChartViewModel chartViewModel; - private CellularRecordWrapper latestServingCellRecord; + private SharedViewModel sharedViewModel; @Override public void onCreate(@Nullable Bundle savedInstanceState) @@ -113,6 +115,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c viewModel = new ViewModelProvider(requireActivity()).get(getClass().getName() + subscriptionId, CellularViewModel.class); chartViewModel = new ViewModelProvider(requireActivity()).get(getClass().getName() + "cellular_chart" + subscriptionId, CellularChartViewModel.class); + sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class); initializeLocationTextView(); @@ -597,7 +600,7 @@ private void processCellularGroup(List cellularGroup) { if (CellularUtils.isServingCell(cellularRecord.cellularRecord)) { - latestServingCellRecord = cellularRecord; + sharedViewModel.updateLatestServingCellInfo(new ServingCellInfo(cellularRecord, subscriptionId)); } switch (cellularRecord.cellularProtocol) diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/TowerMapFragment.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/TowerMapFragment.kt index c6840813..ff09b8d2 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/TowerMapFragment.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/TowerMapFragment.kt @@ -17,10 +17,10 @@ import androidx.appcompat.app.AlertDialog import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.core.view.MenuProvider +import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewmodel.compose.viewModel import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs import com.craxiom.networksurvey.R import com.craxiom.networksurvey.SimChangeReceiver import com.craxiom.networksurvey.listeners.ICellularSurveyRecordListener @@ -30,6 +30,7 @@ import com.craxiom.networksurvey.services.NetworkSurveyService import com.craxiom.networksurvey.ui.cellular.TowerMapScreen import com.craxiom.networksurvey.ui.cellular.model.ServingCellInfo import com.craxiom.networksurvey.ui.cellular.model.TowerMapViewModel +import com.craxiom.networksurvey.ui.main.SharedViewModel import com.craxiom.networksurvey.ui.theme.NsTheme import com.craxiom.networksurvey.util.PreferenceUtils import timber.log.Timber @@ -68,8 +69,9 @@ class TowerMapFragment : AServiceDataFragment(), MenuProvider, ICellularSurveyRe container: ViewGroup?, savedInstanceState: Bundle? ): View { - val args: TowerMapFragmentArgs by navArgs() - servingCell = args.servingCell + val viewModel = ViewModelProvider(requireActivity())[SharedViewModel::class.java] + servingCell = viewModel.latestServingCellInfo + activity?.addMenuProvider(this, getViewLifecycleOwner()) composeView = ComposeView(requireContext()).apply { diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/WifiNetworksFragment.java b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/WifiNetworksFragment.java index e34cd721..e2400863 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/WifiNetworksFragment.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/WifiNetworksFragment.java @@ -12,9 +12,6 @@ import android.os.Looper; import android.provider.Settings; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -22,7 +19,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import androidx.core.view.MenuProvider; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; @@ -53,7 +49,7 @@ * * @since 0.1.2 */ -public class WifiNetworksFragment extends AServiceDataFragment implements IWifiSurveyRecordListener, MenuProvider +public class WifiNetworksFragment extends AServiceDataFragment implements IWifiSurveyRecordListener { private FragmentWifiNetworksListBinding binding; private SortedList wifiRecordSortedList; @@ -135,12 +131,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, if (paused) lastScanTime = System.currentTimeMillis(); }); - FragmentActivity activity = getActivity(); - if (activity != null) - { - activity.addMenuProvider(this, getViewLifecycleOwner()); - } - return binding.getRoot(); } @@ -235,20 +225,6 @@ public void onWifiBeaconSurveyRecords(List wifiBeaconRecords) }); } - @Override - public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) - { - menuInflater.inflate(R.menu.wifi_networks_menu, menu); - } - - // TODO Remove all the menu stuff from all the fragments - @Override - public boolean onMenuItemSelected(@NonNull MenuItem menuItem) - { - //navigateToWifiSpectrumScreen(); - return menuItem.getItemId() == R.id.action_open_spectrum; - } - /** * Navigates to the Wi-Fi details screen for the selected Wi-Fi network. */ diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/TowerMapScreen.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/TowerMapScreen.kt index f8addf57..9b40b215 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/TowerMapScreen.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/TowerMapScreen.kt @@ -436,7 +436,7 @@ private fun goToMyLocation(viewModel: TowerMapViewModel) { Timber.w("The last known location is null") return } - viewModel.mapView.controller.animateTo( + viewModel.mapView!!.controller.animateTo( GeoPoint( lastKnownLocation.latitude, lastKnownLocation.longitude @@ -512,7 +512,7 @@ private suspend fun runTowerQuery(viewModel: TowerMapViewModel) { val towers = viewModel.towers.value towerPoints.forEach { - val towerMarker = TowerMarker(viewModel.mapView, it) + val towerMarker = TowerMarker(viewModel.mapView!!, it) if (towers.size >= MAX_TOWERS_ON_MAP) { val towerToRemove = towers.first() diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/model/TowerMapViewModel.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/model/TowerMapViewModel.kt index cc1774ad..9ebfa3ea 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/model/TowerMapViewModel.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/cellular/model/TowerMapViewModel.kt @@ -35,7 +35,7 @@ internal class TowerMapViewModel : ASignalChartViewModel() { MutableStateFlow>(HashMap()) // val servingSignals = _servingSignals.asStateFlow() - lateinit var mapView: MapView + var mapView: MapView? = null lateinit var gpsMyLocationProvider: GpsMyLocationProvider private var hasMapLocationBeenSet = false @@ -95,7 +95,7 @@ internal class TowerMapViewModel : ASignalChartViewModel() { if (location != null && !hasMapLocationBeenSet) { if (location.latitude != 0.0 || location.longitude != 0.0) { hasMapLocationBeenSet = true - mapView.controller.setCenter(GeoPoint(location.latitude, location.longitude)) + mapView!!.controller.setCenter(GeoPoint(location.latitude, location.longitude)) } } @@ -137,7 +137,9 @@ internal class TowerMapViewModel : ASignalChartViewModel() { } } - recreateOverlaysFromTowerData(mapView, false) + mapView?.let { mapView -> + recreateOverlaysFromTowerData(mapView, false) + } } /** diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/NsMainScreen.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/NsMainScreen.kt index f03421a9..30b7246d 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/NsMainScreen.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/NsMainScreen.kt @@ -120,6 +120,7 @@ fun MainCompose( Scaffold { paddingValues -> ModalNavigationDrawer( drawerState = drawerState, + gesturesEnabled = drawerState.isOpen, drawerContent = { AppDrawerContent( appVersion = appVersion, diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/SharedViewModel.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/SharedViewModel.kt index 1b5ea4c5..846662da 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/SharedViewModel.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/SharedViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData import com.craxiom.messaging.BluetoothRecordData import com.craxiom.networksurvey.fragments.model.MqttConnectionSettings import com.craxiom.networksurvey.model.WifiNetwork +import com.craxiom.networksurvey.ui.cellular.model.ServingCellInfo import com.craxiom.networksurvey.ui.wifi.model.WifiNetworkInfoList import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @@ -22,6 +23,9 @@ class SharedViewModel @Inject constructor(application: Application) : private val _navigateToTowerMap = MutableLiveData(false) val navigateToTowerMap: LiveData = _navigateToTowerMap + private var _latestServingCellInfo: ServingCellInfo? = null + val latestServingCellInfo: ServingCellInfo? + get() = _latestServingCellInfo /*private val _navigateToWifiSpectrum = MutableLiveData(false) val navigateToWifiSpectrum: LiveData = _navigateToWifiSpectrum*/ @@ -60,6 +64,10 @@ class SharedViewModel @Inject constructor(application: Application) : _navigateToQrCodeShare.value = true } + fun updateLatestServingCellInfo(servingCellInfo: ServingCellInfo) { + _latestServingCellInfo = servingCellInfo + } + fun triggerNavigationToTowerMap() { _navigateToTowerMap.value = true }