Skip to content

Commit

Permalink
display activation state
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 19, 2023
1 parent f46881a commit 63895d7
Show file tree
Hide file tree
Showing 21 changed files with 381 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.component

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.error

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.style.TextOverflow
import dev.datlag.burningseries.SharedRes
import dev.icerock.moko.resources.compose.stringResource

@Composable
actual fun ErrorDialog(component: ErrorComponent) {
AlertDialog(
onDismissRequest = {
component.dismiss()
},
title = {
Text(
text = stringResource(SharedRes.strings.activate_error_title),
style = MaterialTheme.typography.headlineMedium,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
softWrap = true
)
},
text = {
Text(text = stringResource(SharedRes.strings.activate_error_text))
},
confirmButton = {
Button(
onClick = {
component.dismiss()
}
) {
Text(text = stringResource(SharedRes.strings.close))
}
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.success

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.style.TextOverflow
import dev.datlag.burningseries.SharedRes
import dev.icerock.moko.resources.compose.stringResource

@Composable
actual fun SuccessDialog(component: SuccessComponent) {
AlertDialog(
onDismissRequest = {
component.dismiss()
},
title = {
Text(
text = stringResource(SharedRes.strings.activate_success_title),
style = MaterialTheme.typography.headlineMedium,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
softWrap = true
)
},
text = {
Text(text = stringResource(SharedRes.strings.activate_success_text))
},
confirmButton = {
Button(
onClick = {
component.dismiss()
}
) {
Text(text = stringResource(SharedRes.strings.close))
}
},
dismissButton = if (component.stream != null) {
{
Button(
onClick = {

}
) {
Text(text = stringResource(SharedRes.strings.watch))
}
}
} else {
null
}
)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate

import com.arkivanov.decompose.router.slot.ChildSlot
import com.arkivanov.decompose.value.Value
import dev.datlag.burningseries.model.Series
import dev.datlag.burningseries.ui.navigation.Component
import dev.datlag.burningseries.ui.navigation.DialogComponent
import dev.datlag.burningseries.ui.screen.initial.series.activate.component.DialogConfig

interface ActivateComponent : Component {

val episode: Series.Episode
val scrapingJs: String

val dialog: Value<ChildSlot<DialogConfig, DialogComponent>>

fun back()
fun onScraped(data: String)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBackIosNew
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import dev.icerock.moko.resources.compose.stringResource
import dev.datlag.burningseries.SharedRes
import dev.datlag.burningseries.model.BSUtil
Expand Down Expand Up @@ -37,14 +38,21 @@ fun ActivateScreen(component: ActivateComponent) {
)
}
) {
Box(modifier = Modifier.padding(it)) {
val dialogState by component.dialog.subscribeAsState()

Column(
modifier = Modifier.padding(it),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
dialogState.child?.instance?.render()
WebView(
url = BSUtil.getBurningSeriesLink(component.episode.href),
scrapingJs = component.scrapingJs,
modifier = Modifier.fillMaxSize()
) { data ->
component.onScraped(data)
}
modifier = Modifier.fillMaxSize(),
onScraped = { data ->
component.onScraped(data)
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package dev.datlag.burningseries.ui.screen.initial.series.activate

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.router.slot.SlotNavigation
import com.arkivanov.decompose.router.slot.activate
import com.arkivanov.decompose.router.slot.childSlot
import com.arkivanov.decompose.router.slot.dismiss
import com.arkivanov.essenty.backhandler.BackCallback
import dev.datlag.burningseries.model.Series
import org.kodein.di.DI
import dev.datlag.burningseries.SharedRes
import dev.datlag.burningseries.common.ioScope
import dev.datlag.burningseries.common.launchIO
import dev.datlag.burningseries.common.withMainContext
import dev.datlag.burningseries.model.HosterScraping
import dev.datlag.burningseries.model.common.scopeCatching
import dev.datlag.burningseries.model.state.EpisodeAction
Expand All @@ -16,6 +21,10 @@ import dev.datlag.burningseries.model.state.SaveAction
import dev.datlag.burningseries.model.state.SaveState
import dev.datlag.burningseries.network.state.EpisodeStateMachine
import dev.datlag.burningseries.network.state.SaveStateMachine
import dev.datlag.burningseries.ui.navigation.DialogComponent
import dev.datlag.burningseries.ui.screen.initial.series.activate.component.DialogConfig
import dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.error.ErrorDialogComponent
import dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.success.SuccessDialogComponent
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.serialization.json.Json
Expand All @@ -34,6 +43,25 @@ class ActivateScreenComponent(
private val json by di.instance<Json>()
private val savedData: MutableSet<String> = mutableSetOf()

private val dialogNavigation = SlotNavigation<DialogConfig>()
override val dialog = childSlot(
source = dialogNavigation
) { config, slotContext ->
when (config) {
is DialogConfig.Success -> SuccessDialogComponent(
componentContext = slotContext,
di = di,
stream = config.stream,
onDismissed = dialogNavigation::dismiss
) as DialogComponent
is DialogConfig.Error -> ErrorDialogComponent(
componentContext = slotContext,
di = di,
onDismissed = dialogNavigation::dismiss
)
}
}

private val backCallback = BackCallback {
onGoBack()
}
Expand All @@ -43,11 +71,14 @@ class ActivateScreenComponent(

ioScope().launchIO {
saveState.collect { state ->
when (val current = state) {
is SaveState.Saving -> {
println("Saving data: ${current.data}")
if (state is SaveState.Success) {
withMainContext {
dialogNavigation.activate(DialogConfig.Success(state.stream))
}
} else if (state is SaveState.Error) {
withMainContext {
dialogNavigation.activate(DialogConfig.Error)
}
else -> { }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.component

import com.arkivanov.essenty.parcelable.Parcelable
import com.arkivanov.essenty.parcelable.Parcelize
import dev.datlag.burningseries.model.Stream

@Parcelize
sealed class DialogConfig : Parcelable {

@Parcelize
data class Success(val stream: Stream?) : DialogConfig(), Parcelable

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

import dev.datlag.burningseries.ui.navigation.DialogComponent

interface ErrorComponent : DialogComponent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.error

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.style.TextOverflow
import dev.icerock.moko.resources.compose.stringResource
import dev.datlag.burningseries.SharedRes

@Composable
expect fun ErrorDialog(component: ErrorComponent)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.error

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import org.kodein.di.DI

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

@Composable
override fun render() {
ErrorDialog(this)
}

override fun dismiss() {
onDismissed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.success

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

interface SuccessComponent : DialogComponent {

val stream: Stream?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.success

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.style.TextOverflow
import dev.icerock.moko.resources.compose.stringResource
import dev.datlag.burningseries.SharedRes

@Composable
expect fun SuccessDialog(component: SuccessComponent)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.dialog.success

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

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

@Composable
override fun render() {
SuccessDialog(this)
}

override fun dismiss() {
onDismissed()
}
}
5 changes: 5 additions & 0 deletions app/shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
<string name="activate_hint">Activate episodes by loading them once</string>
<string name="later">Later</string>
<string name="browser_initializing">Browser initializing, please wait</string>
<string name="activate_success_title">Successfully activated hoster</string>
<string name="activate_success_text">You can go back now or continue browsing and activate some more.</string>
<string name="activate_error_title">Error activating hoster</string>
<string name="activate_error_text">Could not activate hoster, please try again later.</string>
<string name="watch">Watch</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package dev.datlag.burningseries.ui.screen.initial.series.activate.component

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.awt.SwingPanel
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.multiplatform.webview.web.WebContent
import dev.datlag.burningseries.SharedRes
import dev.datlag.burningseries.common.withIOContext
Expand All @@ -30,7 +35,7 @@ actual fun WebView(url: String, scrapingJs: String, modifier: Modifier, onScrape
factory = {
browser.uiComponent
},
modifier = modifier
modifier = modifier.padding(8.dp)
)

LaunchedEffect(browser) {
Expand Down
Loading

0 comments on commit 63895d7

Please sign in to comment.