diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/BluetoothFragment.java b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/BluetoothFragment.java index 624d99b5..3de8d911 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/BluetoothFragment.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/BluetoothFragment.java @@ -25,9 +25,7 @@ import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; -import androidx.lifecycle.ViewModelStoreOwner; import androidx.navigation.Navigation; -import androidx.navigation.fragment.NavHostFragment; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.DividerItemDecoration; @@ -96,9 +94,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, { binding = FragmentBluetoothListBinding.inflate(inflater); - final ViewModelStoreOwner viewModelStoreOwner = NavHostFragment.findNavController(this).getViewModelStoreOwner(R.id.nav_graph); - final ViewModelProvider viewModelProvider = new ViewModelProvider(viewModelStoreOwner); - viewModel = viewModelProvider.get(getClass().getName(), BluetoothViewModel.class); + viewModel = new ViewModelProvider(requireActivity()).get(BluetoothViewModel.class); binding.setVm(viewModel); 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 15fb90ea..838e8b87 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/WifiNetworksFragment.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/WifiNetworksFragment.java @@ -26,9 +26,7 @@ import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; -import androidx.lifecycle.ViewModelStoreOwner; import androidx.navigation.Navigation; -import androidx.navigation.fragment.NavHostFragment; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.SortedList; @@ -97,9 +95,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, { binding = FragmentWifiNetworksListBinding.inflate(inflater); - final ViewModelStoreOwner viewModelStoreOwner = NavHostFragment.findNavController(this).getViewModelStoreOwner(R.id.nav_graph); - final ViewModelProvider viewModelProvider = new ViewModelProvider(viewModelStoreOwner); - viewModel = viewModelProvider.get(getClass().getName(), WifiViewModel.class); + viewModel = new ViewModelProvider(requireActivity()).get(WifiViewModel.class); binding.setVm(viewModel); diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/HomeScreen.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/HomeScreen.kt index c154b955..3a8693b1 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/HomeScreen.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/HomeScreen.kt @@ -34,37 +34,51 @@ import com.craxiom.networksurvey.fragments.MainCellularFragment import com.craxiom.networksurvey.fragments.MainGnssFragment import com.craxiom.networksurvey.fragments.WifiNetworksFragment import com.craxiom.networksurvey.ui.main.appbar.AppBar +import com.craxiom.networksurvey.ui.main.appbar.AppBarAction +import com.craxiom.networksurvey.ui.main.appdrawer.NavOption @Composable fun HomeScreen( - drawerState: DrawerState + drawerState: DrawerState, + mainNavController: NavHostController ) { - val navController: NavHostController = rememberNavController() + val bottomNavController: NavHostController = rememberNavController() + var currentScreen by remember { mutableStateOf(MainScreens.Dashboard) } Scaffold( - topBar = { AppBar(drawerState = drawerState) }, + topBar = { + AppBar( + drawerState = drawerState, + appBarActions = getAppBarActions(currentScreen, mainNavController) + ) + }, bottomBar = { - BottomNavigationBar(navController) + BottomNavigationBar(bottomNavController) }, ) { padding -> NavHost( - navController, + bottomNavController, startDestination = MainScreens.Dashboard.route, modifier = Modifier.padding(paddingValues = padding) ) { composable(MainScreens.Dashboard.route) { + currentScreen = MainScreens.Dashboard DashboardFragmentInCompose() } composable(MainScreens.Cellular.route) { + currentScreen = MainScreens.Cellular CellularFragmentInCompose() } composable(MainScreens.Wifi.route) { + currentScreen = MainScreens.Wifi WifiFragmentInCompose() } composable(MainScreens.Bluetooth.route) { + currentScreen = MainScreens.Bluetooth BluetoothFragmentInCompose() } composable(MainScreens.Gnss.route) { + currentScreen = MainScreens.Gnss GnssFragmentInCompose() } } @@ -108,6 +122,50 @@ fun BottomNavigationBar(navController: NavController) { } } +@Composable +fun getAppBarActions(currentScreen: MainScreens, navController: NavController): List { + return when (currentScreen) { + MainScreens.Cellular -> listOf( + AppBarAction( + icon = android.R.drawable.ic_dialog_map, + description = R.string.open_tower_map, + onClick = { + navController.navigate(NavOption.TowerMap.name) + } + ) + ) + + MainScreens.Wifi -> listOf( + AppBarAction( + icon = R.drawable.ic_spectrum_chart, + description = R.string.open_wifi_spectrum, + onClick = { + // TODO Navigate to WiFi Spectrum Fragment + } + ) + ) + + MainScreens.Gnss -> listOf( + AppBarAction( + icon = R.drawable.ic_sort, + description = R.string.menu_option_sort_by, + onClick = { + // TODO Finish me + } + ), + AppBarAction( + icon = R.drawable.ic_filter, + description = R.string.menu_option_filter_content_description, + onClick = { + // TODO Finish me + } + ) + ) + + else -> emptyList() + } +} + sealed class MainScreens(val route: String) { data object Dashboard : MainScreens("dashboard_route") data object Cellular : MainScreens("cellular_route") 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 0b5fe7bc..a75e2a4e 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 @@ -29,7 +29,7 @@ import com.craxiom.networksurvey.util.NsTheme @Composable fun MainCompose( - navController: NavHostController = rememberNavController(), + mainNavController: NavHostController = rememberNavController(), drawerState: DrawerState = rememberDrawerState(initialValue = DrawerValue.Closed), appVersion: String ) { @@ -41,7 +41,7 @@ fun MainCompose( LaunchedEffect(viewModel.navigateToQrCodeScanner) { viewModel.navigateToQrCodeScanner.observe(lifecycleOwner) { shouldNavigate -> if (shouldNavigate) { - navController.navigate(NavOption.QrCodeScanner.name) + mainNavController.navigate(NavOption.QrCodeScanner.name) viewModel.resetNavigationFlag() } } @@ -50,7 +50,7 @@ fun MainCompose( LaunchedEffect(viewModel.navigateToQrCodeShare) { viewModel.navigateToQrCodeShare.observe(lifecycleOwner) { shouldNavigate -> if (shouldNavigate) { - navController.navigate(NavOption.QrCodeShare.name) + mainNavController.navigate(NavOption.QrCodeShare.name) viewModel.resetNavigationFlag() } } @@ -59,7 +59,7 @@ fun MainCompose( LaunchedEffect(viewModel.navigateToTowerMap) { viewModel.navigateToTowerMap.observe(lifecycleOwner) { shouldNavigate -> if (shouldNavigate) { - navController.navigate(NavOption.TowerMap.name) + mainNavController.navigate(NavOption.TowerMap.name) viewModel.resetNavigationFlag() } } @@ -68,7 +68,7 @@ fun MainCompose( LaunchedEffect(viewModel.navigateToWifiSpectrum) { viewModel.navigateToWifiSpectrum.observe(lifecycleOwner) { shouldNavigate -> if (shouldNavigate) { - navController.navigate(NavOption.WifiSpectrum.name) + mainNavController.navigate(NavOption.WifiSpectrum.name) viewModel.resetNavigationFlag() } } @@ -77,7 +77,7 @@ fun MainCompose( LaunchedEffect(viewModel.navigateToWifiDetails) { viewModel.navigateToWifiDetails.observe(lifecycleOwner) { shouldNavigate -> if (shouldNavigate) { - navController.navigate(NavOption.WifiDetails.name) + mainNavController.navigate(NavOption.WifiDetails.name) viewModel.resetNavigationFlag() } } @@ -86,7 +86,7 @@ fun MainCompose( LaunchedEffect(viewModel.navigateToBluetooth) { viewModel.navigateToBluetooth.observe(lifecycleOwner) { shouldNavigate -> if (shouldNavigate) { - navController.navigate(NavOption.BluetoothDetails.name) + mainNavController.navigate(NavOption.BluetoothDetails.name) viewModel.resetNavigationFlag() } } @@ -106,31 +106,31 @@ fun MainCompose( ) { onUserPickedOption -> when (onUserPickedOption) { NavDrawerOption.None -> { - navController.navigate(onUserPickedOption.name) { + mainNavController.navigate(onUserPickedOption.name) { popUpTo(NavDrawerOption.None.name) } } NavDrawerOption.ServerConnection -> { - navController.navigate(onUserPickedOption.name) { + mainNavController.navigate(onUserPickedOption.name) { popUpTo(NavDrawerOption.None.name) } } NavDrawerOption.MqttBrokerConnection -> { - navController.navigate(onUserPickedOption.name) { + mainNavController.navigate(onUserPickedOption.name) { popUpTo(NavDrawerOption.None.name) } } NavDrawerOption.CellularCalculators -> { - navController.navigate(onUserPickedOption.name) { + mainNavController.navigate(onUserPickedOption.name) { popUpTo(NavDrawerOption.None.name) } } NavDrawerOption.Settings -> { - navController.navigate(onUserPickedOption.name) { + mainNavController.navigate(onUserPickedOption.name) { popUpTo(NavDrawerOption.None.name) } } @@ -171,10 +171,13 @@ fun MainCompose( } ) { NavHost( - navController, + mainNavController, startDestination = NavRoutes.MainRoute.name ) { - mainGraph(drawerState, paddingValues = paddingValues) + mainGraph( + drawerState, paddingValues = paddingValues, + mainNavController = mainNavController + ) } } } diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/appdrawer/AppDrawerNav.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/appdrawer/AppDrawerNav.kt index 8bce8c58..182d79da 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/appdrawer/AppDrawerNav.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/main/appdrawer/AppDrawerNav.kt @@ -10,6 +10,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.viewinterop.AndroidViewBinding import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavHostController import androidx.navigation.NavType import androidx.navigation.compose.composable import androidx.navigation.compose.navigation @@ -31,17 +32,19 @@ import com.craxiom.networksurvey.ui.main.NavRoutes fun NavGraphBuilder.mainGraph( drawerState: DrawerState, - paddingValues: PaddingValues + paddingValues: PaddingValues, + mainNavController: NavHostController ) { navigation(startDestination = NavDrawerOption.None.name, route = NavRoutes.MainRoute.name) { // TODO Need to add a header like the old display for all of these composable(NavDrawerOption.None.name) { - HomeScreen(drawerState) + HomeScreen(drawerState, mainNavController = mainNavController) } composable(NavDrawerOption.ServerConnection.name) { GrpcFragmentInCompose(paddingValues) } + composable( route = "${NavDrawerOption.MqttBrokerConnection.name}?${MqttConnectionSettings.KEY}={mqttConnectionSettings}", arguments = listOf(navArgument("mqttConnectionSettings") { diff --git a/networksurvey/src/main/res/values/strings.xml b/networksurvey/src/main/res/values/strings.xml index 764294ca..ed5ca3d1 100644 --- a/networksurvey/src/main/res/values/strings.xml +++ b/networksurvey/src/main/res/values/strings.xml @@ -648,8 +648,9 @@ but work independently, so you have full control over how you handle your data.< Channel SSID\n - Tower Map + Open Tower Map Tower Map Info MQTT Connection Settings QR Code + Open Wi-Fi Spectrum View