Skip to content

Commit

Permalink
added watch option for error save state
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Dec 2, 2023
1 parent 50d6e1a commit e5d3bcc
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ actual fun ErrorDialog(component: ErrorComponent) {
) {
Text(text = stringResource(SharedRes.strings.close))
}
},
dismissButton = if (component.stream != null) {
{
Button(
onClick = {
component.watch(component.stream!!)
}
) {
Text(text = stringResource(SharedRes.strings.watch))
}
}
} else {
null
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class ActivateScreenComponent(
is DialogConfig.Error -> ErrorDialogComponent(
componentContext = slotContext,
di = di,
onDismissed = dialogNavigation::dismiss
stream = config.stream,
onDismissed = dialogNavigation::dismiss,
watchVideo = { watchVideo(it) }
)
}
}
Expand All @@ -79,7 +81,7 @@ class ActivateScreenComponent(
}
} else if (state is SaveState.Error) {
withMainContext {
dialogNavigation.activate(DialogConfig.Error)
dialogNavigation.activate(DialogConfig.Error(state.stream))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ sealed class DialogConfig : Parcelable {
data class Success(val stream: Stream?) : DialogConfig(), Parcelable

@Parcelize
data object Error : DialogConfig(), Parcelable
data class Error(val stream: Stream?) : DialogConfig(), Parcelable
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.datlag.burningseries.shared.ui.screen.initial.series.activate.dialog.error

import dev.datlag.burningseries.model.Stream
import dev.datlag.burningseries.shared.ui.navigation.DialogComponent

interface ErrorComponent : DialogComponent {
val stream: Stream?
fun watch(stream: Stream)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package dev.datlag.burningseries.shared.ui.screen.initial.series.activate.dialog

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import dev.datlag.burningseries.model.Stream
import org.kodein.di.DI

class ErrorDialogComponent(
componentContext: ComponentContext,
override val di: DI,
private val onDismissed: () -> Unit
override val stream: Stream?,
private val onDismissed: () -> Unit,
private val watchVideo: (Stream) -> Unit
) : ErrorComponent, ComponentContext by componentContext {

@Composable
Expand All @@ -18,4 +21,8 @@ class ErrorDialogComponent(
override fun dismiss() {
onDismissed()
}

override fun watch(stream: Stream) {
watchVideo(stream)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import dev.datlag.burningseries.model.Stream
import dev.datlag.burningseries.shared.ui.navigation.DialogComponent

interface SuccessComponent : DialogComponent {

val stream: Stream?

fun watch(stream: Stream)
}
2 changes: 1 addition & 1 deletion app/shared/src/commonMain/resources/MR/de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<string name="close">Schließen</string>
<string name="clear">Löschen</string>
<string name="stream_unavailable_title">Stream nicht verfügbar</string>
<string name="stream_unavailable_text">Kein Stream verfügbar, du kannst welche jetzt in der App aktivieren oder die Browser-Extension auf dem PC verwenden.</string>
<string name="stream_unavailable_text">Kein Stream verfügbar, du kannst jetzt welche in der App aktivieren oder die Browser-Extension auf dem PC verwenden.</string>
<string name="activate">Aktivieren</string>
<string name="activate_hint">Aktiviere Episoden, indem du sie einmal lädst</string>
<string name="later">Später</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.datlag.burningseries.shared.ui.screen.initial.series.activate.dialog.error

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
Expand Down Expand Up @@ -31,13 +33,27 @@ actual fun ErrorDialog(component: ErrorComponent) {
text = stringResource(SharedRes.strings.activate_error_text),
modifier = Modifier.padding(8.dp)
)
Button(
onClick = {
component.dismiss()
},
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(8.dp).align(Alignment.End)
) {
Text(text = stringResource(SharedRes.strings.close))
if (component.stream != null) {
Button(
onClick = {
component.watch(component.stream!!)
}
) {
Text(text = stringResource(SharedRes.strings.watch))
}
}
Button(
onClick = {
component.dismiss()
}
) {
Text(text = stringResource(SharedRes.strings.close))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sealed interface SaveState {
data object Waiting : SaveState
data class Saving(val data: HosterScraping, val loadStream: Boolean) : SaveState
data class Success(val stream: Stream?) : SaveState
data object Error : SaveState
data class Error(val stream: Stream?) : SaveState
}

sealed interface SaveAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SaveStateMachine(
if (anySuccess) {
state.override { SaveState.Success(stream) }
} else {
state.override { SaveState.Error }
state.override { SaveState.Error(stream) }
}
}
}
Expand Down

0 comments on commit e5d3bcc

Please sign in to comment.