Skip to content

Commit

Permalink
feat: implemented compose navigation in path tracking module
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Aug 18, 2024
1 parent e074088 commit cdc9bd1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -50,6 +51,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.registerReceiver
import androidx.core.content.ContextCompat.startActivity
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.android.gms.maps.model.CameraPosition
Expand All @@ -73,8 +75,7 @@ import com.mifos.feature.path.tracking.R

@Composable
fun PathTrackingScreen(
onBackPressed: () -> Unit,
onPathTrackingClick: (List<UserLatLng>) -> Unit
onBackPressed: () -> Unit
) {

val context = LocalContext.current
Expand Down Expand Up @@ -115,7 +116,22 @@ fun PathTrackingScreen(
onRetry = {
viewModel.loadPathTracking()
},
onPathTrackingClick = onPathTrackingClick,
onPathTrackingClick = { userLatLngs ->
val uri = if (userLatLngs.isNotEmpty()) {
val originLatLng = userLatLngs[0]
val destinationLatLng = userLatLngs[userLatLngs.size - 1]
"http://maps.google.com/maps?f=d&hl=en&saddr=${originLatLng.lat},${originLatLng.lng}&daddr=${destinationLatLng.lat},${destinationLatLng.lng}"
} else {
// Handle the case when userLatLngs is empty
""
}

val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
intent.setClassName(
"com.google.android.apps.maps", "com.google.android.maps.MapsActivity"
)
startActivity(context, Intent.createChooser(intent, "Start Tracking"), null)
},
onRefresh = {
viewModel.refreshCenterList()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@ package com.mifos.feature.path_tracking.navigation
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.mifos.feature.path_tracking.PathTrackingScreen

/**
* Created by Pronay Sarker on 10/08/2024 (7:35 AM)
*/
const val PATH_TRACKING_SCREEN_ROUTE = "path_tracking_route"

fun NavController.navigateToPathTrackingScreen() {
this.navigate(PATH_TRACKING_SCREEN_ROUTE)
fun NavGraphBuilder.pathTrackingNavGraph(
navController: NavController
) {
navigation(
startDestination = PathTrackingScreens.PathTrackingScreen.route,
route = PathTrackingScreens.PathTrackingScreenRoute.route
) {
pathTrackingRoute(
onBackPressed = navController::popBackStack
)
}
}

fun NavGraphBuilder.pathTrackingScreen(
fun NavGraphBuilder.pathTrackingRoute(
onBackPressed: () -> Unit
) {
composable(PATH_TRACKING_SCREEN_ROUTE) {
composable(
route = PathTrackingScreens.PathTrackingScreen.route
) {
PathTrackingScreen(
onBackPressed = onBackPressed,
onPathTrackingClick = {}
onBackPressed = onBackPressed
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mifos.feature.path_tracking.navigation

sealed class PathTrackingScreens(val route: String) {

data object PathTrackingScreenRoute : PathTrackingScreens("path_tracking_screen_route")

data object PathTrackingScreen : PathTrackingScreens("path_tracking_screen")

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.mifos.feature.checker_inbox_task.navigation.CHECKER_INBOX_TASK_SCREEN
import com.mifos.feature.groups.navigation.GROUP_LIST_SCREEN_ROUTE
import com.mifos.feature.individual_collection_sheet.navigation.GENERATE_COLLECTION_SHEET_SCREEN_ROUTE
import com.mifos.feature.individual_collection_sheet.navigation.INDIVIDUAL_COLLECTION_SHEET_SCREEN_ROUTE
import com.mifos.feature.path_tracking.navigation.PATH_TRACKING_SCREEN_ROUTE
import com.mifos.feature.path_tracking.navigation.PathTrackingScreens
import com.mifos.feature.search.Navigation.SEARCH_SCREEN_ROUTE
import com.mifos.feature.settings.navigation.SETTINGS_SCREEN_ROUTE

Expand Down Expand Up @@ -77,7 +77,7 @@ sealed class HomeDestinationsScreen(

data object PathTrackerScreen : HomeDestinationsScreen(
title = "Path Tracker",
route = PATH_TRACKING_SCREEN_ROUTE,
route = PathTrackingScreens.PathTrackingScreen.route,
icon = Icons.Rounded.PersonPinCircle
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class PathTrackingActivity : MifosBaseActivity() {
setContent {
PathTrackingScreen(
onBackPressed = { finish() },
onPathTrackingClick = { userLatLngs ->
onUserLocationClick(userLatLngs)
}
// onPathTrackingClick = { userLatLngs ->
// onUserLocationClick(userLatLngs)
// }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.mifos.feature.loan.navigation.navigateToLoanAccountScreen
import com.mifos.feature.loan.navigation.navigateToLoanAccountSummaryScreen
import com.mifos.feature.note.navigation.navigateToNoteScreen
import com.mifos.feature.note.navigation.noteScreen
import com.mifos.feature.path_tracking.navigation.pathTrackingScreen
import com.mifos.feature.path_tracking.navigation.pathTrackingNavGraph
import com.mifos.feature.report.navigation.reportNavGraph
import com.mifos.feature.savings.navigation.addSavingsAccountScreen
import com.mifos.feature.savings.navigation.navigateToAddSavingsAccount
Expand Down Expand Up @@ -135,8 +135,8 @@ fun Navigation(
onBackPressed = { navController.popBackStack() }
)

pathTrackingScreen(
onBackPressed = { navController.popBackStack() }
pathTrackingNavGraph(
navController = navController
)

settingsScreen(
Expand Down

0 comments on commit cdc9bd1

Please sign in to comment.