Hide widgets that are already in use from widget picker

This commit is contained in:
MM20
2023-04-10 14:09:29 +02:00
parent f927ed8e82
commit 4db54fc038
2 changed files with 17 additions and 4 deletions
@@ -23,7 +23,8 @@ class WidgetsService(
) {
suspend fun getAppWidgetProviders(): List<AppWidgetProviderInfo> = withContext(Dispatchers.IO) {
val appWidgetManager = AppWidgetManager.getInstance(context)
val launcherApps = context.getSystemService<LauncherApps>() ?: return@withContext emptyList()
val launcherApps =
context.getSystemService<LauncherApps>() ?: return@withContext emptyList()
val profiles = launcherApps.profiles
val widgets = mutableListOf<AppWidgetProviderInfo>()
for (profile in profiles) {
@@ -32,6 +33,18 @@ class WidgetsService(
widgets
}
fun getAvailableBuiltInWidgets(): Flow<List<BuiltInWidgetInfo>> {
return widgetRepository.get().map { widgets ->
getBuiltInWidgets().filter {
it.type == FavoritesWidget.Type && !widgets.any { it is FavoritesWidget } ||
it.type == WeatherWidget.Type && !widgets.any { it is WeatherWidget } ||
it.type == MusicWidget.Type && !widgets.any { it is MusicWidget } ||
it.type == CalendarWidget.Type && !widgets.any { it is CalendarWidget }
}
}
}
fun getBuiltInWidgets(): List<BuiltInWidgetInfo> {
return listOf(
BuiltInWidgetInfo(