Add possibility to delete pinned shortcuts

This commit is contained in:
MM20
2022-08-05 13:16:26 +02:00
parent b957826227
commit 20f6acc389
3 changed files with 46 additions and 2 deletions
@@ -141,6 +141,14 @@ fun AppShortcutItem(
action = { edit = true }
))
if (viewModel.canDelete) {
toolbarActions.add(DefaultToolbarAction(
label = stringResource(R.string.menu_delete),
icon = Icons.Rounded.Delete,
action = { viewModel.deleteShortcut() }
))
}
val isHidden by viewModel.isHidden.collectAsState(false)
val hideAction = if (isHidden) {
DefaultToolbarAction(
@@ -4,11 +4,20 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.util.Log
import de.mm20.launcher2.appshortcuts.AppShortcutRepository
import de.mm20.launcher2.ktx.tryStartActivity
import de.mm20.launcher2.search.data.AppShortcut
import de.mm20.launcher2.ui.launcher.search.common.SearchableItemVM
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
class ShortcutItemVM(private val shortcut: AppShortcut) : SearchableItemVM(shortcut), KoinComponent {
private val shortcutRepository: AppShortcutRepository by inject()
val canDelete = shortcut.launcherShortcut.isPinned
class ShortcutItemVM(private val shortcut: AppShortcut) : SearchableItemVM(shortcut) {
fun openAppInfo(context: Context) {
context.tryStartActivity(
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
@@ -17,4 +26,8 @@ class ShortcutItemVM(private val shortcut: AppShortcut) : SearchableItemVM(short
}
)
}
fun deleteShortcut() {
shortcutRepository.removePinnedShortcut(shortcut)
}
}