Refactor favorites and searchable database
This commit is contained in:
@@ -40,7 +40,7 @@ dependencies {
|
||||
|
||||
implementation(libs.koin.android)
|
||||
|
||||
implementation(project(":data:favorites"))
|
||||
implementation(project(":data:searchable"))
|
||||
implementation(project(":data:widgets"))
|
||||
implementation(project(":data:search-actions"))
|
||||
implementation(project(":core:preferences"))
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import de.mm20.launcher2.data.customattrs.CustomAttributesRepository
|
||||
import de.mm20.launcher2.favorites.FavoritesRepository
|
||||
import de.mm20.launcher2.searchable.SearchableRepository
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import de.mm20.launcher2.preferences.export
|
||||
import de.mm20.launcher2.preferences.import
|
||||
@@ -21,7 +21,7 @@ import java.util.zip.ZipOutputStream
|
||||
class BackupManager(
|
||||
private val context: Context,
|
||||
private val dataStore: LauncherDataStore,
|
||||
private val favoritesRepository: FavoritesRepository,
|
||||
private val searchableRepository: SearchableRepository,
|
||||
private val widgetRepository: WidgetRepository,
|
||||
private val searchActionRepository: SearchActionRepository,
|
||||
private val customAttrsRepository: CustomAttributesRepository,
|
||||
@@ -63,7 +63,7 @@ class BackupManager(
|
||||
}
|
||||
|
||||
if (include.contains(BackupComponent.Favorites)) {
|
||||
favoritesRepository.export(backupDir)
|
||||
searchableRepository.export(backupDir)
|
||||
}
|
||||
|
||||
if (include.contains(BackupComponent.Widgets)) {
|
||||
@@ -104,7 +104,7 @@ class BackupManager(
|
||||
}
|
||||
|
||||
if (include.contains(BackupComponent.Favorites)) {
|
||||
favoritesRepository.import(restoreDir)
|
||||
searchableRepository.import(restoreDir)
|
||||
}
|
||||
|
||||
if (include.contains(BackupComponent.Widgets)) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,46 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
id("kotlin-android")
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = sdk.versions.compileSdk.get().toInt()
|
||||
|
||||
defaultConfig {
|
||||
minSdk = sdk.versions.minSdk.get().toInt()
|
||||
targetSdk = sdk.versions.targetSdk.get().toInt()
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
namespace = "de.mm20.launcher2.services.favorites"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.bundles.kotlin)
|
||||
implementation(libs.androidx.core)
|
||||
implementation(libs.koin.android)
|
||||
|
||||
implementation(project(":core:base"))
|
||||
implementation(project(":core:i18n"))
|
||||
implementation(project(":data:searchable"))
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package de.mm20.launcher2.services.favorites
|
||||
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.searchable.SearchableRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class FavoritesService(
|
||||
val searchableRepository: SearchableRepository,
|
||||
) {
|
||||
|
||||
|
||||
fun getFavorites(
|
||||
includeTypes: List<String>? = null,
|
||||
excludeTypes: List<String>? = null,
|
||||
manuallySorted: Boolean = false,
|
||||
automaticallySorted: Boolean = false,
|
||||
frequentlyUsed: Boolean = false,
|
||||
limit: Int = 100,
|
||||
): Flow<List<SavableSearchable>> {
|
||||
return searchableRepository.get(
|
||||
hidden = false,
|
||||
includeTypes = includeTypes,
|
||||
excludeTypes = excludeTypes,
|
||||
manuallySorted = manuallySorted,
|
||||
automaticallySorted = automaticallySorted,
|
||||
frequentlyUsed = frequentlyUsed,
|
||||
limit = limit,
|
||||
)
|
||||
}
|
||||
fun isPinned(searchable: SavableSearchable): Flow<Boolean> {
|
||||
return searchableRepository.isPinned(searchable)
|
||||
}
|
||||
|
||||
fun pinItem(searchable: SavableSearchable) {
|
||||
searchableRepository.upsert(
|
||||
searchable,
|
||||
pinned = true,
|
||||
hidden = false,
|
||||
)
|
||||
}
|
||||
|
||||
fun reset(searchable: SavableSearchable) {
|
||||
searchableRepository.update(
|
||||
searchable,
|
||||
pinned = false,
|
||||
hidden = false,
|
||||
weight = 0.0,
|
||||
launchCount = 0,
|
||||
)
|
||||
}
|
||||
|
||||
fun unpinItem(searchable: SavableSearchable) {
|
||||
searchableRepository.upsert(
|
||||
searchable,
|
||||
pinned = false,
|
||||
)
|
||||
}
|
||||
|
||||
fun reportLaunch(searchable: SavableSearchable) {
|
||||
searchableRepository.touch(searchable)
|
||||
}
|
||||
|
||||
fun updateFavorites(
|
||||
manuallySorted: List<SavableSearchable>,
|
||||
automaticallySorted: List<SavableSearchable>
|
||||
) {
|
||||
searchableRepository.updateFavorites(
|
||||
manuallySorted = manuallySorted,
|
||||
automaticallySorted = automaticallySorted
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.mm20.launcher2.services.favorites
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val favoritesModule = module {
|
||||
factory { FavoritesService(get()) }
|
||||
}
|
||||
@@ -48,6 +48,6 @@ dependencies {
|
||||
implementation(project(":core:ktx"))
|
||||
implementation(project(":core:crashreporter"))
|
||||
implementation(project(":data:customattrs"))
|
||||
implementation(project(":data:favorites"))
|
||||
implementation(project(":data:searchable"))
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.mm20.launcher2.services.tags.impl
|
||||
|
||||
import de.mm20.launcher2.data.customattrs.CustomAttributesRepository
|
||||
import de.mm20.launcher2.favorites.FavoritesRepository
|
||||
import de.mm20.launcher2.searchable.SearchableRepository
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.data.Tag
|
||||
import de.mm20.launcher2.services.tags.TagsService
|
||||
@@ -14,7 +14,7 @@ import kotlinx.coroutines.launch
|
||||
|
||||
internal class TagsServiceImpl(
|
||||
private val customAttributesRepository: CustomAttributesRepository,
|
||||
private val favoritesRepository: FavoritesRepository,
|
||||
private val searchableRepository: SearchableRepository,
|
||||
) : TagsService {
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||
override fun getAllTags(startsWith: String?): Flow<List<String>> {
|
||||
@@ -22,7 +22,7 @@ internal class TagsServiceImpl(
|
||||
}
|
||||
|
||||
override fun deleteTag(tag: String) {
|
||||
favoritesRepository.remove(Tag(tag))
|
||||
searchableRepository.delete(Tag(tag))
|
||||
customAttributesRepository.deleteTag(tag)
|
||||
}
|
||||
|
||||
@@ -44,15 +44,15 @@ internal class TagsServiceImpl(
|
||||
}
|
||||
if (newName != null && newName != tag) {
|
||||
customAttributesRepository.renameTag(tag, newName).join()
|
||||
val pinnedTags = favoritesRepository.getFavorites(
|
||||
val pinnedTags = searchableRepository.get(
|
||||
includeTypes = listOf(Tag.Domain),
|
||||
manuallySorted = true,
|
||||
automaticallySorted = true
|
||||
).first()
|
||||
val oldTag = Tag(tag)
|
||||
if (pinnedTags.any { it.key == oldTag.key }) {
|
||||
favoritesRepository.unpinItem(oldTag)
|
||||
favoritesRepository.pinItem(Tag(newName))
|
||||
searchableRepository.update(oldTag, pinned = false)
|
||||
searchableRepository.update(Tag(newName), pinned = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user