Create shortcuts from edit favorite panel

Close #154
This commit is contained in:
MM20
2022-09-18 21:35:51 +02:00
parent 7a73b72314
commit b068e4d6fd
5 changed files with 351 additions and 116 deletions
@@ -16,6 +16,7 @@ import de.mm20.launcher2.permissions.PermissionGroup
import de.mm20.launcher2.permissions.PermissionsManager
import de.mm20.launcher2.preferences.LauncherDataStore
import de.mm20.launcher2.search.data.AppShortcut
import de.mm20.launcher2.search.data.LauncherApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -31,6 +32,8 @@ interface AppShortcutRepository {
count: Int = 5
): List<AppShortcut>
suspend fun getShortcutsConfigActivities(): List<LauncherApp>
fun search(query: String): Flow<List<AppShortcut>>
fun removePinnedShortcut(shortcut: AppShortcut)
@@ -204,6 +207,24 @@ internal class AppShortcutRepositoryImpl(
)
}
override suspend fun getShortcutsConfigActivities(): List<LauncherApp> {
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
if (!launcherApps.hasShortcutHostPermission()) return emptyList()
val results = mutableListOf<LauncherApp>()
val profiles = launcherApps.profiles
for (profile in profiles) {
val activities = launcherApps.getShortcutConfigActivityList(null, profile)
results.addAll(
activities.map {
LauncherApp(
context, it
)
}
)
}
return results.sorted()
}
private fun matches(label: String, query: String): Boolean {
val labelLatin = label.normalize()