Create appshortcuts module

This commit is contained in:
MM20
2022-03-19 15:46:13 +01:00
parent fb762736a1
commit b73c9fabc9
22 changed files with 244 additions and 95 deletions
+1
View File
@@ -115,6 +115,7 @@ dependencies {
implementation(project(":search"))
implementation(project(":preferences"))
implementation(project(":applications"))
implementation(project(":appshortcuts"))
implementation(project(":calculator"))
implementation(project(":files"))
implementation(project(":widgets"))
@@ -112,7 +112,9 @@ fun AppItem(
)
}
for (shortcut in app.shortcuts.subList(0, min(app.shortcuts.size, 5))) {
val shortcuts by viewModel.shortcuts.collectAsState(emptyList())
for (shortcut in shortcuts) {
val title =
shortcut.launcherShortcut.shortLabel
?: shortcut.launcherShortcut.longLabel
@@ -10,14 +10,17 @@ import android.provider.Settings
import android.service.notification.StatusBarNotification
import androidx.core.content.FileProvider
import androidx.core.content.getSystemService
import de.mm20.launcher2.appshortcuts.AppShortcutRepository
import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.ktx.tryStartActivity
import de.mm20.launcher2.notifications.NotificationRepository
import de.mm20.launcher2.search.data.AppShortcut
import de.mm20.launcher2.search.data.Application
import de.mm20.launcher2.search.data.LauncherApp
import de.mm20.launcher2.ui.launcher.search.common.SearchableItemVM
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import org.koin.core.component.inject
@@ -26,6 +29,7 @@ class AppItemVM(
private val app: Application
) : SearchableItemVM(app) {
private val notificationRepository: NotificationRepository by inject()
private val appShortcutRepository: AppShortcutRepository by inject()
val notifications =
@@ -105,6 +109,12 @@ class AppItemVM(
return launcherApps.getShortcutIconDrawable(shortcut, 0)
}
val shortcuts = flow {
if (app is LauncherApp) {
emit(appShortcutRepository.getShortcutsForActivity(app.launcherActivityInfo, 5))
}
}
fun isShortcutPinned(shortcut: AppShortcut): Flow<Boolean> {
return favoritesRepository.isPinned(shortcut)
}