Configure search suggestions
parent
19da2267d6
commit
73e768def0
@ -0,0 +1,15 @@
|
||||
package org.koitharu.kotatsu.core.prefs
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.R
|
||||
|
||||
enum class SearchSuggestionType(
|
||||
@StringRes val titleResId: Int,
|
||||
) {
|
||||
|
||||
GENRES(R.string.genres),
|
||||
QUERIES_RECENT(R.string.recent_queries),
|
||||
QUERIES_SUGGEST(R.string.suggested_queries),
|
||||
MANGA(R.string.content_type_manga),
|
||||
SOURCES(R.string.remote_sources),
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
package org.koitharu.kotatsu.core.util
|
||||
|
||||
import androidx.collection.ArrayMap
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
@Deprecated("", replaceWith = ReplaceWith("CompositeMutex2"))
|
||||
class CompositeMutex<T : Any> : Set<T> {
|
||||
|
||||
private val state = ArrayMap<T, MutableStateFlow<Boolean>>()
|
||||
private val mutex = Mutex()
|
||||
|
||||
override val size: Int
|
||||
get() = state.size
|
||||
|
||||
override fun contains(element: T): Boolean {
|
||||
return state.containsKey(element)
|
||||
}
|
||||
|
||||
override fun containsAll(elements: Collection<T>): Boolean {
|
||||
return elements.all { x -> state.containsKey(x) }
|
||||
}
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
return state.isEmpty()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
return state.keys.iterator()
|
||||
}
|
||||
|
||||
suspend fun lock(element: T) {
|
||||
while (coroutineContext.isActive) {
|
||||
waitForRemoval(element)
|
||||
mutex.withLock {
|
||||
if (state[element] == null) {
|
||||
state[element] = MutableStateFlow(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun unlock(element: T) {
|
||||
checkNotNull(state.remove(element)) {
|
||||
"CompositeMutex is not locked for $element"
|
||||
}.value = true
|
||||
}
|
||||
|
||||
private suspend fun waitForRemoval(element: T) {
|
||||
val flow = state[element] ?: return
|
||||
flow.first { it }
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package org.koitharu.kotatsu.core.util
|
||||
|
||||
class CompositeRunnable(
|
||||
private val children: List<Runnable>,
|
||||
) : Runnable, Collection<Runnable> by children {
|
||||
|
||||
override fun run() {
|
||||
for (child in children) {
|
||||
child.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package org.koitharu.kotatsu.core.util.ext
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.text.StaticLayout
|
||||
import androidx.core.graphics.withTranslation
|
||||
|
||||
fun StaticLayout.draw(canvas: Canvas, x: Float, y: Float) {
|
||||
canvas.withTranslation(x, y) {
|
||||
draw(this)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue