|
|
|
@ -5,11 +5,13 @@ import android.content.Intent
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
|
|
|
import android.widget.Toast
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import kotlinx.android.synthetic.main.activity_reader.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_reader.*
|
|
|
|
import moxy.ktx.moxyPresenter
|
|
|
|
import moxy.ktx.moxyPresenter
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.model.Manga
|
|
|
|
import org.koitharu.kotatsu.core.model.Manga
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
|
|
|
import org.koitharu.kotatsu.core.model.MangaPage
|
|
|
|
import org.koitharu.kotatsu.core.model.MangaPage
|
|
|
|
import org.koitharu.kotatsu.ui.common.BaseActivity
|
|
|
|
import org.koitharu.kotatsu.ui.common.BaseActivity
|
|
|
|
import org.koitharu.kotatsu.utils.ext.showDialog
|
|
|
|
import org.koitharu.kotatsu.utils.ext.showDialog
|
|
|
|
@ -18,12 +20,7 @@ class ReaderActivity : BaseActivity(), ReaderView {
|
|
|
|
|
|
|
|
|
|
|
|
private val presenter by moxyPresenter { ReaderPresenter() }
|
|
|
|
private val presenter by moxyPresenter { ReaderPresenter() }
|
|
|
|
|
|
|
|
|
|
|
|
private val manga by lazy(LazyThreadSafetyMode.NONE) {
|
|
|
|
private lateinit var state: ReaderState
|
|
|
|
intent.getParcelableExtra<Manga>(EXTRA_MANGA)!!
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private val chapterId by lazy(LazyThreadSafetyMode.NONE) {
|
|
|
|
|
|
|
|
intent.getLongExtra(EXTRA_CHAPTER_ID, 0L)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var loader: PageLoader
|
|
|
|
private lateinit var loader: PageLoader
|
|
|
|
private lateinit var adapter: PagesAdapter
|
|
|
|
private lateinit var adapter: PagesAdapter
|
|
|
|
@ -34,21 +31,24 @@ class ReaderActivity : BaseActivity(), ReaderView {
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
bottomBar.inflateMenu(R.menu.opt_reader_bottom)
|
|
|
|
bottomBar.inflateMenu(R.menu.opt_reader_bottom)
|
|
|
|
|
|
|
|
|
|
|
|
val chapter = manga.chapters?.find { x -> x.id == chapterId }
|
|
|
|
state = savedInstanceState?.getParcelable<ReaderState>(EXTRA_STATE)
|
|
|
|
if (chapter == null) {
|
|
|
|
?: intent.getParcelableExtra<ReaderState>(EXTRA_STATE)
|
|
|
|
// TODO
|
|
|
|
?: let {
|
|
|
|
|
|
|
|
Toast.makeText(this, R.string.error_occurred, Toast.LENGTH_SHORT).show()
|
|
|
|
finish()
|
|
|
|
finish()
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
title = chapter.name
|
|
|
|
|
|
|
|
manga.chapters?.run {
|
|
|
|
title = state.chapter?.name ?: state.manga.title
|
|
|
|
supportActionBar?.subtitle = getString(R.string.chapter_d_of_d, chapter.number, size)
|
|
|
|
state.manga.chapters?.run {
|
|
|
|
|
|
|
|
supportActionBar?.subtitle =
|
|
|
|
|
|
|
|
getString(R.string.chapter_d_of_d, state.chapter?.number ?: 0, size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loader = PageLoader(this)
|
|
|
|
loader = PageLoader(this)
|
|
|
|
adapter = PagesAdapter(loader)
|
|
|
|
adapter = PagesAdapter(loader)
|
|
|
|
pager.adapter = adapter
|
|
|
|
pager.adapter = adapter
|
|
|
|
presenter.loadChapter(chapter)
|
|
|
|
presenter.loadChapter(state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
override fun onDestroy() {
|
|
|
|
@ -57,7 +57,8 @@ class ReaderActivity : BaseActivity(), ReaderView {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
override fun onPause() {
|
|
|
|
presenter.addToHistory(manga, chapterId, pager.currentItem)
|
|
|
|
state = state.copy(page = pager.currentItem)
|
|
|
|
|
|
|
|
presenter.saveState(state)
|
|
|
|
super.onPause()
|
|
|
|
super.onPause()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -66,16 +67,17 @@ class ReaderActivity : BaseActivity(), ReaderView {
|
|
|
|
return super.onCreateOptionsMenu(menu)
|
|
|
|
return super.onCreateOptionsMenu(menu)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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, manga.chapters.orEmpty())
|
|
|
|
ChaptersDialog.show(supportFragmentManager, state.manga.chapters.orEmpty())
|
|
|
|
true
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPagesReady(pages: List<MangaPage>) {
|
|
|
|
override fun onPagesReady(pages: List<MangaPage>, index: Int) {
|
|
|
|
adapter.replaceData(pages)
|
|
|
|
adapter.replaceData(pages)
|
|
|
|
|
|
|
|
pager.setCurrentItem(index, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onLoadingStateChanged(isLoading: Boolean) {
|
|
|
|
override fun onLoadingStateChanged(isLoading: Boolean) {
|
|
|
|
@ -92,11 +94,32 @@ class ReaderActivity : BaseActivity(), ReaderView {
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
|
|
|
private const val EXTRA_MANGA = "manga"
|
|
|
|
private const val EXTRA_STATE = "state"
|
|
|
|
private const val EXTRA_CHAPTER_ID = "chapter_id"
|
|
|
|
|
|
|
|
|
|
|
|
fun newIntent(context: Context, state: ReaderState) =
|
|
|
|
fun newIntent(context: Context, manga: Manga, chapterId: Long) = Intent(context, ReaderActivity::class.java)
|
|
|
|
Intent(context, ReaderActivity::class.java)
|
|
|
|
.putExtra(EXTRA_MANGA, manga)
|
|
|
|
.putExtra(EXTRA_STATE, state)
|
|
|
|
.putExtra(EXTRA_CHAPTER_ID, chapterId)
|
|
|
|
|
|
|
|
|
|
|
|
fun newIntent(context: Context, manga: Manga, chapterId: Long = -1) = newIntent(
|
|
|
|
|
|
|
|
context, ReaderState(
|
|
|
|
|
|
|
|
manga = manga,
|
|
|
|
|
|
|
|
chapterId = if (chapterId == -1L) manga.chapters?.firstOrNull()?.id
|
|
|
|
|
|
|
|
?: -1 else chapterId,
|
|
|
|
|
|
|
|
page = 0
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun newIntent(context: Context, manga: Manga, history: MangaHistory?) =
|
|
|
|
|
|
|
|
if (history == null) {
|
|
|
|
|
|
|
|
newIntent(context, manga)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
newIntent(
|
|
|
|
|
|
|
|
context, ReaderState(
|
|
|
|
|
|
|
|
manga = manga,
|
|
|
|
|
|
|
|
chapterId = history.chapterId,
|
|
|
|
|
|
|
|
page = history.page
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|