Fixed infinite loading when there's no result
This commit is contained in:
@@ -20,7 +20,7 @@ android {
|
|||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 42
|
versionCode 42
|
||||||
versionName "4.6-beta3"
|
versionName "4.6-beta4"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6-beta3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6-beta4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||||
@@ -937,26 +937,26 @@ class MainActivity : AppCompatActivity() {
|
|||||||
when(sortMode) {
|
when(sortMode) {
|
||||||
SortMode.POPULAR -> getGalleryIDsFromNozomi(null, "popular", "all")
|
SortMode.POPULAR -> getGalleryIDsFromNozomi(null, "popular", "all")
|
||||||
else -> getGalleryIDsFromNozomi(null, "index", "all")
|
else -> getGalleryIDsFromNozomi(null, "index", "all")
|
||||||
}.apply {
|
}.also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> doSearch("$defaultQuery $query", sortMode == SortMode.POPULAR).apply {
|
else -> doSearch("$defaultQuery $query", sortMode == SortMode.POPULAR).also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode.HISTORY -> {
|
Mode.HISTORY -> {
|
||||||
when {
|
when {
|
||||||
query.isEmpty() -> {
|
query.isEmpty() -> {
|
||||||
histories.toList().apply {
|
histories.toList().also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val result = doSearch(query).sorted()
|
val result = doSearch(query).sorted()
|
||||||
histories.filter { result.binarySearch(it) >= 0 }.apply {
|
histories.filter { result.binarySearch(it) >= 0 }.also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -969,26 +969,26 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
query.isEmpty() -> downloads.apply {
|
query.isEmpty() -> downloads.also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val result = doSearch(query).sorted()
|
val result = doSearch(query).sorted()
|
||||||
downloads.filter { result.binarySearch(it) >= 0 }.apply {
|
downloads.filter { result.binarySearch(it) >= 0 }.also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode.FAVORITE -> {
|
Mode.FAVORITE -> {
|
||||||
when {
|
when {
|
||||||
query.isEmpty() -> favorites.toList().apply {
|
query.isEmpty() -> favorites.toList().also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val result = doSearch(query).sorted()
|
val result = doSearch(query).sorted()
|
||||||
favorites.filter { result.binarySearch(it) >= 0 }.apply {
|
favorites.filter { result.binarySearch(it) >= 0 }.also {
|
||||||
totalItems = size
|
totalItems = it.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1003,10 +1003,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
loadingJob = CoroutineScope(Dispatchers.IO).launch {
|
loadingJob = CoroutineScope(Dispatchers.IO).launch {
|
||||||
val galleryIDs = try {
|
val galleryIDs = try {
|
||||||
galleryIDs!!.await()
|
galleryIDs!!.await().also {
|
||||||
|
if (it.isEmpty())
|
||||||
|
throw Exception("No result")
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
||||||
if (Fabric.isInitialized())
|
if (Fabric.isInitialized() && e.message != "No result")
|
||||||
Crashlytics.logException(e)
|
Crashlytics.logException(e)
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
|||||||
@@ -187,14 +187,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
|||||||
queue.remove(galleryID)
|
queue.remove(galleryID)
|
||||||
worker[galleryID]?.cancel()
|
worker[galleryID]?.cancel()
|
||||||
|
|
||||||
clients[galleryID]?.dispatcher()?.queuedCalls()
|
clients[galleryID]?.dispatcher()?.cancelAll()
|
||||||
?.filter {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
(it.request().tag() as? Pair<Int, Int>)?.first == galleryID
|
|
||||||
}
|
|
||||||
?.forEach {
|
|
||||||
it.cancel()
|
|
||||||
}
|
|
||||||
clients.remove(galleryID)
|
clients.remove(galleryID)
|
||||||
|
|
||||||
progress.remove(galleryID)
|
progress.remove(galleryID)
|
||||||
@@ -283,7 +276,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
|||||||
for (i in reader.galleryInfo.indices) {
|
for (i in reader.galleryInfo.indices) {
|
||||||
val callback = object : Callback {
|
val callback = object : Callback {
|
||||||
override fun onFailure(call: Call, e: IOException) {
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
if (Fabric.isInitialized())
|
if (Fabric.isInitialized() && e.message != "Canceled")
|
||||||
Crashlytics.logException(e)
|
Crashlytics.logException(e)
|
||||||
|
|
||||||
progress[galleryID]?.set(i, Float.NaN)
|
progress[galleryID]?.set(i, Float.NaN)
|
||||||
|
|||||||
Reference in New Issue
Block a user