Hide widgets that are already in use from widget picker
This commit is contained in:
parent
f927ed8e82
commit
4db54fc038
@ -42,9 +42,9 @@ class WidgetPickerSheetVM(
|
||||
private val enabledWidgets = widgetsService.getWidgets()
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(100), emptyList())
|
||||
|
||||
private val allBuiltInWidgets = enabledWidgets.map { w ->
|
||||
widgetsService.getBuiltInWidgets().filter { b -> !w.any { it::class == b::class } }
|
||||
}.shareIn(viewModelScope, SharingStarted.WhileSubscribed(100))
|
||||
private val allBuiltInWidgets =
|
||||
widgetsService.getAvailableBuiltInWidgets()
|
||||
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(100))
|
||||
|
||||
val builtInWidgets = allBuiltInWidgets
|
||||
.combine(searchQuery) { widgets, query ->
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user