订阅源在未开启预加载时无法主动加载的问题

This commit is contained in:
HapeLee committed 2026-05-15 01:55:05 +08:00
1 parent 5cc126cf5b
commit c6cbfab0fa
5 files changed
+31 -44

No files matched your search

@@ -120,11 +120,7 @@ fun RssArticlesPage(
val articles by articleFlow.collectAsStateWithLifecycle(initialValue = emptyList()) val articles by articleFlow.collectAsStateWithLifecycle(initialValue = emptyList())
LaunchedEffect(rssSource?.sourceUrl, sortName, sortUrl) { LaunchedEffect(rssSource?.sourceUrl, sortName, sortUrl) {
rssSource?.let { source -> rssSource?.let(viewModel::loadArticles)
if (isPreload) {
viewModel.loadArticles(source)
}
}
} }
LaunchedEffect(loadState.errorMessage) { LaunchedEffect(loadState.errorMessage) {
@@ -308,7 +304,7 @@ private fun LoadMoreFooter(
onRetry: () -> Unit onRetry: () -> Unit
) { ) {
val text = when { val text = when {
state.isLoadingMore -> "加载中..." state.isRefreshing || state.isLoadingMore -> "加载中..."
!state.hasMore -> "没有更多了" !state.hasMore -> "没有更多了"
state.errorMessage != null -> "加载失败,点击重试" state.errorMessage != null -> "加载失败,点击重试"
else -> "上拉加载更多" else -> "上拉加载更多"
@@ -326,7 +322,7 @@ private fun LoadMoreFooter(
) { ) {
EmptyMessage( EmptyMessage(
message = text, message = text,
isLoading = state.isLoadingMore, isLoading = state.isRefreshing || state.isLoadingMore,
modifier = contentModifier modifier = contentModifier
) )
} }
@@ -90,7 +90,6 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
val pageUrl = nextPageUrl val pageUrl = nextPageUrl
if (pageUrl.isNullOrEmpty()) { if (pageUrl.isNullOrEmpty()) {
_loadState.value = currentState.copy(hasMore = false)
return return
} }
@@ -6,6 +6,7 @@ import android.app.Activity
import androidx.activity.compose.LocalActivity import androidx.activity.compose.LocalActivity
import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@@ -52,26 +53,25 @@ fun RssSortRouteScreen(
var showReadRecordSheet by remember { mutableStateOf(false) } var showReadRecordSheet by remember { mutableStateOf(false) }
var readRecords by remember { mutableStateOf<List<RssReadRecord>>(emptyList()) } var readRecords by remember { mutableStateOf<List<RssReadRecord>>(emptyList()) }
fun reloadSourceState() { suspend fun reloadSourceState() {
viewModel.initData(sourceUrl) { withContext(Dispatchers.IO) {
scope.launch { viewModel.initDataSource(sourceUrl)
sortList = viewModel.loadSorts()
articleStyle = viewModel.currentArticleStyle()
screenTitle = viewModel.rssSource?.sourceName.orEmpty()
redirectPolicy = RedirectPolicy.fromString(viewModel.rssSource?.redirectPolicy)
}
} }
sortList = viewModel.loadSorts()
articleStyle = viewModel.currentArticleStyle()
screenTitle = viewModel.rssSource?.sourceName.orEmpty()
redirectPolicy = RedirectPolicy.fromString(viewModel.rssSource?.redirectPolicy)
} }
val editSourceResult = rememberLauncherForActivityResult( val editSourceResult = rememberLauncherForActivityResult(
StartActivityContract(RssSourceEditActivity::class.java) StartActivityContract(RssSourceEditActivity::class.java)
) { ) {
if (it.resultCode == Activity.RESULT_OK) { if (it.resultCode == Activity.RESULT_OK) {
reloadSourceState() scope.launch { reloadSourceState() }
} }
} }
androidx.compose.runtime.LaunchedEffect(sourceUrl) { LaunchedEffect(sourceUrl) {
reloadSourceState() reloadSourceState()
} }
@@ -91,8 +91,9 @@ fun RssSortRouteScreen(
} }
}, },
onRefreshSort = { onRefreshSort = {
viewModel.clearSortCache { scope.launch {
scope.launch { sortList = viewModel.loadSorts() } viewModel.clearSortCache()
sortList = viewModel.loadSorts()
} }
}, },
onSetSourceVariable = { onSetSourceVariable = {
@@ -1,7 +1,6 @@
package io.legado.app.ui.rss.article package io.legado.app.ui.rss.article
import android.app.Application import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
@@ -21,23 +20,15 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
val isGridLayout get() = rssSource?.articleStyle == 2 val isGridLayout get() = rssSource?.articleStyle == 2
val isWaterLayout get() = rssSource?.articleStyle == 3 val isWaterLayout get() = rssSource?.articleStyle == 3
fun initData(intent: Intent, finally: () -> Unit) { fun initDataSource(sourceUrl: String?) {
initData(intent.getStringExtra("url") ?: intent.getStringExtra("sourceUrl"), finally) url = sourceUrl
} url?.let { src ->
rssSource = appDb.rssSourceDao.getByKey(src)
fun initData(sourceUrl: String?, finally: () -> Unit) { rssSource?.let {
execute { titleLiveData.postValue(it.sourceName)
url = sourceUrl } ?: run {
url?.let { sourceUrl -> rssSource = RssSource(sourceUrl = src)
rssSource = appDb.rssSourceDao.getByKey(sourceUrl)
rssSource?.let {
titleLiveData.postValue(it.sourceName)
} ?: let {
rssSource = RssSource(sourceUrl = sourceUrl)
}
} }
}.onFinally {
finally()
} }
} }
@@ -80,12 +71,8 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun clearSortCache(onFinally: () -> Unit) { suspend fun clearSortCache() {
execute { rssSource?.removeSortCache()
rssSource?.removeSortCache()
}.onFinally {
onFinally.invoke()
}
} }
fun getRecords(): List<RssReadRecord> { fun getRecords(): List<RssReadRecord> {
@@ -31,6 +31,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.RssStar import io.legado.app.data.entities.RssStar
import io.legado.app.ui.theme.adaptiveContentPadding
import io.legado.app.ui.widget.components.ActionItem import io.legado.app.ui.widget.components.ActionItem
import io.legado.app.ui.widget.components.EmptyMessage import io.legado.app.ui.widget.components.EmptyMessage
import io.legado.app.ui.widget.components.SourceIcon import io.legado.app.ui.widget.components.SourceIcon
@@ -191,7 +192,10 @@ fun RssFavoritesScreen(
} else { } else {
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
contentPadding = paddingValues, contentPadding = adaptiveContentPadding(
top = paddingValues.calculateTopPadding(),
bottom = paddingValues.calculateBottomPadding() + 120.dp
),
verticalArrangement = Arrangement.spacedBy(8.dp) verticalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
items(state.items, key = { "${it.origin}|${it.link}" }) { rssStar -> items(state.items, key = { "${it.origin}|${it.link}" }) { rssStar ->