Restructure contacts search for plugins
This commit is contained in:
@@ -3,6 +3,7 @@ package de.mm20.launcher2.preferences
|
||||
import android.content.Context
|
||||
import de.mm20.launcher2.preferences.migrations.Migration2
|
||||
import de.mm20.launcher2.preferences.migrations.Migration3
|
||||
import de.mm20.launcher2.preferences.migrations.Migration4
|
||||
import de.mm20.launcher2.settings.BaseSettings
|
||||
|
||||
internal class LauncherDataStore(
|
||||
@@ -14,6 +15,7 @@ internal class LauncherDataStore(
|
||||
migrations = listOf(
|
||||
Migration2(),
|
||||
Migration3(),
|
||||
Migration4(),
|
||||
),
|
||||
) {
|
||||
|
||||
|
||||
@@ -52,7 +52,9 @@ data class LauncherSettingsData internal constructor(
|
||||
|
||||
val fileSearchProviders: Set<String> = setOf("local"),
|
||||
|
||||
@Deprecated("Use contactSearchProviders `local` instead")
|
||||
val contactSearchEnabled: Boolean = true,
|
||||
val contactSearchProviders: Set<String> = setOf("local"),
|
||||
val contactSearchCallOnTap: Boolean = false,
|
||||
|
||||
@Deprecated("Use calendarSearchProviders `local` instead")
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package de.mm20.launcher2.preferences.migrations
|
||||
|
||||
import androidx.datastore.core.DataMigration
|
||||
import de.mm20.launcher2.preferences.LauncherSettingsData
|
||||
|
||||
class Migration4 : DataMigration<LauncherSettingsData> {
|
||||
override suspend fun cleanUp() {
|
||||
}
|
||||
|
||||
override suspend fun migrate(currentData: LauncherSettingsData): LauncherSettingsData {
|
||||
return currentData.copy(
|
||||
schemaVersion = 4,
|
||||
contactSearchProviders = setOfNotNull(
|
||||
if (currentData.contactSearchEnabled) "local" else null,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun shouldMigrate(currentData: LauncherSettingsData): Boolean {
|
||||
return currentData.schemaVersion < 4
|
||||
}
|
||||
|
||||
}
|
||||
+13
-4
@@ -6,11 +6,20 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class ContactSearchSettings internal constructor(private val dataStore: LauncherDataStore) {
|
||||
val enabled: Flow<Boolean>
|
||||
get() = dataStore.data.map { it.contactSearchEnabled }.distinctUntilChanged()
|
||||
|
||||
fun setEnabled(enabled: Boolean) {
|
||||
dataStore.update { it.copy(contactSearchEnabled = enabled) }
|
||||
val enabledProviders: Flow<Set<String>>
|
||||
get() = dataStore.data.map { it.contactSearchProviders }.distinctUntilChanged()
|
||||
|
||||
fun isProviderEnabled(provider: String) = dataStore.data.map { it.contactSearchProviders.contains(provider) }
|
||||
|
||||
fun setProviderEnabled(provider: String, enabled: Boolean) {
|
||||
dataStore.update {
|
||||
if (enabled) {
|
||||
it.copy(contactSearchProviders = it.contactSearchProviders + provider)
|
||||
} else {
|
||||
it.copy(contactSearchProviders = it.contactSearchProviders - provider)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val callOnTap: Flow<Boolean>
|
||||
|
||||
Reference in New Issue
Block a user