Hide settings for widgets if they are disabled
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package de.mm20.launcher2.ui.settings.widgets
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import de.mm20.launcher2.widgets.WidgetRepository
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class WidgetSettingsScreenVM: ViewModel(), KoinComponent {
|
||||
|
||||
private val widgetRepository: WidgetRepository by inject()
|
||||
|
||||
val calendarWidget = widgetRepository.isCalendarWidgetEnabled().asLiveData()
|
||||
val musicWidget = widgetRepository.isMusicWidgetEnabled().asLiveData()
|
||||
val weatherWidget = widgetRepository.isWeatherWidgetEnabled().asLiveData()
|
||||
}
|
||||
@@ -6,7 +6,10 @@ import androidx.compose.material.icons.rounded.LightMode
|
||||
import androidx.compose.material.icons.rounded.Schedule
|
||||
import androidx.compose.material.icons.rounded.Today
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.preferences.Preference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
@@ -15,6 +18,7 @@ import de.mm20.launcher2.ui.locals.LocalNavController
|
||||
@Composable
|
||||
fun WidgetsSettingsScreen() {
|
||||
val navController = LocalNavController.current
|
||||
val viewModel: WidgetSettingsScreenVM = viewModel()
|
||||
PreferenceScreen(title = stringResource(R.string.preference_screen_widgets)) {
|
||||
item {
|
||||
Preference(
|
||||
@@ -24,27 +28,39 @@ fun WidgetsSettingsScreen() {
|
||||
navController?.navigate("settings/widgets/clock")
|
||||
}
|
||||
)
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_screen_weatherwidget),
|
||||
icon = Icons.Rounded.LightMode,
|
||||
onClick = {
|
||||
navController?.navigate("settings/widgets/weather")
|
||||
}
|
||||
)
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_screen_musicwidget),
|
||||
icon = Icons.Rounded.Audiotrack,
|
||||
onClick = {
|
||||
navController?.navigate("settings/widgets/music")
|
||||
}
|
||||
)
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_screen_calendarwidget),
|
||||
icon = Icons.Rounded.Today,
|
||||
onClick = {
|
||||
navController?.navigate("settings/widgets/calendar")
|
||||
}
|
||||
)
|
||||
|
||||
val weatherWidget by viewModel.weatherWidget.observeAsState()
|
||||
if (weatherWidget == true) {
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_screen_weatherwidget),
|
||||
icon = Icons.Rounded.LightMode,
|
||||
onClick = {
|
||||
navController?.navigate("settings/widgets/weather")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val musicWidget by viewModel.musicWidget.observeAsState()
|
||||
if (musicWidget == true) {
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_screen_musicwidget),
|
||||
icon = Icons.Rounded.Audiotrack,
|
||||
onClick = {
|
||||
navController?.navigate("settings/widgets/music")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val calendarWidget by viewModel.calendarWidget.observeAsState()
|
||||
if (calendarWidget == true) {
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_screen_calendarwidget),
|
||||
icon = Icons.Rounded.Today,
|
||||
onClick = {
|
||||
navController?.navigate("settings/widgets/calendar")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user