Add hidden item badges (but don't enable them)
This commit is contained in:
parent
1d6688831c
commit
a29475b485
16
core/base/src/main/res/drawable/ic_badge_hidden.xml
Normal file
16
core/base/src/main/res/drawable/ic_badge_hidden.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#000000"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<group
|
||||
android:pivotX="12"
|
||||
android:pivotY="12"
|
||||
android:scaleX="0.75"
|
||||
android:scaleY="0.75">
|
||||
<path
|
||||
android:fillColor="@color/badge_text"
|
||||
android:pathData="M12,6.5c2.76,0 5,2.24 5,5 0,0.51 -0.1,1 -0.24,1.46l3.06,3.06c1.39,-1.23 2.49,-2.77 3.18,-4.53C21.27,7.11 17,4 12,4c-1.27,0 -2.49,0.2 -3.64,0.57l2.17,2.17c0.47,-0.14 0.96,-0.24 1.47,-0.24zM2.71,3.16c-0.39,0.39 -0.39,1.02 0,1.41l1.97,1.97C3.06,7.83 1.77,9.53 1,11.5 2.73,15.89 7,19 12,19c1.52,0 2.97,-0.3 4.31,-0.82l2.72,2.72c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L4.13,3.16c-0.39,-0.39 -1.03,-0.39 -1.42,0zM12,16.5c-2.76,0 -5,-2.24 -5,-5 0,-0.77 0.18,-1.5 0.49,-2.14l1.57,1.57c-0.03,0.18 -0.06,0.37 -0.06,0.57 0,1.66 1.34,3 3,3 0.2,0 0.38,-0.03 0.57,-0.07L14.14,16c-0.65,0.32 -1.37,0.5 -2.14,0.5zM14.97,11.17c-0.15,-1.4 -1.25,-2.49 -2.64,-2.64l2.64,2.64z" />
|
||||
</group>
|
||||
</vector>
|
||||
@ -1,6 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#000000"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<group
|
||||
|
||||
@ -482,7 +482,7 @@
|
||||
<string name="preference_automatic_location">Automatic location</string>
|
||||
<string name="preference_automatic_location_summary">Use GPS and location services to determine location automatically</string>
|
||||
<string name="preference_location_managed">Managed by plugin</string>
|
||||
<string name="preference_location_managed_summary">The location for this provider can be configured in the plugin app</string>
|
||||
<string name="preference_location_managed_summary">The location for this provider is managed by the plugin app</string>
|
||||
<string name="preference_location">Location</string>
|
||||
<string name="preference_imperial_units_summary">Use degrees Fahrenheit and miles per hour</string>
|
||||
<string name="preference_imperial_units">Imperial units</string>
|
||||
|
||||
@ -47,7 +47,6 @@ dependencies {
|
||||
implementation(project(":core:preferences"))
|
||||
implementation(project(":core:ktx"))
|
||||
implementation(project(":data:wikipedia"))
|
||||
implementation(project(":services:badges"))
|
||||
implementation(project(":core:crashreporter"))
|
||||
|
||||
}
|
||||
@ -50,4 +50,5 @@ dependencies {
|
||||
implementation(project(":core:preferences"))
|
||||
implementation(project(":core:base"))
|
||||
implementation(project(":data:files"))
|
||||
implementation(project(":data:searchable"))
|
||||
}
|
||||
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import de.mm20.launcher2.badges.providers.AppShortcutBadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.BadgeProvider
|
||||
import de.mm20.launcher2.badges.providers.CloudBadgeProvider
|
||||
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
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
package de.mm20.launcher2.badges.providers
|
||||
|
||||
import de.mm20.launcher2.badges.Badge
|
||||
import de.mm20.launcher2.badges.R
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.Searchable
|
||||
import de.mm20.launcher2.searchable.SavableSearchableRepository
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.shareIn
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class HiddenItemBadgeProvider(
|
||||
) : BadgeProvider, KoinComponent {
|
||||
|
||||
private val searchableRepository: SavableSearchableRepository by inject()
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||
|
||||
private val hiddenItemKeys = searchableRepository.getKeys(
|
||||
hidden = true,
|
||||
limit = 9999,
|
||||
).shareIn(scope, SharingStarted.WhileSubscribed(), 1)
|
||||
|
||||
override fun getBadge(searchable: Searchable): Flow<Badge?> {
|
||||
if (searchable !is SavableSearchable) return flowOf(null)
|
||||
return hiddenItemKeys.map { keys ->
|
||||
if (searchable.key in keys) {
|
||||
Badge(
|
||||
iconRes = R.drawable.ic_badge_hidden
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user