Refactor favorites and searchable database
This commit is contained in:
@@ -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()) }
|
||||
}
|
||||
Reference in New Issue
Block a user