Update icon pack picker automatically when an icon pack has been installed or uninstalled
This commit is contained in:
parent
c040076ce9
commit
314e4f0736
@ -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 {
|
||||
|
||||
@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import de.mm20.launcher2.database.entities.IconEntity
|
||||
import de.mm20.launcher2.database.entities.IconPackEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
internal val AppTypes = listOf("app", "calendar", "clock")
|
||||
|
||||
@ -33,8 +34,8 @@ interface IconDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun installIconPack(iconPack: IconPackEntity)
|
||||
|
||||
@Query("SELECT * FROM IconPack")
|
||||
suspend fun getInstalledIconPacks(): List<IconPackEntity>
|
||||
@Query("SELECT * FROM IconPack ORDER BY name ASC")
|
||||
fun getInstalledIconPacks(): Flow<List<IconPackEntity>>
|
||||
|
||||
@Query("SELECT * FROM IconPack WHERE packageName = :packageName LIMIT 1")
|
||||
suspend fun getIconPack(packageName: String): IconPackEntity?
|
||||
|
||||
@ -24,6 +24,8 @@ import de.mm20.launcher2.icons.loaders.GrayscaleMapIconPackInstaller
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.ktx.randomElementOrNull
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.math.roundToInt
|
||||
@ -33,11 +35,9 @@ class IconPackManager(
|
||||
private val context: Context,
|
||||
private val appDatabase: AppDatabase,
|
||||
) {
|
||||
suspend fun getInstalledIconPacks(): List<IconPack> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
appDatabase.iconDao().getInstalledIconPacks().map {
|
||||
IconPack(it)
|
||||
}
|
||||
fun getInstalledIconPacks(): Flow<List<IconPack>> {
|
||||
return appDatabase.iconDao().getInstalledIconPacks().map {
|
||||
it.map { IconPack(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,6 +375,7 @@ class IconPackManager(
|
||||
backgroundLayer = ColorLayer(),
|
||||
)
|
||||
}
|
||||
|
||||
icon.themed -> {
|
||||
StaticLauncherIcon(
|
||||
foregroundLayer = TintedClockLayer(
|
||||
@ -387,6 +388,7 @@ class IconPackManager(
|
||||
backgroundLayer = ColorLayer(),
|
||||
)
|
||||
}
|
||||
|
||||
drawable is AdaptiveIconDrawable -> {
|
||||
StaticLauncherIcon(
|
||||
foregroundLayer = ClockLayer(
|
||||
@ -402,6 +404,7 @@ class IconPackManager(
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
StaticLauncherIcon(
|
||||
foregroundLayer = ClockLayer(
|
||||
|
||||
@ -229,7 +229,7 @@ class IconRepository(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getInstalledIconPacks(): List<IconPack> {
|
||||
fun getInstalledIconPacks(): Flow<List<IconPack>> {
|
||||
return iconPackManager.getInstalledIconPacks()
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user