Add possibility to delete pinned shortcuts
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user