|
|
@@ -29,8 +29,6 @@ import androidx.compose.material.icons.filled.Subscriptions
|
|
|
import androidx.compose.material.icons.filled.VerticalAlignTop
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
import androidx.compose.runtime.Composable
|
|
|
-import androidx.compose.runtime.CompositionLocalProvider
|
|
|
-import androidx.compose.runtime.DisposableEffect
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
@@ -46,11 +44,6 @@ import androidx.compose.ui.res.stringResource
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
-import androidx.lifecycle.Lifecycle
|
|
|
-import androidx.lifecycle.LifecycleEventObserver
|
|
|
-import androidx.lifecycle.LifecycleOwner
|
|
|
-import androidx.lifecycle.LifecycleRegistry
|
|
|
-import androidx.lifecycle.compose.LocalLifecycleOwner
|
|
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
|
import io.legado.app.R
|
|
|
import io.legado.app.data.entities.RssSource
|
|
|
@@ -79,7 +72,6 @@ import org.koin.androidx.compose.koinViewModel
|
|
|
@Composable
|
|
|
fun RssScreen(
|
|
|
viewModel: RssViewModel = koinViewModel(),
|
|
|
- isActive: Boolean = true,
|
|
|
onOpenSort: (sourceUrl: String, sortUrl: String?, key: String?) -> Unit,
|
|
|
onOpenRead: (title: String?, origin: String, link: String?, openUrl: String?) -> Unit,
|
|
|
onOpenRuleSub: () -> Unit,
|
|
|
@@ -96,7 +88,6 @@ fun RssScreen(
|
|
|
val currentOnOpenRead by rememberUpdatedState(onOpenRead)
|
|
|
val currentOnOpenRuleSub by rememberUpdatedState(onOpenRuleSub)
|
|
|
val currentOnOpenFavorites by rememberUpdatedState(onOpenFavorites)
|
|
|
- val pageLifecycleOwner = rememberRssPageLifecycleOwner(isActive)
|
|
|
|
|
|
LaunchedEffect(viewModel) {
|
|
|
viewModel.effects.collectLatest { effect ->
|
|
|
@@ -141,8 +132,7 @@ fun RssScreen(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- CompositionLocalProvider(LocalLifecycleOwner provides pageLifecycleOwner) {
|
|
|
- ListScaffold(
|
|
|
+ ListScaffold(
|
|
|
title = stringResource(R.string.rss),
|
|
|
state = uiState,
|
|
|
subtitle = uiState.group.ifEmpty { stringResource(R.string.all) },
|
|
|
@@ -253,7 +243,6 @@ fun RssScreen(
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
AppAlertDialog(
|
|
|
@@ -270,51 +259,6 @@ fun RssScreen(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-@Composable
|
|
|
-private fun rememberRssPageLifecycleOwner(isActive: Boolean): LifecycleOwner {
|
|
|
- val parentLifecycle = LocalLifecycleOwner.current.lifecycle
|
|
|
- val currentActive by rememberUpdatedState(isActive)
|
|
|
- val owner = remember(parentLifecycle) { RssPageLifecycleOwner() }
|
|
|
-
|
|
|
- DisposableEffect(parentLifecycle) {
|
|
|
- val observer = LifecycleEventObserver { _, _ ->
|
|
|
- owner.update(parentLifecycle.currentState, currentActive)
|
|
|
- }
|
|
|
- parentLifecycle.addObserver(observer)
|
|
|
- owner.update(parentLifecycle.currentState, currentActive)
|
|
|
- onDispose {
|
|
|
- parentLifecycle.removeObserver(observer)
|
|
|
- owner.destroy()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- LaunchedEffect(isActive, parentLifecycle) {
|
|
|
- owner.update(parentLifecycle.currentState, isActive)
|
|
|
- }
|
|
|
-
|
|
|
- return owner
|
|
|
-}
|
|
|
-
|
|
|
-private class RssPageLifecycleOwner : LifecycleOwner {
|
|
|
-
|
|
|
- private val registry = LifecycleRegistry(this)
|
|
|
-
|
|
|
- override val lifecycle: Lifecycle = registry
|
|
|
-
|
|
|
- fun update(parentState: Lifecycle.State, isActive: Boolean) {
|
|
|
- registry.currentState = when {
|
|
|
- parentState == Lifecycle.State.DESTROYED -> Lifecycle.State.DESTROYED
|
|
|
- !parentState.isAtLeast(Lifecycle.State.STARTED) -> Lifecycle.State.CREATED
|
|
|
- isActive -> parentState
|
|
|
- else -> Lifecycle.State.STARTED
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun destroy() {
|
|
|
- registry.currentState = Lifecycle.State.DESTROYED
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
@OptIn(ExperimentalFoundationApi::class)
|
|
|
@Composable
|
|
|
fun RssSourceGridItem(
|
|
|
@@ -341,7 +285,7 @@ fun RssSourceGridItem(
|
|
|
) {
|
|
|
Box {
|
|
|
SourceIcon(
|
|
|
- path = source.sourceIcon.ifEmpty { R.drawable.image_rss },
|
|
|
+ path = source.sourceIcon,
|
|
|
sourceOrigin = source.sourceUrl,
|
|
|
modifier = Modifier.size(48.dp)
|
|
|
)
|