Skip to content

Commit

Permalink
WIP: Adds routes for the other fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Oct 24, 2024
1 parent 329650f commit 086b540
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
final String scanSuccess = "Successfully scanned the MQTT settings";
Toast.makeText(getContext(), scanSuccess, Toast.LENGTH_SHORT).show();

// TODO Navigate to Mqtt Fragment
Navigation.findNavController(requireActivity(), getId())
.navigate(CodeScannerFragmentDirections.actionScannerFragmentToMqttConnectionFragment()
.setMqttConnectionSettings(mqttConnectionSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,51 @@ fun MainCompose(
}
}

LaunchedEffect(viewModel.navigateToQrCodeShare) {
viewModel.navigateToQrCodeShare.observe(lifecycleOwner) { shouldNavigate ->
if (shouldNavigate) {
navController.navigate(NavOption.QrCodeShare.name)
viewModel.resetNavigationFlag()
}
}
}

LaunchedEffect(viewModel.navigateToTowerMap) {
viewModel.navigateToTowerMap.observe(lifecycleOwner) { shouldNavigate ->
if (shouldNavigate) {
navController.navigate(NavOption.TowerMap.name)
viewModel.resetNavigationFlag()
}
}
}

LaunchedEffect(viewModel.navigateToWifiSpectrum) {
viewModel.navigateToWifiSpectrum.observe(lifecycleOwner) { shouldNavigate ->
if (shouldNavigate) {
navController.navigate(NavOption.WifiSpectrum.name)
viewModel.resetNavigationFlag()
}
}
}

LaunchedEffect(viewModel.navigateToWifiDetails) {
viewModel.navigateToWifiDetails.observe(lifecycleOwner) { shouldNavigate ->
if (shouldNavigate) {
navController.navigate(NavOption.WifiDetails.name)
viewModel.resetNavigationFlag()
}
}
}

LaunchedEffect(viewModel.navigateToBluetooth) {
viewModel.navigateToBluetooth.observe(lifecycleOwner) { shouldNavigate ->
if (shouldNavigate) {
navController.navigate(NavOption.BluetoothDetails.name)
viewModel.resetNavigationFlag()
}
}
}

NsTheme {
Scaffold { paddingValues ->
ModalNavigationDrawer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,52 @@ class SharedViewModel @Inject constructor(application: Application) :
private val _navigateToQrCodeScanner = MutableLiveData(false)
val navigateToQrCodeScanner: LiveData<Boolean> = _navigateToQrCodeScanner

private val _navigateToQrCodeShare = MutableLiveData(false)
val navigateToQrCodeShare: LiveData<Boolean> = _navigateToQrCodeShare

private val _navigateToTowerMap = MutableLiveData(false)
val navigateToTowerMap: LiveData<Boolean> = _navigateToTowerMap

private val _navigateToWifiSpectrum = MutableLiveData(false)
val navigateToWifiSpectrum: LiveData<Boolean> = _navigateToWifiSpectrum

private val _navigateToWifiDetails = MutableLiveData(false)
val navigateToWifiDetails: LiveData<Boolean> = _navigateToWifiDetails

private val _navigateToBluetooth = MutableLiveData(false)
val navigateToBluetooth: LiveData<Boolean> = _navigateToBluetooth

fun triggerNavigationToQrCodeScanner() {
_navigateToQrCodeScanner.value = true
}

fun triggerNavigationToQrCodeShare() {
_navigateToQrCodeShare.value = true
}

fun triggerNavigationToTowerMap() {
_navigateToTowerMap.value = true
}

fun triggerNavigationToWifiSpectrum() {
_navigateToWifiSpectrum.value = true
}

fun triggerNavigationToWifiDetails() {
_navigateToWifiDetails.value = true
}

fun triggerNavigationToBluetooth() {
_navigateToBluetooth.value = true
}

fun resetNavigationFlag() {
// TODO is this a good idea to set them all in one method?
_navigateToQrCodeScanner.value = false
_navigateToQrCodeShare.value = false
_navigateToTowerMap.value = false
_navigateToWifiSpectrum.value = false
_navigateToWifiDetails.value = false
_navigateToBluetooth.value = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.navArgument
import com.craxiom.networksurvey.databinding.ContainerBluetoothFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerGrpcFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerMqttFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerMqttQrCodeScannerFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerMqttQrCodeShareFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerSettingsFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerTowerMapFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerWifiDetailsFragmentBinding
import com.craxiom.networksurvey.databinding.ContainerWifiSpectrumFragmentBinding
import com.craxiom.networksurvey.fragments.MqttFragment
import com.craxiom.networksurvey.fragments.model.MqttConnectionSettings
import com.craxiom.networksurvey.ui.cellular.CalculatorScreen
Expand Down Expand Up @@ -70,10 +75,31 @@ fun NavGraphBuilder.mainGraph(
SettingsFragmentInCompose(paddingValues)
}

// --------- Deeper navigation (beyond the nav drawer) ---------
// --------- Deeper navigation (beyond the nav drawer) --------- //

composable(NavOption.QrCodeScanner.name) {
QrCodeScannerInCompose(paddingValues)
}

composable(NavOption.QrCodeShare.name) {
QrCodeShareInCompose(paddingValues)
}

composable(NavOption.TowerMap.name) {
TowerMapInCompose(paddingValues)
}

composable(NavOption.WifiSpectrum.name) {
WifiSpectrumInCompose(paddingValues)
}

composable(NavOption.WifiDetails.name) {
WifiDetailsInCompose(paddingValues)
}

composable(NavOption.BluetoothDetails.name) {
BluetoothDetailsInCompose(paddingValues)
}
}
}

Expand All @@ -92,7 +118,12 @@ enum class NavDrawerOption {
}

enum class NavOption {
QrCodeScanner
QrCodeScanner,
QrCodeShare,
TowerMap,
WifiSpectrum,
WifiDetails,
BluetoothDetails
}

@Composable
Expand Down Expand Up @@ -135,3 +166,48 @@ fun QrCodeScannerInCompose(paddingValues: PaddingValues) {
) {
}
}

@Composable
fun QrCodeShareInCompose(paddingValues: PaddingValues) {
AndroidViewBinding(
ContainerMqttQrCodeShareFragmentBinding::inflate,
modifier = Modifier.padding(paddingValues = paddingValues)
) {
}
}

@Composable
fun TowerMapInCompose(paddingValues: PaddingValues) {
AndroidViewBinding(
ContainerTowerMapFragmentBinding::inflate,
modifier = Modifier.padding(paddingValues = paddingValues)
) {
}
}

@Composable
fun WifiSpectrumInCompose(paddingValues: PaddingValues) {
AndroidViewBinding(
ContainerWifiSpectrumFragmentBinding::inflate,
modifier = Modifier.padding(paddingValues = paddingValues)
) {
}
}

@Composable
fun WifiDetailsInCompose(paddingValues: PaddingValues) {
AndroidViewBinding(
ContainerWifiDetailsFragmentBinding::inflate,
modifier = Modifier.padding(paddingValues = paddingValues)
) {
}
}

@Composable
fun BluetoothDetailsInCompose(paddingValues: PaddingValues) {
AndroidViewBinding(
ContainerBluetoothFragmentBinding::inflate,
modifier = Modifier.padding(paddingValues = paddingValues)
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bluetooth_details_fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.craxiom.networksurvey.fragments.BluetoothDetailsFragment" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mqtt_qr_code_share_fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.craxiom.networksurvey.fragments.QrCodeShareFragment" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tower_map_fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.craxiom.networksurvey.fragments.TowerMapFragment" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wifi_details_fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.craxiom.networksurvey.fragments.WifiDetailsFragment" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wifi_spectrum_fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.craxiom.networksurvey.fragments.WifiSpectrumFragment" />

0 comments on commit 086b540

Please sign in to comment.