-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
271 additions
and
11 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
app/shared/src/commonMain/kotlin/dev/datlag/burningseries/ui/navigation/DialogComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.datlag.burningseries.ui.navigation | ||
|
||
interface DialogComponent : Component { | ||
fun dismiss() | ||
} |
15 changes: 15 additions & 0 deletions
15
...d/src/commonMain/kotlin/dev/datlag/burningseries/ui/screen/initial/series/DialogConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.series | ||
|
||
import com.arkivanov.essenty.parcelable.Parcelable | ||
import com.arkivanov.essenty.parcelable.Parcelize | ||
import dev.datlag.burningseries.model.Series | ||
|
||
@Parcelize | ||
sealed class DialogConfig : Parcelable { | ||
|
||
@Parcelize | ||
data class Season( | ||
val selected: Series.Season, | ||
val seasons: List<Series.Season> | ||
) : DialogConfig() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...kotlin/dev/datlag/burningseries/ui/screen/initial/series/dialog/season/SeasonComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.series.dialog.season | ||
|
||
import dev.datlag.burningseries.model.Series | ||
import dev.datlag.burningseries.ui.navigation.DialogComponent | ||
|
||
interface SeasonComponent : DialogComponent { | ||
|
||
val defaultSeason: Series.Season | ||
val seasons: List<Series.Season> | ||
|
||
fun onConfirm(season: Series.Season) | ||
} |
111 changes: 111 additions & 0 deletions
111
...in/kotlin/dev/datlag/burningseries/ui/screen/initial/series/dialog/season/SeasonDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.series.dialog.season | ||
|
||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.selection.selectable | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Check | ||
import androidx.compose.material.icons.filled.Clear | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import dev.datlag.burningseries.shared.SharedRes | ||
import dev.icerock.moko.resources.compose.stringResource | ||
|
||
@Composable | ||
fun SeasonDialog(component: SeasonComponent) { | ||
var selectedItem by remember { mutableStateOf(component.defaultSeason) } | ||
|
||
AlertDialog( | ||
onDismissRequest = { | ||
component.dismiss() | ||
}, | ||
title = { | ||
Text( | ||
text = stringResource(SharedRes.strings.select_season), | ||
style = MaterialTheme.typography.headlineMedium, | ||
maxLines = 2, | ||
overflow = TextOverflow.Ellipsis, | ||
softWrap = true | ||
) | ||
}, | ||
text = { | ||
Column( | ||
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
) { | ||
component.seasons.forEach { | ||
val selected = selectedItem == it | ||
Row( | ||
modifier = Modifier.selectable( | ||
selected = selected, | ||
role = Role.RadioButton, | ||
onClick = { selectedItem = it } | ||
).fillMaxWidth(), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
RadioButton( | ||
selected = selected, | ||
onClick = null | ||
) | ||
val seasonText = if (it.title.toIntOrNull() != null) { | ||
stringResource(SharedRes.strings.season_placeholder, it.title) | ||
} else { | ||
it.title | ||
} | ||
Text( | ||
text = seasonText, | ||
overflow = TextOverflow.Ellipsis, | ||
softWrap = true | ||
) | ||
} | ||
} | ||
} | ||
}, | ||
confirmButton = { | ||
Button( | ||
onClick = { | ||
if (component.defaultSeason != selectedItem) { | ||
component.onConfirm(selectedItem) | ||
} else { | ||
component.dismiss() | ||
} | ||
} | ||
) { | ||
Icon( | ||
imageVector = Icons.Default.Check, | ||
contentDescription = stringResource(SharedRes.strings.confirm), | ||
modifier = Modifier.size(ButtonDefaults.IconSize) | ||
) | ||
Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing)) | ||
Text(text = stringResource(SharedRes.strings.confirm)) | ||
} | ||
}, | ||
dismissButton = { | ||
Button( | ||
onClick = { | ||
component.dismiss() | ||
}, | ||
modifier = Modifier.padding(bottom = 8.dp), | ||
colors = ButtonDefaults.buttonColors( | ||
containerColor = MaterialTheme.colorScheme.errorContainer, | ||
contentColor = MaterialTheme.colorScheme.onErrorContainer | ||
) | ||
) { | ||
Icon( | ||
imageVector = Icons.Default.Clear, | ||
contentDescription = stringResource(SharedRes.strings.close), | ||
modifier = Modifier.size(ButtonDefaults.IconSize) | ||
) | ||
Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing)) | ||
Text(text = stringResource(SharedRes.strings.close)) | ||
} | ||
} | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
.../dev/datlag/burningseries/ui/screen/initial/series/dialog/season/SeasonDialogComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.series.dialog.season | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.arkivanov.decompose.ComponentContext | ||
import dev.datlag.burningseries.model.Series | ||
import org.kodein.di.DI | ||
|
||
class SeasonDialogComponent( | ||
componentContext: ComponentContext, | ||
override val di: DI, | ||
override val defaultSeason: Series.Season, | ||
override val seasons: List<Series.Season>, | ||
private val onDismissed: () -> Unit, | ||
private val onSelected: (Series.Season) -> Unit | ||
) : SeasonComponent, ComponentContext by componentContext { | ||
|
||
@Composable | ||
override fun render() { | ||
SeasonDialog(this) | ||
} | ||
|
||
override fun dismiss() { | ||
onDismissed() | ||
} | ||
|
||
override fun onConfirm(season: Series.Season) { | ||
onSelected(season) | ||
onDismissed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.