Fix source tab long click
This commit is contained in:
parent
de4567a508
commit
290e962a57
@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PushPin
|
||||
import androidx.compose.material.icons.outlined.PushPin
|
||||
@ -189,8 +191,8 @@ fun SourceOptionsDialog(
|
||||
onClickPin: () -> Unit,
|
||||
onClickDisable: () -> Unit,
|
||||
// SY -->
|
||||
onClickSetCategories: () -> Unit,
|
||||
onClickToggleDataSaver: () -> Unit,
|
||||
onClickSetCategories: (() -> Unit)?,
|
||||
onClickToggleDataSaver: (() -> Unit)?,
|
||||
// SY <--
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
@ -218,24 +220,28 @@ fun SourceOptionsDialog(
|
||||
)
|
||||
}
|
||||
// SY -->
|
||||
Text(
|
||||
text = stringResource(id = R.string.categories),
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClickSetCategories)
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp),
|
||||
)
|
||||
Text(
|
||||
text = if (source.isExcludedFromDataSaver) {
|
||||
stringResource(id = R.string.data_saver_stop_exclude)
|
||||
} else {
|
||||
stringResource(id = R.string.data_saver_exclude)
|
||||
},
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClickToggleDataSaver)
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp),
|
||||
)
|
||||
if (onClickSetCategories != null) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.categories),
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClickSetCategories)
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp),
|
||||
)
|
||||
}
|
||||
if (onClickToggleDataSaver != null) {
|
||||
Text(
|
||||
text = if (source.isExcludedFromDataSaver) {
|
||||
stringResource(id = R.string.data_saver_stop_exclude)
|
||||
} else {
|
||||
stringResource(id = R.string.data_saver_exclude)
|
||||
},
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClickToggleDataSaver)
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp),
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
},
|
||||
@ -252,12 +258,11 @@ sealed class SourceUiModel {
|
||||
// SY -->
|
||||
@Composable
|
||||
fun SourceCategoriesDialog(
|
||||
source: Source?,
|
||||
source: Source,
|
||||
categories: List<String>,
|
||||
onClickCategories: (List<String>) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
source ?: return
|
||||
val newCategories = remember(source) {
|
||||
mutableStateListOf<String>().also { it += source.categories }
|
||||
}
|
||||
@ -266,7 +271,7 @@ fun SourceCategoriesDialog(
|
||||
Text(text = source.visualName)
|
||||
},
|
||||
text = {
|
||||
Column {
|
||||
Column(Modifier.verticalScroll(rememberScrollState())) {
|
||||
categories.forEach {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@ -293,7 +298,7 @@ fun SourceCategoriesDialog(
|
||||
}
|
||||
}
|
||||
},
|
||||
onDismissRequest = onDismiss,
|
||||
onDismissRequest = onDismissRequest,
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onClickCategories(newCategories.toList()) }) {
|
||||
Text(text = stringResource(android.R.string.ok))
|
||||
|
@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import logcat.LogPriority
|
||||
@ -67,6 +68,12 @@ class SourcesScreenModel(
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
.launchIn(coroutineScope)
|
||||
|
||||
sourcePreferences.dataSaver().changes()
|
||||
.onEach { enabled ->
|
||||
mutableState.update { it.copy(dataSaverEnabled = enabled) }
|
||||
}
|
||||
.launchIn(coroutineScope)
|
||||
// SY <--
|
||||
}
|
||||
|
||||
@ -182,6 +189,7 @@ data class SourcesState(
|
||||
val categories: List<String> = emptyList(),
|
||||
val showPin: Boolean = true,
|
||||
val showLatest: Boolean = false,
|
||||
val dataSaverEnabled: Boolean = false,
|
||||
// SY <--
|
||||
) {
|
||||
val isEmpty = items.isEmpty()
|
||||
|
@ -77,45 +77,43 @@ fun Screen.sourcesTab(
|
||||
onLongClickItem = screenModel::showSourceDialog,
|
||||
)
|
||||
|
||||
state.dialog?.let { dialog ->
|
||||
when (dialog) {
|
||||
is SourcesScreenModel.Dialog.SourceCategories -> {
|
||||
val source = dialog.source
|
||||
SourceOptionsDialog(
|
||||
source = source,
|
||||
onClickPin = {
|
||||
screenModel.togglePin(source)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
onClickDisable = {
|
||||
screenModel.toggleSource(source)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
// SY -->
|
||||
onClickSetCategories = {
|
||||
screenModel.showSourceCategoriesDialog(source)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
onClickToggleDataSaver = {
|
||||
screenModel.toggleExcludeFromDataSaver(source)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
onDismiss = screenModel::closeDialog,
|
||||
)
|
||||
}
|
||||
is SourcesScreenModel.Dialog.SourceLongClick -> {
|
||||
val source = dialog.source
|
||||
SourceCategoriesDialog(
|
||||
source = source,
|
||||
categories = state.categories,
|
||||
onClickCategories = { categories ->
|
||||
screenModel.setSourceCategories(source, categories)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
onDismiss = screenModel::closeDialog,
|
||||
)
|
||||
}
|
||||
when (val dialog = state.dialog) {
|
||||
is SourcesScreenModel.Dialog.SourceLongClick -> {
|
||||
val source = dialog.source
|
||||
SourceOptionsDialog(
|
||||
source = source,
|
||||
onClickPin = {
|
||||
screenModel.togglePin(source)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
onClickDisable = {
|
||||
screenModel.toggleSource(source)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
// SY -->
|
||||
onClickSetCategories = {
|
||||
screenModel.showSourceCategoriesDialog(source)
|
||||
}.takeIf { state.categories.isNotEmpty() },
|
||||
onClickToggleDataSaver = {
|
||||
screenModel.toggleExcludeFromDataSaver(source)
|
||||
screenModel.closeDialog()
|
||||
}.takeIf { state.dataSaverEnabled },
|
||||
onDismiss = screenModel::closeDialog,
|
||||
)
|
||||
}
|
||||
is SourcesScreenModel.Dialog.SourceCategories -> {
|
||||
val source = dialog.source
|
||||
SourceCategoriesDialog(
|
||||
source = source,
|
||||
categories = state.categories,
|
||||
onClickCategories = { categories ->
|
||||
screenModel.setSourceCategories(source, categories)
|
||||
screenModel.closeDialog()
|
||||
},
|
||||
onDismissRequest = screenModel::closeDialog,
|
||||
)
|
||||
}
|
||||
null -> Unit
|
||||
}
|
||||
|
||||
val internalErrString = stringResource(R.string.internal_error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user