Update icon pack picker automatically when an icon pack has been installed or uninstalled

This commit is contained in:
MM20
2023-03-03 14:42:08 +01:00
parent c040076ce9
commit 314e4f0736
6 changed files with 30 additions and 26 deletions
@@ -57,9 +57,7 @@ class CustomizeSearchableSheetVM(
val iconSearchResults = mutableStateOf(emptyList<CustomIconWithPreview>())
val isSearchingIcons = mutableStateOf(false)
val installedIconPacks = flow {
emit(iconRepository.getInstalledIconPacks().sortedBy { it.name })
}
val installedIconPacks = iconRepository.getInstalledIconPacks()
private var debounceSearchJob: Job? = null
suspend fun searchIcon(query: String, iconPack: IconPack?) {
@@ -25,6 +25,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@@ -248,7 +249,7 @@ fun AppearanceSettingsScreen() {
)
val iconPackPackage by viewModel.iconPack.observeAsState()
val installedIconPacks by viewModel.installedIconPacks.observeAsState(emptyList())
val installedIconPacks by viewModel.installedIconPacks.collectAsState(emptyList())
val iconPack by remember {
derivedStateOf { installedIconPacks.firstOrNull { it.packageName == iconPackPackage } }
}
@@ -5,16 +5,21 @@ import android.content.Intent
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import androidx.lifecycle.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.icons.IconPack
import de.mm20.launcher2.icons.IconRepository
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.preferences.LauncherDataStore
import de.mm20.launcher2.preferences.Settings
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.*
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.ColorScheme
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Font
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
import de.mm20.launcher2.preferences.Settings.SearchBarSettings
import de.mm20.launcher2.preferences.Settings.SearchBarSettings.SearchBarColors
import de.mm20.launcher2.preferences.Settings.SystemBarsSettings
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
@@ -193,18 +198,14 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
}
}
val installedIconPacks: LiveData<List<IconPack>> = liveData {
emit(
listOf(
IconPack(
name = "System",
packageName = "",
version = "",
)
) +
iconRepository.getInstalledIconPacks()
)
}
val installedIconPacks: Flow<List<IconPack>> = iconRepository.getInstalledIconPacks().map {
listOf(IconPack(
name = "System",
packageName = "",
version = "",
)) + it
}
val iconPack = dataStore.data.map { it.icons.iconPack }.asLiveData()
fun setIconPack(iconPack: String) {
viewModelScope.launch {