Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver app tour details #168

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e2b455
motis v2 for routing, remove implicit paths (user), (maintainer)
felixguendling Oct 15, 2024
6a18b46
basic andriod app setup
steffenheger Oct 24, 2024
c8afb8c
remove .gradle from VC
steffenheger Oct 24, 2024
8d9fbcd
Merge branch 'master' of github.com:motis-project/prima into motis-v2
felixguendling Oct 25, 2024
9e4eea9
wip
felixguendling Oct 25, 2024
fc4b7e5
Move MOTIS_BASE_URL to constants
nilspenzel Oct 26, 2024
2def2bb
Change API for geocoding according to new Motis version
nilspenzel Oct 26, 2024
79271c0
Remove unused imports
nilspenzel Oct 26, 2024
64681d5
Remove old geocoding API
nilspenzel Oct 26, 2024
c471980
Format
nilspenzel Oct 26, 2024
9638476
update .gitignore
steffenheger Oct 29, 2024
8e7bc43
login and basic navigation
steffenheger Oct 31, 2024
822cdc9
Merge branch 'master' into login-driver
steffenheger Oct 31, 2024
32fe6c1
prevent back navigation from login screen
steffenheger Nov 1, 2024
82b9fea
Merge branch 'login-driver' of github.com:motis-project/prima into lo…
steffenheger Nov 1, 2024
6a48b42
update .gitignore, test readme
steffenheger Nov 1, 2024
6026bc2
Merge branch 'master' into navigation-driver-app
steffenheger Nov 2, 2024
e7d885f
navigation
steffenheger Nov 2, 2024
64a4a12
Merge branch 'navigation-driver-app' of github.com:motis-project/prim…
steffenheger Nov 2, 2024
822de40
wip
steffenheger Nov 2, 2024
c360a40
wip
steffenheger Nov 2, 2024
9fa2676
Update Motis api files
nilspenzel Nov 5, 2024
1952445
Remove fare computation
nilspenzel Nov 5, 2024
0214dcb
Use plan Endpoint of Motis instead if route
nilspenzel Nov 5, 2024
2ac6a00
Convert time units in booking api
nilspenzel Nov 5, 2024
619368b
Use /user routes in test files
nilspenzel Nov 5, 2024
14c931f
Format
nilspenzel Nov 5, 2024
3232339
Use /user route in moveTour test
nilspenzel Nov 6, 2024
d7b98a5
Fix postgis version to 3.4.3
nilspenzel Nov 6, 2024
88177c2
wip
nilspenzel Nov 6, 2024
2695484
wip
steffenheger Nov 7, 2024
8d2aae9
wip
steffenheger Nov 7, 2024
3f9d4cb
Merge branch 'motis-v2' of github.com:motis-project/prima into v2
steffenheger Nov 7, 2024
0e074b1
wip
steffenheger Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ package-lock.json
yarn.lock

taxidriver-android-app

