React to changing profile availability
This commit is contained in:
@@ -48,6 +48,7 @@ dependencies {
|
||||
implementation(project(":data:appshortcuts"))
|
||||
implementation(project(":data:notifications"))
|
||||
implementation(project(":core:preferences"))
|
||||
implementation(project(":core:profiles"))
|
||||
implementation(project(":core:base"))
|
||||
implementation(project(":data:files"))
|
||||
implementation(project(":data:searchable"))
|
||||
|
||||
@@ -8,7 +8,7 @@ import de.mm20.launcher2.badges.providers.HiddenItemBadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.NotificationBadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.PluginBadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.SuspendedAppsBadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.WorkProfileBadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.ProfileBadgeProvider
|
||||
import de.mm20.launcher2.preferences.ui.BadgeSettings
|
||||
import de.mm20.launcher2.search.Searchable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -42,7 +42,7 @@ internal class BadgeServiceImpl(
|
||||
scope.launch {
|
||||
settings.distinctUntilChanged().collectLatest {
|
||||
val providers = mutableListOf<BadgeProvider>()
|
||||
providers += WorkProfileBadgeProvider()
|
||||
providers += ProfileBadgeProvider()
|
||||
providers += HiddenItemBadgeProvider()
|
||||
if (it.notifications) {
|
||||
providers += NotificationBadgeProvider()
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package de.mm20.launcher2.badges.providers
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Lock
|
||||
import androidx.compose.material.icons.rounded.Work
|
||||
import de.mm20.launcher2.badges.Badge
|
||||
import de.mm20.launcher2.badges.BadgeIcon
|
||||
import de.mm20.launcher2.profiles.Profile
|
||||
import de.mm20.launcher2.profiles.ProfileManager
|
||||
import de.mm20.launcher2.search.AppShortcut
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.Searchable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emitAll
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class ProfileBadgeProvider : BadgeProvider, KoinComponent {
|
||||
private val profileManager: ProfileManager by inject()
|
||||
|
||||
override fun getBadge(searchable: Searchable): Flow<Badge?> = flow {
|
||||
val userHandle = when(searchable) {
|
||||
is Application -> searchable.user
|
||||
is AppShortcut -> searchable.user
|
||||
else -> null
|
||||
}
|
||||
if (userHandle != null) {
|
||||
emitAll(
|
||||
profileManager.getProfile(userHandle).map {
|
||||
when(it?.type) {
|
||||
Profile.Type.Work -> WorkProfile
|
||||
Profile.Type.Private -> PrivateProfile
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
emit(null)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val WorkProfile = Badge(
|
||||
icon = BadgeIcon(Icons.Rounded.Work)
|
||||
)
|
||||
|
||||
private val PrivateProfile = Badge(
|
||||
icon = BadgeIcon(Icons.Rounded.Lock)
|
||||
)
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package de.mm20.launcher2.badges.providers
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Work
|
||||
import de.mm20.launcher2.badges.Badge
|
||||
import de.mm20.launcher2.badges.BadgeIcon
|
||||
import de.mm20.launcher2.badges.MutableBadge
|
||||
import de.mm20.launcher2.badges.R
|
||||
import de.mm20.launcher2.search.AppProfile
|
||||
import de.mm20.launcher2.search.AppShortcut
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.Searchable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
class WorkProfileBadgeProvider : BadgeProvider {
|
||||
override fun getBadge(searchable: Searchable): Flow<Badge?> = flow {
|
||||
if (searchable is Application && searchable.profile == AppProfile.Work || searchable is AppShortcut && searchable.profile == AppProfile.Work) {
|
||||
emit(
|
||||
MutableBadge(
|
||||
icon = BadgeIcon(Icons.Rounded.Work)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
emit(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user