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 iconSearchResults = mutableStateOf(emptyList<CustomIconWithPreview>())
|
||||||
val isSearchingIcons = mutableStateOf(false)
|
val isSearchingIcons = mutableStateOf(false)
|
||||||
|
|
||||||
val installedIconPacks = flow {
|
val installedIconPacks = iconRepository.getInstalledIconPacks()
|
||||||
emit(iconRepository.getInstalledIconPacks().sortedBy { it.name })
|
|
||||||
}
|
|
||||||
|
|
||||||
private var debounceSearchJob: Job? = null
|
private var debounceSearchJob: Job? = null
|
||||||
suspend fun searchIcon(query: String, iconPack: IconPack?) {
|
suspend fun searchIcon(query: String, iconPack: IconPack?) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
@ -248,7 +249,7 @@ fun AppearanceSettingsScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val iconPackPackage by viewModel.iconPack.observeAsState()
|
val iconPackPackage by viewModel.iconPack.observeAsState()
|
||||||
val installedIconPacks by viewModel.installedIconPacks.observeAsState(emptyList())
|
val installedIconPacks by viewModel.installedIconPacks.collectAsState(emptyList())
|
||||||
val iconPack by remember {
|
val iconPack by remember {
|
||||||
derivedStateOf { installedIconPacks.firstOrNull { it.packageName == iconPackPackage } }
|
derivedStateOf { installedIconPacks.firstOrNull { it.packageName == iconPackPackage } }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,16 +5,21 @@ import android.content.Intent
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.getSystemService
|
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.IconPack
|
||||||
import de.mm20.launcher2.icons.IconRepository
|
import de.mm20.launcher2.icons.IconRepository
|
||||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||||
import de.mm20.launcher2.preferences.Settings
|
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
|
||||||
import de.mm20.launcher2.preferences.Settings.SearchBarSettings.SearchBarColors
|
import de.mm20.launcher2.preferences.Settings.SearchBarSettings.SearchBarColors
|
||||||
import de.mm20.launcher2.preferences.Settings.SystemBarsSettings
|
import de.mm20.launcher2.preferences.Settings.SystemBarsSettings
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
@ -193,18 +198,14 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val installedIconPacks: LiveData<List<IconPack>> = liveData {
|
val installedIconPacks: Flow<List<IconPack>> = iconRepository.getInstalledIconPacks().map {
|
||||||
emit(
|
listOf(IconPack(
|
||||||
listOf(
|
name = "System",
|
||||||
IconPack(
|
packageName = "",
|
||||||
name = "System",
|
version = "",
|
||||||
packageName = "",
|
)) + it
|
||||||
version = "",
|
}
|
||||||
)
|
|
||||||
) +
|
|
||||||
iconRepository.getInstalledIconPacks()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val iconPack = dataStore.data.map { it.icons.iconPack }.asLiveData()
|
val iconPack = dataStore.data.map { it.icons.iconPack }.asLiveData()
|
||||||
fun setIconPack(iconPack: String) {
|
fun setIconPack(iconPack: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import de.mm20.launcher2.database.entities.IconEntity
|
import de.mm20.launcher2.database.entities.IconEntity
|
||||||
import de.mm20.launcher2.database.entities.IconPackEntity
|
import de.mm20.launcher2.database.entities.IconPackEntity
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
internal val AppTypes = listOf("app", "calendar", "clock")
|
internal val AppTypes = listOf("app", "calendar", "clock")
|
||||||
|
|
||||||
@ -33,8 +34,8 @@ interface IconDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun installIconPack(iconPack: IconPackEntity)
|
fun installIconPack(iconPack: IconPackEntity)
|
||||||
|
|
||||||
@Query("SELECT * FROM IconPack")
|
@Query("SELECT * FROM IconPack ORDER BY name ASC")
|
||||||
suspend fun getInstalledIconPacks(): List<IconPackEntity>
|
fun getInstalledIconPacks(): Flow<List<IconPackEntity>>
|
||||||
|
|
||||||
@Query("SELECT * FROM IconPack WHERE packageName = :packageName LIMIT 1")
|
@Query("SELECT * FROM IconPack WHERE packageName = :packageName LIMIT 1")
|
||||||
suspend fun getIconPack(packageName: String): IconPackEntity?
|
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.isAtLeastApiLevel
|
||||||
import de.mm20.launcher2.ktx.randomElementOrNull
|
import de.mm20.launcher2.ktx.randomElementOrNull
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@ -33,11 +35,9 @@ class IconPackManager(
|
|||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val appDatabase: AppDatabase,
|
private val appDatabase: AppDatabase,
|
||||||
) {
|
) {
|
||||||
suspend fun getInstalledIconPacks(): List<IconPack> {
|
fun getInstalledIconPacks(): Flow<List<IconPack>> {
|
||||||
return withContext(Dispatchers.IO) {
|
return appDatabase.iconDao().getInstalledIconPacks().map {
|
||||||
appDatabase.iconDao().getInstalledIconPacks().map {
|
it.map { IconPack(it) }
|
||||||
IconPack(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,6 +375,7 @@ class IconPackManager(
|
|||||||
backgroundLayer = ColorLayer(),
|
backgroundLayer = ColorLayer(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
icon.themed -> {
|
icon.themed -> {
|
||||||
StaticLauncherIcon(
|
StaticLauncherIcon(
|
||||||
foregroundLayer = TintedClockLayer(
|
foregroundLayer = TintedClockLayer(
|
||||||
@ -387,6 +388,7 @@ class IconPackManager(
|
|||||||
backgroundLayer = ColorLayer(),
|
backgroundLayer = ColorLayer(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
drawable is AdaptiveIconDrawable -> {
|
drawable is AdaptiveIconDrawable -> {
|
||||||
StaticLauncherIcon(
|
StaticLauncherIcon(
|
||||||
foregroundLayer = ClockLayer(
|
foregroundLayer = ClockLayer(
|
||||||
@ -402,6 +404,7 @@ class IconPackManager(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
StaticLauncherIcon(
|
StaticLauncherIcon(
|
||||||
foregroundLayer = ClockLayer(
|
foregroundLayer = ClockLayer(
|
||||||
|
|||||||
@ -229,7 +229,7 @@ class IconRepository(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getInstalledIconPacks(): List<IconPack> {
|
fun getInstalledIconPacks(): Flow<List<IconPack>> {
|
||||||
return iconPackManager.getInstalledIconPacks()
|
return iconPackManager.getInstalledIconPacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user