Show tag icons on tag settings screen

This commit is contained in:
MM20 2024-11-15 22:26:07 +01:00
parent eeaa8fa8dd
commit b2a39e2350
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 17 additions and 9 deletions

View File

@ -19,8 +19,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import de.mm20.launcher2.ui.R import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.component.ShapedLauncherIcon
import de.mm20.launcher2.ui.component.preferences.Preference import de.mm20.launcher2.ui.component.preferences.Preference
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
@ -46,19 +48,16 @@ fun TagsSettingsScreen() {
for (tag in tags) { for (tag in tags) {
var showMenu by remember { mutableStateOf(false) } var showMenu by remember { mutableStateOf(false) }
val (emoji, tagName) = remember(tag) { val icon by remember(tag) { viewModel.getIcon(tag) }.collectAsState(null)
tag.splitLeadingEmoji()
}
Preference( Preference(
icon = { icon = {
if (emoji != null) { ShapedLauncherIcon(
Text(emoji) size = 36.dp,
} else { icon = { icon },
Icon(Icons.Rounded.Tag, null) )
}
}, },
title = { Text(tagName ?: "") }, title = { Text(tag) },
onClick = { onClick = {
viewModel.editTag.value = tag viewModel.editTag.value = tag
}, },

View File

@ -4,7 +4,11 @@ import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.data.customattrs.CustomAttributesRepository import de.mm20.launcher2.data.customattrs.CustomAttributesRepository
import de.mm20.launcher2.icons.IconService
import de.mm20.launcher2.icons.LauncherIcon
import de.mm20.launcher2.search.Tag
import de.mm20.launcher2.services.tags.TagsService import de.mm20.launcher2.services.tags.TagsService
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent import org.koin.core.component.KoinComponent
@ -12,6 +16,7 @@ import org.koin.core.component.inject
class TagsSettingsScreenVM: ViewModel(), KoinComponent { class TagsSettingsScreenVM: ViewModel(), KoinComponent {
private val tagsService: TagsService by inject() private val tagsService: TagsService by inject()
private val iconService: IconService by inject()
val tags = tagsService.getAllTags() val tags = tagsService.getAllTags()
@ -35,4 +40,8 @@ class TagsSettingsScreenVM: ViewModel(), KoinComponent {
tagsService.deleteTag(tag) tagsService.deleteTag(tag)
} }
fun getIcon(tag: String): Flow<LauncherIcon?> {
return iconService.getIcon(Tag(tag), 1)
}
} }