Add debug options to weather settings screen

This commit is contained in:
MM20 2022-01-03 22:51:55 +01:00
parent 497625a9e6
commit 2a01bccb62
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 27 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.lifecycle.viewmodel.compose.viewModel
import de.mm20.launcher2.preferences.Settings.WeatherSettings.WeatherProvider
import de.mm20.launcher2.ui.BuildConfig
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.component.MissingPermissionBanner
import de.mm20.launcher2.ui.component.preferences.*
@ -108,6 +109,18 @@ fun WeatherScreen() {
)
}
}
if (BuildConfig.DEBUG) {
item {
PreferenceCategory(stringResource(R.string.preference_category_debug)) {
Preference(
"Clear weather data",
summary = "Remove weather data from database",
onClick = {
viewModel.clearWeatherData()
})
}
}
}
}
}

View File

@ -92,4 +92,8 @@ class WeatherScreenVM : ViewModel(), KoinComponent {
}
}
fun clearWeatherData() {
repository.clearForecasts()
}
}

View File

@ -32,6 +32,8 @@ interface WeatherRepository {
fun selectProvider(provider: WeatherSettings.WeatherProvider)
val selectedProvider: Flow<WeatherSettings.WeatherProvider>
fun clearForecasts()
}
class WeatherRepositoryImpl(
@ -174,6 +176,14 @@ class WeatherRepositoryImpl(
.build()
WorkManager.getInstance(context).enqueue(weatherRequest)
}
override fun clearForecasts() {
scope.launch {
withContext(Dispatchers.IO) {
database.weatherDao().deleteAll()
}
}
}
}
class WeatherUpdateWorker(val context: Context, params: WorkerParameters) :