/src/lib/motis
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ booking-generator/test
.vscode
/driver-app/.gradle/
/driver-app/.idea
/driver-app/local.properties
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ yarn.lock
src/lib/components/*
.github/*
migrations/*

src/lib/motis
taxidriver-android-app
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
pg:
image: postgis/postgis
image: postgis/postgis:16-3.4
restart: always
container_name: pg
ports:
Expand Down
141 changes: 111 additions & 30 deletions driver-app/app/src/main/java/de/motis/prima/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.motis.prima

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -11,16 +12,29 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ExitToApp
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.Button
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.ViewModel
Expand Down Expand Up @@ -50,9 +64,11 @@ class HomeViewModel : ViewModel() {
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Home(
navController: NavController,
vehiclesViewModel: VehiclesViewModel,
viewModel: HomeViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
) {
LaunchedEffect(key1 = viewModel) {
Expand All @@ -66,48 +82,111 @@ fun Home(
}
}

var dropdownExpanded by remember {
mutableStateOf(false)
}

Scaffold(
modifier = Modifier
.fillMaxSize()
) { contentPadding ->
topBar = {
CenterAlignedTopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary,
),
title = {
Text(
"Home",
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
},
navigationIcon = {
IconButton(onClick = { navController.navigate("home") }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Localized description"
)
}
},
actions = {
IconButton(onClick = { dropdownExpanded = !dropdownExpanded }) {
Icon(Icons.Filled.MoreVert, contentDescription = "More Options")
}
DropdownMenu(
expanded = dropdownExpanded,
onDismissRequest = { dropdownExpanded = false }
) {
DropdownMenuItem(
onClick = {
dropdownExpanded = false
navController.navigate("vehicles")

},
text = {Text("Fahrzeug wechseln")}
)
DropdownMenuItem(
onClick = {
viewModel.logout()
dropdownExpanded = false

},
text = { Text("Logout") }
)
}
}
)

}
) { innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(contentPadding)
.padding(innerPadding)
) {
Spacer(modifier = Modifier.height(42.dp))
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
TextButton(onClick = { viewModel.logout() }) {
Icon(
Icons.AutoMirrored.Outlined.ExitToApp, contentDescription = null
)
}
}
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Button(
modifier = Modifier.width(300.dp),
onClick = {
navController.navigate("vehicles") {}
if (vehiclesViewModel.selectedVehicleId == 0) {
Button(
modifier = Modifier.width(300.dp),
onClick = {
navController.navigate("vehicles") {}
}
) {
Text(
text = "Fahrzeug auswählen",
fontSize = 24.sp,
textAlign = TextAlign.Center
)
}
} else {
var licensePlate = ""
try {
val vehicle = vehiclesViewModel.vehicles.value.filter {
v -> v.id == vehiclesViewModel.selectedVehicleId
}[0]
licensePlate = vehicle.license_plate
} catch (e: Exception) {
licensePlate = "Kein Fahrzeug ausgewählt"
}

Box() {
Text(
text = licensePlate,
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
textAlign = TextAlign.Center
)
}
) {
Text(
text = "Fahrzeug auswählen", fontSize = 24.sp
)
}
}

Spacer(modifier = Modifier.height(20.dp))
Spacer(modifier = Modifier.height(36.dp))

Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Button(
Expand All @@ -117,7 +196,9 @@ fun Home(
}
) {
Text(
text = "Aufträge", fontSize = 24.sp
text = "Aufträge",
fontSize = 24.sp,
textAlign = TextAlign.Center
)
}
}
Expand Down
10 changes: 6 additions & 4 deletions driver-app/app/src/main/java/de/motis/prima/Login.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class LoginViewModel : ViewModel() {
@Composable
fun Login(
navController: NavController,
vehiclesViewModel: VehiclesViewModel,
viewModel: LoginViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
) {
val snackbarHostState = remember { SnackbarHostState() }
Expand All @@ -92,14 +93,15 @@ fun Login(
LaunchedEffect(key1 = viewModel) {
// Catching successful login event and navigation to the next screen
launch {
// vehiclesViewModel.selectedVehicleId = 0
viewModel.navigationEvent.collect { shouldNavigate ->
Log.d("Navigation event", "Navigation triggered.")
if (shouldNavigate) {
Log.d("Navigation event", "Navigating to vehicle selection.")
navController.navigate("home") {
popUpTo("login") {
inclusive = true
}
if (vehiclesViewModel.selectedVehicleId == 0) {
navController.navigate("vehicles") {}
} else {
navController.navigate("tours") {}
}
}
}
Expand Down
35 changes: 29 additions & 6 deletions driver-app/app/src/main/java/de/motis/prima/Nav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
Expand All @@ -15,8 +16,10 @@ import de.motis.prima.services.CookieStore
fun Nav() {

val navController = rememberNavController()
val vehiclesViewModel: VehiclesViewModel = viewModel()
val toursViewModel: ToursViewModel = viewModel()

// Check before render of any component whether user is authenticated.
// Before rendering any component, check whether user is authenticated.
val startDestination by remember {
derivedStateOf {
val cookieStore = CookieStore(DriversApp.instance)
Expand All @@ -25,27 +28,47 @@ fun Nav() {
"login"
} else {
Log.d("Cookie", "Cookie found. Navigating to Journeys.")
"home"
if (vehiclesViewModel.selectedVehicleId == 0) {
"vehicles"
} else {
"tours"
}
}
}
}

NavHost(navController = navController, startDestination = startDestination) {

composable(route = "login") {
Login(navController)
Login(navController, vehiclesViewModel)
}

composable(route = "home") {
Home(navController)
Home(navController, vehiclesViewModel)
}

composable(route = "vehicles") {
Vehicles(navController)
Vehicles(navController, vehiclesViewModel)
}

composable(route = "tours") {
Tours(navController)
Tours(navController, vehiclesViewModel, toursViewModel)
}

composable(route = "taxameter") {
Taxameter(navController, toursViewModel)
}

composable(route = "overview/{tourId}") {
val tourId = it.arguments?.getString("tourId")?.toInt()
TourOverview(navController, tourId!!)
}


composable(route = "legs/{tourId}/{eventIndex}") {
val tourId = it.arguments?.getString("tourId")?.toInt()
val eventIndex = it.arguments?.getString("eventIndex")?.toInt()
TourDetail(navController, tourId!!, eventIndex!!, toursViewModel)
}
}
}
Loading
Loading