Skip to content

Commit

Permalink
WIP: Tower Map Fragment navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Oct 29, 2024
1 parent 93fca3c commit 4dc9275
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -45,7 +38,7 @@
*
* @since 0.0.10
*/
public class MainCellularFragment extends AServiceDataFragment implements MenuProvider
public class MainCellularFragment extends AServiceDataFragment
{
private List<SubscriptionInfo> activeSubscriptionInfoList;

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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();

Expand Down Expand Up @@ -597,7 +600,7 @@ private void processCellularGroup(List<CellularRecordWrapper> cellularGroup)
{
if (CellularUtils.isServingCell(cellularRecord.cellularRecord))
{
latestServingCellRecord = cellularRecord;
sharedViewModel.updateLatestServingCellInfo(new ServingCellInfo(cellularRecord, subscriptionId));
}

switch (cellularRecord.cellularProtocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
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;
import android.widget.Toast;

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;
Expand Down Expand Up @@ -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<WifiRecordWrapper> wifiRecordSortedList;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -235,20 +225,6 @@ public void onWifiBeaconSurveyRecords(List<WifiRecordWrapper> 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class TowerMapViewModel : ASignalChartViewModel() {
MutableStateFlow<HashMap<Int, ServingSignalInfo>>(HashMap()) // <SubscriptionId, ServingSignalInfo>
val servingSignals = _servingSignals.asStateFlow()

lateinit var mapView: MapView
var mapView: MapView? = null
lateinit var gpsMyLocationProvider: GpsMyLocationProvider
private var hasMapLocationBeenSet = false

Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -137,7 +137,9 @@ internal class TowerMapViewModel : ASignalChartViewModel() {
}
}

recreateOverlaysFromTowerData(mapView, false)
mapView?.let { mapView ->
recreateOverlaysFromTowerData(mapView, false)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fun MainCompose(
Scaffold { paddingValues ->
ModalNavigationDrawer(
drawerState = drawerState,
gesturesEnabled = drawerState.isOpen,
drawerContent = {
AppDrawerContent(
appVersion = appVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,9 @@ class SharedViewModel @Inject constructor(application: Application) :

private val _navigateToTowerMap = MutableLiveData(false)
val navigateToTowerMap: LiveData<Boolean> = _navigateToTowerMap
private var _latestServingCellInfo: ServingCellInfo? = null
val latestServingCellInfo: ServingCellInfo?
get() = _latestServingCellInfo

/*private val _navigateToWifiSpectrum = MutableLiveData(false)
val navigateToWifiSpectrum: LiveData<Boolean> = _navigateToWifiSpectrum*/
Expand Down Expand Up @@ -60,6 +64,10 @@ class SharedViewModel @Inject constructor(application: Application) :
_navigateToQrCodeShare.value = true
}

fun updateLatestServingCellInfo(servingCellInfo: ServingCellInfo) {
_latestServingCellInfo = servingCellInfo
}

fun triggerNavigationToTowerMap() {
_navigateToTowerMap.value = true
}
Expand Down

0 comments on commit 4dc9275

Please sign in to comment.