Skip to content

Commit

Permalink
Merge pull request #487 from jaro-jaro/455-pridat-moznost-prepnout-de…
Browse files Browse the repository at this point in the history
…n-kdyz-nic-nejede

#455 V odjezdech přidána tlačítka na přepínání dnů i když nic nejede
  • Loading branch information
rblaha15 authored Sep 4, 2024
2 parents 05502d9 + d181b9f commit fcd60af
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 88 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId = "cz.jaro.dpmcb"
minSdk = 26
targetSdk = 34
versionCode = 44
versionName = "1.6.4-pre.1"
versionCode = 45
versionName = "1.6.4-pre.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
153 changes: 68 additions & 85 deletions app/src/main/java/cz/jaro/dpmcb/ui/departures/DeparturesScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -80,8 +81,8 @@ import cz.jaro.dpmcb.data.helperclasses.UtilFunctions.plus
import cz.jaro.dpmcb.data.helperclasses.UtilFunctions.toCzechLocative
import cz.jaro.dpmcb.data.realtions.StopType
import cz.jaro.dpmcb.ui.chooser.ChooserType
import cz.jaro.dpmcb.ui.common.IconWithTooltip
import cz.jaro.dpmcb.ui.common.ChooserResult
import cz.jaro.dpmcb.ui.common.IconWithTooltip
import cz.jaro.dpmcb.ui.common.StopTypeIcon
import cz.jaro.dpmcb.ui.common.toLocalTime
import cz.jaro.dpmcb.ui.departures.DeparturesEvent.Canceled
Expand Down Expand Up @@ -425,98 +426,80 @@ fun DeparturesScreen(
CircularProgressIndicator()
}

is DeparturesState.NothingRuns -> Row(
Modifier
.padding(top = 8.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Text(
when (state) {
DeparturesState.NothingRunsAtAll -> "Přes tuto zastávku ${date.toCzechLocative()} nic nejede"
DeparturesState.NothingRunsHere -> "Přes tuto zastávku nejede žádný spoj, který bude zastavovat na zastávce ${info.stopFilter}"
DeparturesState.LineDoesNotRun -> "Přes tuto zastávku nejede žádný spoj linky ${info.lineFilter}"
DeparturesState.LineDoesNotRunHere -> "Přes tuto zastávku nejede žádný spoj linky ${info.lineFilter}, který bude zastavovat na zastávce ${info.stopFilter}"
},
Modifier.padding(horizontal = 16.dp)
)
}

is DeparturesState.Runs -> LazyColumn(
else -> LazyColumn(
state = listState,
modifier = Modifier.padding(top = 16.dp)
) {
items(
count = state.line.size + 2,
key = { i ->
when (i) {
0 -> 0
state.line.lastIndex + 2 -> Int.MAX_VALUE
else -> state.line[i - 1].busName to state.line[i - 1].time
}
},
itemContent = { i ->
when (i) {
0 -> {
Surface(
modifier = Modifier.clickable {
onEvent(DeparturesEvent.PreviousDay)
},
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.padding(top = 4.dp, start = 16.dp, end = 16.dp, bottom = 8.dp)
) {
Text(
modifier = Modifier
.weight(1F),
text = "Předchozí den…",
fontSize = 20.sp,
textAlign = TextAlign.Center,
)
}
}
}

state.line.lastIndex + 2 -> {
HorizontalDivider()
Surface(
modifier = Modifier.clickable {
onEvent(DeparturesEvent.NextDay)
},
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.padding(top = 4.dp, start = 16.dp, end = 16.dp, bottom = 8.dp)
) {
Text(
modifier = Modifier
.weight(1F),
text = "Následující den…",
fontSize = 20.sp,
textAlign = TextAlign.Center,
)
}
}
}

else -> Card(
state.line[i - 1], onEvent, info.compactMode, modifier = Modifier
.animateContentSize()
// .animateItemPlacement(spring(stiffness = Spring.StiffnessMediumLow))
)
}
item {
HorizontalDivider()
DaySwitcher(onEvent, DeparturesEvent.PreviousDay, "Předchozí den…")
}
if (state is DeparturesState.NothingRuns) item {
HorizontalDivider()
Row(
Modifier
.padding(top = 4.dp, start = 16.dp, end = 16.dp, bottom = 8.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Text(
when (state) {
DeparturesState.NothingRunsAtAll -> "Přes tuto zastávku ${date.toCzechLocative()} nic nejede"
DeparturesState.NothingRunsHere -> "Přes tuto zastávku nejede žádný spoj, který bude zastavovat na zastávce ${info.stopFilter}"
DeparturesState.LineDoesNotRun -> "Přes tuto zastávku nejede žádný spoj linky ${info.lineFilter}"
DeparturesState.LineDoesNotRunHere -> "Přes tuto zastávku nejede žádný spoj linky ${info.lineFilter}, který bude zastavovat na zastávce ${info.stopFilter}"
},
Modifier.padding(horizontal = 16.dp)
)
}
)
}
else if (state is DeparturesState.Runs) items(
items = state.line,
key = { state ->
state.busName to state.time
},
) { state ->
Card(
state, onEvent, info.compactMode, modifier = Modifier
.animateContentSize()
.animateItem()
// .animateItemPlacement(spring(stiffness = Spring.StiffnessMediumLow))
)
}
item {
HorizontalDivider()
DaySwitcher(onEvent, DeparturesEvent.NextDay, "Následující den…")
HorizontalDivider()
}
}
}
}
}

@Composable
private fun DaySwitcher(onEvent: (DeparturesEvent) -> Unit, event: DeparturesEvent, text: String) {
Surface(
modifier = Modifier.clickable {
onEvent(event)
},
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.padding(top = 4.dp, start = 16.dp, end = 16.dp, bottom = 8.dp)
) {
Text(
modifier = Modifier
.weight(1F),
text = text,
fontSize = 20.sp,
textAlign = TextAlign.Center,
)
}
}
}

@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
private fun Card(
Expand Down Expand Up @@ -662,4 +645,4 @@ fun Duration.asString(): String {
minutes == 0 -> "$hours hod"
else -> "$hours hod $minutes min"
}
}
}
2 changes: 1 addition & 1 deletion app/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.4-pre.1
1.6.4-pre.2

0 comments on commit fcd60af

Please sign in to comment.