Update reader

pull/1/head
Koitharu 6 years ago
parent 64b38c561c
commit f64678d915

@ -1,14 +1,9 @@
package org.koitharu.kotatsu.ui.common package org.koitharu.kotatsu.ui.common
import android.os.Bundle
import android.view.View import android.view.View
abstract class BaseFullscreenActivity : BaseActivity() { abstract class BaseFullscreenActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onWindowFocusChanged(hasFocus: Boolean) { override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus) super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI() 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_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
} }
abstract fun onFullscreenModeChanged(isFullscreen: Boolean)
} }

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

@ -5,6 +5,7 @@ import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.dialog_chapters.* import kotlinx.android.synthetic.main.dialog_chapters.*
import org.koitharu.kotatsu.R 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.ui.details.ChaptersAdapter
import org.koitharu.kotatsu.utils.ext.withArgs 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) { override fun onBuildDialog(builder: AlertDialog.Builder) {
builder.setTitle(R.string.chapters) builder.setTitle(R.string.chapters)
@ -23,9 +25,25 @@ class ChaptersDialog : AlertDialogFragment(R.layout.dialog_chapters), OnRecycler
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 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 { recyclerView_chapters.adapter = ChaptersAdapter(this).apply {
arguments?.getParcelableArrayList<MangaChapter>(ARG_CHAPTERS)?.let(this::replaceData) 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 TAG = "ChaptersDialog"
private const val ARG_CHAPTERS = "chapters" private const val ARG_CHAPTERS = "chapters"
private const val ARG_CURRENT_ID = "current_id"
fun show(fm: FragmentManager, chapters: List<MangaChapter>) = ChaptersDialog() fun show(fm: FragmentManager, chapters: List<MangaChapter>, currentId: Long = 0L) =
.withArgs(1) { ChaptersDialog()
putParcelableArrayList(ARG_CHAPTERS, ArrayList(chapters)) .withArgs(2) {
}.show(fm, TAG) putParcelableArrayList(ARG_CHAPTERS, ArrayList(chapters))
putLong(ARG_CURRENT_ID, currentId)
}.show(fm, TAG)
} }
} }

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

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

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

Loading…
Cancel
Save