Current branch indicator

master
Koitharu 2 years ago
parent c5d88f8700
commit 59bfa929fd
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -4,7 +4,9 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.text.style.DynamicDrawableSpan
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.ImageSpan
import android.text.style.RelativeSizeSpan import android.text.style.RelativeSizeSpan
import android.transition.AutoTransition import android.transition.AutoTransition
import android.transition.Slide import android.transition.Slide
@ -318,6 +320,18 @@ class DetailsActivity :
val branches = viewModel.branches.value val branches = viewModel.branches.value
for ((i, branch) in branches.withIndex()) { for ((i, branch) in branches.withIndex()) {
val title = buildSpannedString { val title = buildSpannedString {
if (branch.isCurrent) {
inSpans(
ImageSpan(
this@DetailsActivity,
R.drawable.ic_current_chapter,
DynamicDrawableSpan.ALIGN_BASELINE,
),
) {
append(' ')
}
append(' ')
}
append(branch.name ?: getString(R.string.system_default)) append(branch.name ?: getString(R.string.system_default))
append(' ') append(' ')
append(' ') append(' ')

@ -25,6 +25,7 @@ import okio.FileNotFoundException
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.bookmarks.domain.Bookmark import org.koitharu.kotatsu.bookmarks.domain.Bookmark
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
import org.koitharu.kotatsu.core.model.findById
import org.koitharu.kotatsu.core.model.getPreferredBranch import org.koitharu.kotatsu.core.model.getPreferredBranch
import org.koitharu.kotatsu.core.parser.MangaIntent import org.koitharu.kotatsu.core.parser.MangaIntent
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
@ -171,10 +172,21 @@ class DetailsViewModel @Inject constructor(
val branches: StateFlow<List<MangaBranch>> = combine( val branches: StateFlow<List<MangaBranch>> = combine(
details, details,
selectedBranch, selectedBranch,
) { m, b -> history,
(m?.chapters ?: return@combine emptyList()) ) { m, b, h ->
.map { x -> MangaBranch(x.key, x.value.size, x.key == b) } val c = m?.chapters
.sortedWith(BranchComparator()) if (c.isNullOrEmpty()) {
return@combine emptyList()
}
val currentBranch = h?.let { m.allChapters.findById(it.chapterId) }?.branch
c.map { x ->
MangaBranch(
name = x.key,
count = x.value.size,
isSelected = x.key == b,
isCurrent = h != null && x.key == currentBranch,
)
}.sortedWith(BranchComparator())
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, emptyList()) }.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, emptyList())
val isChaptersEmpty: StateFlow<Boolean> = details.map { val isChaptersEmpty: StateFlow<Boolean> = details.map {

@ -7,6 +7,7 @@ data class MangaBranch(
val name: String?, val name: String?,
val count: Int, val count: Int,
val isSelected: Boolean, val isSelected: Boolean,
val isCurrent: Boolean,
) : ListModel { ) : ListModel {
override fun areItemsTheSame(other: ListModel): Boolean { override fun areItemsTheSame(other: ListModel): Boolean {

Loading…
Cancel
Save