Reading progress indicator on details screen

This commit is contained in:
Koitharu
2022-06-28 12:10:39 +03:00
parent 04dd8003f7
commit f2ea1cde46
5 changed files with 26 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ import org.koitharu.kotatsu.bookmarks.ui.BookmarksAdapter
import org.koitharu.kotatsu.core.model.MangaHistory
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteCategoriesBottomSheet
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import org.koitharu.kotatsu.image.ui.ImageActivity
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaSource
@@ -176,6 +177,7 @@ class DetailsFragment :
setIconResource(R.drawable.ic_play)
}
}
binding.progressView.setPercent(history?.percent ?: PROGRESS_NONE, animate = true)
}
private fun onFavouriteChanged(isFavourite: Boolean) {

View File

@@ -7,7 +7,6 @@ import androidx.annotation.StyleRes
import androidx.core.graphics.ColorUtils
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import kotlin.math.roundToInt
class ReadingProgressDrawable(
context: Context,
@@ -31,7 +30,7 @@ class ReadingProgressDrawable(
var progress: Float = PROGRESS_NONE
set(value) {
field = value
text = textPattern.format((value * 100f).roundToInt().toString())
text = textPattern.format((value * 100f).toInt().toString())
paint.getTextBounds(text, 0, text.length, textBounds)
invalidateSelf()
}

View File

@@ -20,6 +20,7 @@ import org.koitharu.kotatsu.core.os.ShortcutsRepository
import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.prefs.*
import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.model.MangaPage
@@ -144,7 +145,7 @@ class ReaderViewModel(
historyRepository.saveStateAsync(
manga = mangaData.value ?: return,
state = readerState,
percent = computePercent(readerState.chapterId, readerState.page)
percent = computePercent(readerState.chapterId, readerState.page),
)
}
@@ -371,17 +372,17 @@ class ReaderViewModel(
}
private fun computePercent(chapterId: Long, pageIndex: Int): Float {
val chapters = manga?.chapters ?: return -1f
val chapters = manga?.chapters ?: return PROGRESS_NONE
val chaptersCount = chapters.size
val chapterIndex = chapters.indexOfFirst { x -> x.id == chapterId }
val pages = content.value?.pages ?: return -1f
val pages = content.value?.pages ?: return PROGRESS_NONE
val pagesCount = pages.count { x -> x.chapterId == chapterId }
if (chaptersCount == 0 || pagesCount == 0) {
return -1f
return PROGRESS_NONE
}
val chapterPercent = (chapterIndex + 1) / chaptersCount.toFloat()
val pagePercent = (pageIndex + 1) / pagesCount.toFloat()
return pagePercent * chapterPercent // FIXME
val ppc = 1f / chaptersCount
return ppc * chapterIndex + ppc * pagePercent
}
}

View File

@@ -31,6 +31,14 @@
tools:background="@tools:sample/backgrounds/scenic"
tools:ignore="ContentDescription,UnusedAttribute" />
<org.koitharu.kotatsu.history.ui.util.ReadingProgressView
android:id="@+id/progressView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="4dp"
app:layout_constraintBottom_toBottomOf="@id/imageView_cover"
app:layout_constraintEnd_toEndOf="@id/imageView_cover" />
<LinearLayout
android:id="@+id/layout_titles"
android:layout_width="0dp"

View File

@@ -31,6 +31,14 @@
tools:background="@tools:sample/backgrounds/scenic"
tools:ignore="ContentDescription,UnusedAttribute" />
<org.koitharu.kotatsu.history.ui.util.ReadingProgressView
android:id="@+id/progressView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="4dp"
app:layout_constraintBottom_toBottomOf="@id/imageView_cover"
app:layout_constraintEnd_toEndOf="@id/imageView_cover" />
<TextView
android:id="@+id/textView_title"
android:layout_width="0dp"