Update reader

This commit is contained in:
Koitharu
2020-02-04 17:14:15 +02:00
parent 64b38c561c
commit f64678d915
6 changed files with 45 additions and 24 deletions

View File

@@ -1,14 +1,9 @@
package org.koitharu.kotatsu.ui.common
import android.os.Bundle
import android.view.View
abstract class BaseFullscreenActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI()
@@ -28,6 +23,4 @@ abstract class BaseFullscreenActivity : BaseActivity() {
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
}
abstract fun onFullscreenModeChanged(isFullscreen: Boolean)
}

View File

@@ -16,7 +16,8 @@ class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChap
updateCurrentPosition()
}
private var currentChapterPosition = RecyclerView.NO_POSITION
var currentChapterPosition = RecyclerView.NO_POSITION
private set
override fun onCreateViewHolder(parent: ViewGroup) = ChapterHolder(parent)

View File

@@ -5,6 +5,7 @@ import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.dialog_chapters.*
import org.koitharu.kotatsu.R
@@ -14,7 +15,8 @@ import org.koitharu.kotatsu.ui.common.list.OnRecyclerItemClickListener
import org.koitharu.kotatsu.ui.details.ChaptersAdapter
import org.koitharu.kotatsu.utils.ext.withArgs
class ChaptersDialog : AlertDialogFragment(R.layout.dialog_chapters), OnRecyclerItemClickListener<MangaChapter> {
class ChaptersDialog : AlertDialogFragment(R.layout.dialog_chapters),
OnRecyclerItemClickListener<MangaChapter> {
override fun onBuildDialog(builder: AlertDialog.Builder) {
builder.setTitle(R.string.chapters)
@@ -23,9 +25,25 @@ class ChaptersDialog : AlertDialogFragment(R.layout.dialog_chapters), OnRecycler
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
recyclerView_chapters.addItemDecoration(DividerItemDecoration(requireContext(), RecyclerView.VERTICAL))
recyclerView_chapters.addItemDecoration(
DividerItemDecoration(
requireContext(),
RecyclerView.VERTICAL
)
)
recyclerView_chapters.adapter = ChaptersAdapter(this).apply {
arguments?.getParcelableArrayList<MangaChapter>(ARG_CHAPTERS)?.let(this::replaceData)
currentChapterId = arguments?.getLong(ARG_CURRENT_ID, 0L)?.takeUnless { it == 0L }
}
}
override fun onResume() {
super.onResume()
val pos = (recyclerView_chapters.adapter as? ChaptersAdapter)?.currentChapterPosition
?: RecyclerView.NO_POSITION
if (pos != RecyclerView.NO_POSITION) {
(recyclerView_chapters.layoutManager as? LinearLayoutManager)
?.scrollToPositionWithOffset(pos, 100)
}
}
@@ -38,10 +56,13 @@ class ChaptersDialog : AlertDialogFragment(R.layout.dialog_chapters), OnRecycler
private const val TAG = "ChaptersDialog"
private const val ARG_CHAPTERS = "chapters"
private const val ARG_CURRENT_ID = "current_id"
fun show(fm: FragmentManager, chapters: List<MangaChapter>) = ChaptersDialog()
.withArgs(1) {
putParcelableArrayList(ARG_CHAPTERS, ArrayList(chapters))
}.show(fm, TAG)
fun show(fm: FragmentManager, chapters: List<MangaChapter>, currentId: Long = 0L) =
ChaptersDialog()
.withArgs(2) {
putParcelableArrayList(ARG_CHAPTERS, ArrayList(chapters))
putLong(ARG_CURRENT_ID, currentId)
}.show(fm, TAG)
}
}

View File

@@ -23,23 +23,23 @@ class PageHolder(parent: ViewGroup, private val loader: PageLoader) : BaseViewHo
override fun onBind(data: MangaPage, extra: Unit) {
layout_error.isVisible = false
progressBar.show()
progressBar.isVisible = true
ssiv.recycle()
loader.load(data.url) {
ssiv.setImage(ImageSource.uri(it.toUri()))
}
}
override fun onReady() {
progressBar.hide()
}
override fun onReady() = Unit
override fun onImageLoadError(e: Exception) {
textView_error.text = e.getDisplayMessage(context.resources)
layout_error.isVisible = true
}
override fun onImageLoaded() = Unit
override fun onImageLoaded() {
progressBar.isVisible = false
}
override fun onTileLoadError(e: Exception?) = Unit

View File

@@ -76,7 +76,7 @@ class ReaderActivity : BaseFullscreenActivity(), ReaderView {
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
R.id.action_chapters -> {
ChaptersDialog.show(supportFragmentManager, state.manga.chapters.orEmpty())
ChaptersDialog.show(supportFragmentManager, state.manga.chapters.orEmpty(), state.chapterId)
true
}
else -> super.onOptionsItemSelected(item)
@@ -99,9 +99,15 @@ class ReaderActivity : BaseFullscreenActivity(), ReaderView {
}
}
override fun onFullscreenModeChanged(isFullscreen: Boolean) {
appbar_top.isGone = isFullscreen
appbar_bottom.isGone = isFullscreen
private fun onTapCenter() {
if (appbar_top.isVisible) {
appbar_top.isGone = false
appbar_bottom.isGone = false
} else {
appbar_top.isGone = true
appbar_bottom.isGone = true
showSystemUI()
}
}
companion object {

View File

@@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<androidx.core.widget.ContentLoadingProgressBar
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"