Fix empty chapters label
This commit is contained in:
@@ -9,7 +9,6 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updatePadding
|
||||
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||
@@ -67,8 +66,8 @@ class ChaptersFragment :
|
||||
viewModel.isChaptersReversed.observe(viewLifecycleOwner) {
|
||||
activity?.invalidateOptionsMenu()
|
||||
}
|
||||
viewModel.hasChapters.observe(viewLifecycleOwner) {
|
||||
binding.textViewHolder.isGone = it
|
||||
viewModel.isChaptersEmpty.observe(viewLifecycleOwner) {
|
||||
binding.textViewHolder.isVisible = it
|
||||
activity?.invalidateOptionsMenu()
|
||||
}
|
||||
}
|
||||
@@ -94,7 +93,7 @@ class ChaptersFragment :
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
menu.findItem(R.id.action_reversed).isChecked = viewModel.isChaptersReversed.value == true
|
||||
menu.findItem(R.id.action_search).isVisible = viewModel.hasChapters.value == true
|
||||
menu.findItem(R.id.action_search).isVisible = viewModel.isChaptersEmpty.value == false
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import androidx.core.os.LocaleListCompat
|
||||
import androidx.lifecycle.asFlow
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import java.io.IOException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.*
|
||||
@@ -29,7 +28,9 @@ import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||
import org.koitharu.kotatsu.utils.ext.iterator
|
||||
import java.io.IOException
|
||||
|
||||
class DetailsViewModel(
|
||||
private val intent: MangaIntent,
|
||||
@@ -89,18 +90,18 @@ class DetailsViewModel(
|
||||
|
||||
val branches = mangaData.map {
|
||||
it?.chapters?.mapToSet { x -> x.branch }?.sortedBy { x -> x }.orEmpty()
|
||||
}.asLiveData(viewModelScope.coroutineContext + Dispatchers.Default)
|
||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default)
|
||||
|
||||
val selectedBranchIndex = combine(
|
||||
branches.asFlow(),
|
||||
selectedBranch
|
||||
) { branches, selected ->
|
||||
branches.indexOf(selected)
|
||||
}.asLiveData(viewModelScope.coroutineContext + Dispatchers.Default)
|
||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default)
|
||||
|
||||
val hasChapters = mangaData.map {
|
||||
!(it?.chapters.isNullOrEmpty())
|
||||
}.asLiveData(viewModelScope.coroutineContext + Dispatchers.Default)
|
||||
val isChaptersEmpty = mangaData.mapNotNull { m ->
|
||||
m?.run { chapters.isNullOrEmpty() }
|
||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
||||
|
||||
val chapters = combine(
|
||||
combine(
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.koitharu.kotatsu.utils
|
||||
|
||||
import androidx.annotation.MainThread
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Runnable
|
||||
|
||||
class PausingDispatcher(
|
||||
private val dispatcher: CoroutineDispatcher,
|
||||
) : CoroutineDispatcher() {
|
||||
|
||||
@Volatile
|
||||
private var isPaused = false
|
||||
private val queue = ConcurrentLinkedQueue<Task>()
|
||||
|
||||
override fun isDispatchNeeded(context: CoroutineContext): Boolean {
|
||||
return isPaused || super.isDispatchNeeded(context)
|
||||
}
|
||||
|
||||
override fun dispatch(context: CoroutineContext, block: Runnable) {
|
||||
if (isPaused) {
|
||||
queue.add(Task(context, block))
|
||||
} else {
|
||||
dispatcher.dispatch(context, block)
|
||||
}
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun pause() {
|
||||
isPaused = true
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun resume() {
|
||||
if (!isPaused) {
|
||||
return
|
||||
}
|
||||
isPaused = false
|
||||
while (true) {
|
||||
val task = queue.poll() ?: break
|
||||
dispatcher.dispatch(task.context, task.block)
|
||||
}
|
||||
}
|
||||
|
||||
private class Task(
|
||||
val context: CoroutineContext,
|
||||
val block: Runnable,
|
||||
)
|
||||
}
|
||||
12
app/src/main/res/drawable/ic_pause.xml
Normal file
12
app/src/main/res/drawable/ic_pause.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M14,19H18V5H14M6,19H10V5H6V19Z" />
|
||||
</vector>
|
||||
12
app/src/main/res/drawable/ic_resume.xml
Normal file
12
app/src/main/res/drawable/ic_resume.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M8,5.14V19.14L19,12.14L8,5.14Z" />
|
||||
</vector>
|
||||
18
app/src/main/res/menu/opt_downloads.xml
Normal file
18
app/src/main/res/menu/opt_downloads.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:icon="@drawable/ic_pause"
|
||||
android:id="@+id/action_pause"
|
||||
android:title="Pause"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
|
||||
<item
|
||||
android:icon="@drawable/ic_resume"
|
||||
android:id="@+id/action_resume"
|
||||
android:title="Resume"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user