make AppShortcuts hideable
This commit is contained in:
parent
d080d71e0f
commit
afd793fc85
@ -45,6 +45,7 @@ dependencies {
|
||||
|
||||
implementation(project(":search"))
|
||||
implementation(project(":permissions"))
|
||||
implementation(project(":hiddenitems"))
|
||||
implementation(project(":base"))
|
||||
implementation(project(":preferences"))
|
||||
implementation(project(":ktx"))
|
||||
|
||||
@ -7,6 +7,7 @@ import android.content.pm.PackageManager
|
||||
import android.os.Process
|
||||
import androidx.core.content.getSystemService
|
||||
import com.github.promeg.pinyinhelper.Pinyin
|
||||
import de.mm20.launcher2.hiddenitems.HiddenItemsRepository
|
||||
import de.mm20.launcher2.permissions.PermissionGroup
|
||||
import de.mm20.launcher2.permissions.PermissionsManager
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
@ -32,6 +33,7 @@ interface AppShortcutRepository {
|
||||
internal class AppShortcutRepositoryImpl(
|
||||
private val context: Context,
|
||||
private val permissionsManager: PermissionsManager,
|
||||
private val hiddenItemsRepository: HiddenItemsRepository,
|
||||
private val dataStore: LauncherDataStore,
|
||||
) : AppShortcutRepository {
|
||||
|
||||
@ -107,18 +109,23 @@ internal class AppShortcutRepositoryImpl(
|
||||
|
||||
val pm = context.packageManager
|
||||
|
||||
send(shortcuts.map {
|
||||
val label = try {
|
||||
pm.getApplicationInfo(it.`package`, 0).loadLabel(pm).toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
""
|
||||
}
|
||||
AppShortcut(
|
||||
context,
|
||||
it,
|
||||
label
|
||||
|
||||
hiddenItemsRepository.hiddenItemsKeys.collectLatest { hidden ->
|
||||
send(
|
||||
shortcuts.mapNotNull {
|
||||
val label = try {
|
||||
pm.getApplicationInfo(it.`package`, 0).loadLabel(pm).toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
""
|
||||
}
|
||||
AppShortcut(
|
||||
context,
|
||||
it,
|
||||
label
|
||||
).takeIf { !hidden.contains(it.key) }
|
||||
}.sorted()
|
||||
)
|
||||
}.sorted())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,5 +4,5 @@ import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
|
||||
val appShortcutsModule = module {
|
||||
single<AppShortcutRepository> { AppShortcutRepositoryImpl(androidContext(), get(), get()) }
|
||||
single<AppShortcutRepository> { AppShortcutRepositoryImpl(androidContext(), get(), get(), get()) }
|
||||
}
|
||||
@ -6,10 +6,7 @@ import androidx.compose.animation.core.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.Info
|
||||
import androidx.compose.material.icons.rounded.Star
|
||||
import androidx.compose.material.icons.rounded.StarOutline
|
||||
import androidx.compose.material.icons.rounded.*
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@ -60,7 +57,12 @@ fun AppShortcutItem(
|
||||
.padding(16.dp)
|
||||
) {
|
||||
val titleStyle by animateTextStyleAsState(if (showDetails) MaterialTheme.typography.titleMedium else MaterialTheme.typography.titleSmall)
|
||||
Text(text = shortcut.label, style = titleStyle, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(
|
||||
text = shortcut.label,
|
||||
style = titleStyle,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
val textSpace by transition.animateDp(label = "textSpace") {
|
||||
if (it) 4.dp else 2.dp
|
||||
}
|
||||
@ -123,6 +125,27 @@ fun AppShortcutItem(
|
||||
viewModel.openAppInfo(context)
|
||||
})
|
||||
|
||||
val isHidden by viewModel.isHidden.collectAsState(false)
|
||||
val hideAction = if (isHidden) {
|
||||
DefaultToolbarAction(
|
||||
label = stringResource(R.string.menu_unhide),
|
||||
icon = Icons.Rounded.Visibility,
|
||||
action = {
|
||||
viewModel.unhide()
|
||||
onBack()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
DefaultToolbarAction(
|
||||
label = stringResource(R.string.menu_hide),
|
||||
icon = Icons.Rounded.VisibilityOff,
|
||||
action = {
|
||||
viewModel.hide()
|
||||
onBack()
|
||||
})
|
||||
}
|
||||
toolbarActions.add(hideAction)
|
||||
|
||||
Toolbar(
|
||||
leftActions = listOf(
|
||||
DefaultToolbarAction(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user