Reorganize Searchable data types
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package de.mm20.launcher2.search
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.ktx.romanize
|
||||
import java.text.Collator
|
||||
|
||||
interface PinnableSearchable : Searchable, Comparable<PinnableSearchable> {
|
||||
|
||||
val label: String
|
||||
val labelOverride: String?
|
||||
get() = null
|
||||
|
||||
fun overrideLabel(label: String): PinnableSearchable
|
||||
|
||||
fun launch(context: Context, options: Bundle?): Boolean
|
||||
|
||||
/**
|
||||
* If this is true, tapping the item will open the details popup instead of launching it
|
||||
*/
|
||||
val preferDetailsOverLaunch: Boolean
|
||||
|
||||
fun getPlaceholderIcon(context: Context): StaticLauncherIcon
|
||||
|
||||
suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
themed: Boolean
|
||||
): LauncherIcon? = null
|
||||
|
||||
|
||||
override fun compareTo(other: PinnableSearchable): Int {
|
||||
val label1 = labelOverride ?: label
|
||||
val label2 = other.labelOverride ?: other.label
|
||||
return Collator.getInstance().apply { strength = Collator.SECONDARY }
|
||||
.compare(label1.romanize(), label2.romanize())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package de.mm20.launcher2.search
|
||||
|
||||
interface Searchable {
|
||||
val domain: String
|
||||
val key: String
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.mm20.launcher2.search
|
||||
|
||||
interface SearchableDeserializer {
|
||||
fun deserialize(serialized: String): PinnableSearchable?
|
||||
}
|
||||
|
||||
class NullDeserializer: SearchableDeserializer {
|
||||
override fun deserialize(serialized: String): PinnableSearchable? {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.mm20.launcher2.search
|
||||
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface SearchableRepository<T: Searchable> {
|
||||
fun search(query: String): Flow<ImmutableList<T>>
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.mm20.launcher2.search
|
||||
|
||||
interface SearchableSerializer {
|
||||
fun serialize(searchable: PinnableSearchable): String?
|
||||
val typePrefix: String
|
||||
}
|
||||
|
||||
class NullSerializer : SearchableSerializer {
|
||||
override fun serialize(searchable: PinnableSearchable): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
override val typePrefix: String
|
||||
get() = "null"
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user