UI update

Added sort by popularity functionality
Added auto update
This commit is contained in:
tom5079
2019-07-07 15:21:56 +09:00
parent dca6ba457b
commit 1eb75acb40
28 changed files with 506 additions and 363 deletions

View File

@@ -16,13 +16,13 @@
package xyz.quaver.hitomi
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import java.util.*
import java.util.concurrent.Executors
fun doSearch(query: String) : List<Int> {
val time = System.currentTimeMillis()
fun doSearch(query: String, sortByPopularity: Boolean = false) : List<Int> {
val terms = query
.trim()
.replace(Regex("""^\?"""), "")
@@ -42,7 +42,20 @@ fun doSearch(query: String) : List<Int> {
positiveTerms.push(term)
}
val positiveResults = positiveTerms.map {
CoroutineScope(Dispatchers.IO).async {
getGalleryIDsForQuery(it)
}
}
val negativeResults = negativeTerms.map {
CoroutineScope(Dispatchers.IO).async {
getGalleryIDsForQuery(it)
}
}
var results = when {
sortByPopularity -> getGalleryIDsFromNozomi(null, "popular", "all")
positiveTerms.isEmpty() -> getGalleryIDsFromNozomi(null, "index", "all")
else -> getGalleryIDsForQuery(positiveTerms.poll())
}
@@ -57,25 +70,19 @@ fun doSearch(query: String) : List<Int> {
}
//positive results
positiveTerms.map {
async(Dispatchers.IO) {
Pair(getGalleryIDsForQuery(it), true)
}
}+negativeTerms.map {
async(Dispatchers.IO) {
Pair(getGalleryIDsForQuery(it), false)
}
}.forEach {
val (result, isPositive) = it.await()
positiveResults.forEach {
val result = it.await()
when {
isPositive -> filterPositive(result.sorted())
else -> filterNegative(result.sorted())
}
filterPositive(result.sorted())
}
//negative results
negativeResults.forEach {
val result = it.await()
filterNegative(result.sorted())
}
}
println("PUPIL/SEARCH TIME ${System.currentTimeMillis() - time}ms")
return results
}

View File

@@ -16,6 +16,7 @@
package xyz.quaver.hitomi
import java.io.ByteArrayOutputStream
import java.net.URL
import java.nio.ByteBuffer
import java.nio.ByteOrder
@@ -179,8 +180,10 @@ fun getGalleryIDsFromNozomi(area: String?, tag: String, language: String) : List
val nozomi = ArrayList<Int>()
val bytes = inputStream.readBytes()
val arrayBuffer = ByteBuffer
.wrap(inputStream.readBytes())
.wrap(bytes)
.order(ByteOrder.BIG_ENDIAN)
while (arrayBuffer.hasRemaining())

View File

@@ -19,9 +19,6 @@
package xyz.quaver.hitomi
import org.junit.Test
import java.net.InetAddress
import java.net.UnknownHostException
class UnitTest {
@Test
@@ -31,9 +28,9 @@ class UnitTest {
@Test
fun test_nozomi() {
val nozomi = fetchNozomi(start = 0, count = 5)
val nozomi = getGalleryIDsFromNozomi(null, "popular", "all")
nozomi.first
print(nozomi.size)
}
@Test
@@ -52,7 +49,7 @@ class UnitTest {
@Test
fun test_doSearch() {
val r = doSearch("female:loli female:bondage language:korean -male:yaoi -male:guro -female:guro")
val r = doSearch("female:loli female:bondage language:korean -male:yaoi -male:guro -female:guro", true)
print(r.size)
}