fix: 源变量无法设置的问题
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
@file:Suppress("DEPRECATION")
|
|
||||||
|
|
||||||
package io.legado.app.ui.rss.article
|
package io.legado.app.ui.rss.article
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
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.LaunchedEffect
|
||||||
@@ -14,15 +11,12 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.data.entities.RssReadRecord
|
import io.legado.app.data.entities.RssReadRecord
|
||||||
import io.legado.app.ui.login.SourceLoginActivity
|
import io.legado.app.ui.login.SourceLoginActivity
|
||||||
import io.legado.app.ui.rss.read.RedirectPolicy
|
import io.legado.app.ui.rss.read.RedirectPolicy
|
||||||
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
|
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
|
||||||
import io.legado.app.ui.widget.dialog.VariableDialog
|
|
||||||
import io.legado.app.utils.StartActivityContract
|
import io.legado.app.utils.StartActivityContract
|
||||||
import io.legado.app.utils.showDialogFragment
|
|
||||||
import io.legado.app.utils.startActivity
|
import io.legado.app.utils.startActivity
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -40,7 +34,6 @@ fun RssSortRouteScreen(
|
|||||||
viewModel: RssSortViewModel = koinViewModel()
|
viewModel: RssSortViewModel = koinViewModel()
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val activity = LocalActivity.current as? AppCompatActivity
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
var sortList by remember(sourceUrl) { mutableStateOf<List<Pair<String, String>>>(emptyList()) }
|
var sortList by remember(sourceUrl) { mutableStateOf<List<Pair<String, String>>>(emptyList()) }
|
||||||
@@ -52,6 +45,7 @@ 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()) }
|
||||||
|
var sourceVariableSheet by remember { mutableStateOf<RssSourceVariableSheetState?>(null) }
|
||||||
|
|
||||||
suspend fun reloadSourceState() {
|
suspend fun reloadSourceState() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@@ -83,6 +77,7 @@ fun RssSortRouteScreen(
|
|||||||
redirectPolicy = redirectPolicy,
|
redirectPolicy = redirectPolicy,
|
||||||
showReadRecordSheet = showReadRecordSheet,
|
showReadRecordSheet = showReadRecordSheet,
|
||||||
readRecords = readRecords,
|
readRecords = readRecords,
|
||||||
|
sourceVariableSheet = sourceVariableSheet,
|
||||||
onBackClick = onBackClick,
|
onBackClick = onBackClick,
|
||||||
onLogin = {
|
onLogin = {
|
||||||
context.startActivity<SourceLoginActivity> {
|
context.startActivity<SourceLoginActivity> {
|
||||||
@@ -105,16 +100,19 @@ fun RssSortRouteScreen(
|
|||||||
}
|
}
|
||||||
val comment = source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
|
val comment = source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
|
||||||
val variable = withContext(Dispatchers.IO) { source.getVariable() }
|
val variable = withContext(Dispatchers.IO) { source.getVariable() }
|
||||||
activity?.showDialogFragment(
|
sourceVariableSheet = RssSourceVariableSheetState(
|
||||||
VariableDialog(
|
title = setSourceVariableText,
|
||||||
setSourceVariableText,
|
variable = variable,
|
||||||
source.getKey(),
|
comment = comment
|
||||||
variable,
|
|
||||||
comment
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onDismissSourceVariable = { sourceVariableSheet = null },
|
||||||
|
onSaveSourceVariable = { variable ->
|
||||||
|
viewModel.setSourceVariable(variable)
|
||||||
|
sourceVariableSheet = null
|
||||||
|
context.toastOnUi(R.string.save_success)
|
||||||
|
},
|
||||||
onEditSource = {
|
onEditSource = {
|
||||||
viewModel.rssSource?.sourceUrl?.let { srcUrl ->
|
viewModel.rssSource?.sourceUrl?.let { srcUrl ->
|
||||||
editSourceResult.launch { putExtra("sourceUrl", srcUrl) }
|
editSourceResult.launch { putExtra("sourceUrl", srcUrl) }
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.PaddingValues
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
@@ -14,12 +15,15 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.FormatListBulleted
|
import androidx.compose.material.icons.automirrored.filled.FormatListBulleted
|
||||||
import androidx.compose.material.icons.automirrored.filled.Login
|
import androidx.compose.material.icons.automirrored.filled.Login
|
||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.Check
|
||||||
import androidx.compose.material.icons.filled.CleaningServices
|
import androidx.compose.material.icons.filled.CleaningServices
|
||||||
import androidx.compose.material.icons.filled.Dataset
|
import androidx.compose.material.icons.filled.Dataset
|
||||||
|
import androidx.compose.material.icons.filled.Done
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material.icons.filled.History
|
import androidx.compose.material.icons.filled.History
|
||||||
import androidx.compose.material.icons.filled.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
@@ -33,6 +37,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
@@ -47,7 +52,9 @@ import io.legado.app.ui.rss.read.title
|
|||||||
import io.legado.app.ui.theme.LegadoTheme
|
import io.legado.app.ui.theme.LegadoTheme
|
||||||
import io.legado.app.ui.theme.adaptiveHorizontalPaddingTab
|
import io.legado.app.ui.theme.adaptiveHorizontalPaddingTab
|
||||||
import io.legado.app.ui.widget.components.AppScaffold
|
import io.legado.app.ui.widget.components.AppScaffold
|
||||||
|
import io.legado.app.ui.widget.components.AppTextField
|
||||||
import io.legado.app.ui.widget.components.EmptyMessage
|
import io.legado.app.ui.widget.components.EmptyMessage
|
||||||
|
import io.legado.app.ui.widget.components.button.series.MediumPlainButton
|
||||||
import io.legado.app.ui.widget.components.button.series.SmallPlainButton
|
import io.legado.app.ui.widget.components.button.series.SmallPlainButton
|
||||||
import io.legado.app.ui.widget.components.button.series.SmallToggleButton
|
import io.legado.app.ui.widget.components.button.series.SmallToggleButton
|
||||||
import io.legado.app.ui.widget.components.button.series.ToggleStyle
|
import io.legado.app.ui.widget.components.button.series.ToggleStyle
|
||||||
@@ -65,6 +72,13 @@ import io.legado.app.ui.widget.components.topbar.TopBarActionButton
|
|||||||
import io.legado.app.ui.widget.components.topbar.TopBarNavigationButton
|
import io.legado.app.ui.widget.components.topbar.TopBarNavigationButton
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@Stable
|
||||||
|
data class RssSourceVariableSheetState(
|
||||||
|
val title: String,
|
||||||
|
val variable: String,
|
||||||
|
val comment: String
|
||||||
|
)
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun RssSortScreen(
|
fun RssSortScreen(
|
||||||
@@ -75,10 +89,13 @@ fun RssSortScreen(
|
|||||||
redirectPolicy: RedirectPolicy,
|
redirectPolicy: RedirectPolicy,
|
||||||
showReadRecordSheet: Boolean,
|
showReadRecordSheet: Boolean,
|
||||||
readRecords: List<RssReadRecord>,
|
readRecords: List<RssReadRecord>,
|
||||||
|
sourceVariableSheet: RssSourceVariableSheetState?,
|
||||||
onBackClick: () -> Unit,
|
onBackClick: () -> Unit,
|
||||||
onLogin: () -> Unit,
|
onLogin: () -> Unit,
|
||||||
onRefreshSort: () -> Unit,
|
onRefreshSort: () -> Unit,
|
||||||
onSetSourceVariable: () -> Unit,
|
onSetSourceVariable: () -> Unit,
|
||||||
|
onDismissSourceVariable: () -> Unit,
|
||||||
|
onSaveSourceVariable: (String) -> Unit,
|
||||||
onEditSource: () -> Unit,
|
onEditSource: () -> Unit,
|
||||||
onSwitchLayout: () -> Unit,
|
onSwitchLayout: () -> Unit,
|
||||||
onReadRecord: () -> Unit,
|
onReadRecord: () -> Unit,
|
||||||
@@ -305,6 +322,12 @@ fun RssSortScreen(
|
|||||||
onClear = onClearReadRecord,
|
onClear = onClearReadRecord,
|
||||||
onOpen = onOpenReadRecord
|
onOpen = onOpenReadRecord
|
||||||
)
|
)
|
||||||
|
|
||||||
|
RssSourceVariableSheet(
|
||||||
|
state = sourceVariableSheet,
|
||||||
|
onDismissRequest = onDismissSourceVariable,
|
||||||
|
onSave = onSaveSourceVariable
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -367,3 +390,48 @@ private fun RssReadRecordSheet(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RssSourceVariableSheet(
|
||||||
|
state: RssSourceVariableSheetState?,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
onSave: (String) -> Unit
|
||||||
|
) {
|
||||||
|
var variable by remember(state) { mutableStateOf(state?.variable.orEmpty()) }
|
||||||
|
|
||||||
|
AppModalBottomSheet(
|
||||||
|
data = state,
|
||||||
|
onDismissRequest = onDismissRequest,
|
||||||
|
title = state?.title,
|
||||||
|
endAction = {
|
||||||
|
MediumPlainButton(
|
||||||
|
onClick = { onSave(variable) },
|
||||||
|
icon = Icons.Default.Done,
|
||||||
|
contentDescription = stringResource(R.string.ok)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { sheetState ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.navigationBarsPadding()
|
||||||
|
.padding(bottom = 32.dp)
|
||||||
|
) {
|
||||||
|
AppText(
|
||||||
|
text = sheetState.comment,
|
||||||
|
style = LegadoTheme.typography.bodyMedium,
|
||||||
|
color = LegadoTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(bottom = 12.dp)
|
||||||
|
)
|
||||||
|
AppTextField(
|
||||||
|
value = variable,
|
||||||
|
onValueChange = { variable = it },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
minLines = 8
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
rssSource?.removeSortCache()
|
rssSource?.removeSortCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setSourceVariable(variable: String?) {
|
||||||
|
rssSource?.setVariable(variable)
|
||||||
|
}
|
||||||
|
|
||||||
fun getRecords(): List<RssReadRecord> {
|
fun getRecords(): List<RssReadRecord> {
|
||||||
return appDb.rssReadRecordDao.getRecords()
|
return appDb.rssReadRecordDao.getRecords()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user