Add switch preference to enable feed
This commit is contained in:
@@ -21,6 +21,7 @@ import de.mm20.launcher2.ui.component.LargeMessage
|
||||
import de.mm20.launcher2.ui.component.preferences.Preference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
import de.mm20.launcher2.ui.component.preferences.SwitchPreference
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@@ -32,6 +33,7 @@ fun FeedIntegrationSettingsScreen() {
|
||||
|
||||
val viewModel: FeedIntegrationSettingsScreenVM = viewModel()
|
||||
val selectedProvider by viewModel.providerPackage.collectAsState(null)
|
||||
val feedEnabled by viewModel.feedEnabled.collectAsState(null)
|
||||
|
||||
val providers = remember { viewModel.getFeedProviders(context) }
|
||||
PreferenceScreen(
|
||||
@@ -58,6 +60,19 @@ fun FeedIntegrationSettingsScreen() {
|
||||
} else {
|
||||
item {
|
||||
PreferenceCategory {
|
||||
SwitchPreference(
|
||||
icon = R.drawable.news_24px,
|
||||
title = stringResource(R.string.preference_feed_integration),
|
||||
summary = stringResource(R.string.preference_feed_enable_summary),
|
||||
value = feedEnabled == true,
|
||||
onValueChanged = {
|
||||
viewModel.setFeedEnabled(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
item {
|
||||
PreferenceCategory(stringResource(R.string.preference_category_feed_provider)) {
|
||||
for (prov in providers) {
|
||||
Preference(
|
||||
title = prov.label,
|
||||
|
||||
@@ -23,6 +23,9 @@ class FeedIntegrationSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
val providerPackage = feedSettings.providerPackage
|
||||
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(0), 1)
|
||||
|
||||
val feedEnabled = feedSettings.enabled
|
||||
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(0), 1)
|
||||
|
||||
fun setProviderPackage(providerPackage: String?) {
|
||||
feedSettings.setProviderPackage(providerPackage)
|
||||
}
|
||||
@@ -30,4 +33,8 @@ class FeedIntegrationSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
fun getFeedProviders(context: Context): List<FeedProvider> {
|
||||
return feedService.getAvailableFeedProviders()
|
||||
}
|
||||
|
||||
fun setFeedEnabled(enabled: Boolean) {
|
||||
feedSettings.setEnabled(enabled)
|
||||
}
|
||||
}
|
||||
@@ -701,6 +701,8 @@
|
||||
<string name="preference_smartspacer_enable">Enable Smartspacer integration</string>
|
||||
<string name="preference_launch_smartspacer_app">Open Smartspacer</string>
|
||||
<string name="preference_feed_integration">Feed</string>
|
||||
<string name="preference_category_feed_provider">Feed provider</string>
|
||||
<string name="preference_feed_enable_summary">Swipe right on the home screen to open the feed</string>
|
||||
<string name="no_feed_providers">No feed providers installed</string>
|
||||
<string name="preference_contacts_call_on_tap">Tap to call</string>
|
||||
<string name="preference_contacts_call_on_tap_summary">Start a call without confirmation when tapping a phone number</string>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.preferences.feed
|
||||
|
||||
import de.mm20.launcher2.preferences.GestureAction
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@@ -7,6 +8,15 @@ class FeedSettings internal constructor(
|
||||
private val launcherDataStore: LauncherDataStore,
|
||||
) {
|
||||
|
||||
val enabled
|
||||
get() = launcherDataStore.data.map { it.gesturesSwipeRight is GestureAction.Feed }
|
||||
|
||||
fun setEnabled(enabled: Boolean) {
|
||||
launcherDataStore.update {
|
||||
it.copy(gesturesSwipeRight = if (enabled) GestureAction.Feed else GestureAction.NoAction)
|
||||
}
|
||||
}
|
||||
|
||||
val providerPackage
|
||||
get() = launcherDataStore.data.map { it.feedProviderPackage }
|
||||
|
||||
@@ -15,4 +25,5 @@ class FeedSettings internal constructor(
|
||||
it.copy(feedProviderPackage = providerPackage)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user