|
|
|
|
@ -12,7 +12,6 @@ import androidx.core.view.OnApplyWindowInsetsListener
|
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
|
import androidx.core.view.updatePadding
|
|
|
|
|
import androidx.lifecycle.flowWithLifecycle
|
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import androidx.transition.Slide
|
|
|
|
|
import androidx.transition.TransitionManager
|
|
|
|
|
@ -20,8 +19,6 @@ import androidx.transition.TransitionSet
|
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
import org.koin.android.ext.android.get
|
|
|
|
|
@ -44,7 +41,6 @@ import org.koitharu.kotatsu.reader.ui.thumbnails.OnPageSelectListener
|
|
|
|
|
import org.koitharu.kotatsu.reader.ui.thumbnails.PagesThumbnailsSheet
|
|
|
|
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
|
|
|
|
import org.koitharu.kotatsu.utils.GridTouchHelper
|
|
|
|
|
import org.koitharu.kotatsu.utils.ScreenOrientationHelper
|
|
|
|
|
import org.koitharu.kotatsu.utils.ShareHelper
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.*
|
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
@ -68,7 +64,6 @@ class ReaderActivity :
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private lateinit var touchHelper: GridTouchHelper
|
|
|
|
|
private lateinit var orientationHelper: ScreenOrientationHelper
|
|
|
|
|
private lateinit var controlDelegate: ReaderControlDelegate
|
|
|
|
|
private val savePageRequest = registerForActivityResult(PageSaveContract(), this)
|
|
|
|
|
private var gestureInsets: Insets = Insets.NONE
|
|
|
|
|
@ -81,18 +76,12 @@ class ReaderActivity :
|
|
|
|
|
readerManager = ReaderManager(supportFragmentManager, R.id.container)
|
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
|
touchHelper = GridTouchHelper(this, this)
|
|
|
|
|
orientationHelper = ScreenOrientationHelper(this)
|
|
|
|
|
controlDelegate = ReaderControlDelegate(lifecycleScope, get(), this)
|
|
|
|
|
binding.toolbarBottom.inflateMenu(R.menu.opt_reader_bottom)
|
|
|
|
|
binding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
|
|
|
|
binding.slider.setLabelFormatter(PageLabelFormatter())
|
|
|
|
|
ReaderSliderListener(this, viewModel).attachToSlider(binding.slider)
|
|
|
|
|
insetsDelegate.interceptingWindowInsetsListener = this
|
|
|
|
|
|
|
|
|
|
orientationHelper.observeAutoOrientation()
|
|
|
|
|
.flowWithLifecycle(lifecycle)
|
|
|
|
|
.onEach {
|
|
|
|
|
binding.toolbarBottom.menu.findItem(R.id.action_screen_rotate).isVisible = !it
|
|
|
|
|
}.launchIn(lifecycleScope)
|
|
|
|
|
|
|
|
|
|
viewModel.onError.observe(this, this::onError)
|
|
|
|
|
viewModel.readerMode.observe(this, this::onInitReader)
|
|
|
|
|
viewModel.onPageSaved.observe(this, this::onPageSaved)
|
|
|
|
|
@ -114,15 +103,6 @@ class ReaderActivity :
|
|
|
|
|
if (readerManager.currentMode != mode) {
|
|
|
|
|
readerManager.replace(mode)
|
|
|
|
|
}
|
|
|
|
|
val iconRes = when (mode) {
|
|
|
|
|
ReaderMode.WEBTOON -> R.drawable.ic_script
|
|
|
|
|
ReaderMode.REVERSED -> R.drawable.ic_read_reversed
|
|
|
|
|
ReaderMode.STANDARD -> R.drawable.ic_book_page
|
|
|
|
|
}
|
|
|
|
|
binding.toolbarBottom.menu.findItem(R.id.action_reader_mode).run {
|
|
|
|
|
setIcon(iconRes)
|
|
|
|
|
setVisible(true)
|
|
|
|
|
}
|
|
|
|
|
if (binding.appbarTop.isVisible) {
|
|
|
|
|
lifecycle.postDelayed(hideUiRunnable, TimeUnit.SECONDS.toMillis(1))
|
|
|
|
|
}
|
|
|
|
|
@ -135,7 +115,7 @@ class ReaderActivity :
|
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
|
when (item.itemId) {
|
|
|
|
|
R.id.action_reader_mode -> {
|
|
|
|
|
R.id.action_menu -> {
|
|
|
|
|
val currentMode = readerManager.currentMode ?: return false
|
|
|
|
|
ReaderConfigDialog.show(supportFragmentManager, currentMode)
|
|
|
|
|
}
|
|
|
|
|
@ -149,9 +129,6 @@ class ReaderActivity :
|
|
|
|
|
viewModel.getCurrentState()?.chapterId ?: 0L
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
R.id.action_screen_rotate -> {
|
|
|
|
|
orientationHelper.toggleOrientation()
|
|
|
|
|
}
|
|
|
|
|
R.id.action_pages_thumbs -> {
|
|
|
|
|
val pages = viewModel.getCurrentChapterPages()
|
|
|
|
|
if (!pages.isNullOrEmpty()) {
|
|
|
|
|
@ -165,11 +142,6 @@ class ReaderActivity :
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
R.id.action_save_page -> {
|
|
|
|
|
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
|
|
|
|
val page = viewModel.getCurrentPage() ?: return false
|
|
|
|
|
viewModel.saveCurrentPage(page, savePageRequest)
|
|
|
|
|
}
|
|
|
|
|
R.id.action_bookmark -> {
|
|
|
|
|
if (viewModel.isBookmarkAdded.value == true) {
|
|
|
|
|
viewModel.removeBookmark()
|
|
|
|
|
@ -197,7 +169,6 @@ class ReaderActivity :
|
|
|
|
|
val menu = binding.toolbarBottom.menu
|
|
|
|
|
menu.findItem(R.id.action_bookmark).isVisible = hasPages
|
|
|
|
|
menu.findItem(R.id.action_pages_thumbs).isVisible = hasPages
|
|
|
|
|
menu.findItem(R.id.action_save_page).isVisible = hasPages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun onError(e: Throwable) {
|
|
|
|
|
@ -347,16 +318,28 @@ class ReaderActivity :
|
|
|
|
|
|
|
|
|
|
private fun onUiStateChanged(uiState: ReaderUiState?, previous: ReaderUiState?) {
|
|
|
|
|
title = uiState?.chapterName ?: uiState?.mangaName ?: getString(R.string.loading_)
|
|
|
|
|
supportActionBar?.subtitle = if (uiState != null && uiState.chapterNumber in 1..uiState.chaptersTotal) {
|
|
|
|
|
if (uiState == null) {
|
|
|
|
|
supportActionBar?.subtitle = null
|
|
|
|
|
binding.slider.isVisible = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
supportActionBar?.subtitle = if (uiState.chapterNumber in 1..uiState.chaptersTotal) {
|
|
|
|
|
getString(R.string.chapter_d_of_d, uiState.chapterNumber, uiState.chaptersTotal)
|
|
|
|
|
} else {
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
if (uiState != null && previous?.chapterName != null && uiState.chapterName != previous.chapterName) {
|
|
|
|
|
if (previous?.chapterName != null && uiState.chapterName != previous.chapterName) {
|
|
|
|
|
if (!uiState.chapterName.isNullOrEmpty()) {
|
|
|
|
|
binding.toastView.showTemporary(uiState.chapterName, TOAST_DURATION)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (uiState.totalPages > 0) {
|
|
|
|
|
binding.slider.value = uiState.currentPage.toFloat()
|
|
|
|
|
binding.slider.valueTo = uiState.totalPages.toFloat()
|
|
|
|
|
binding.slider.isVisible = true
|
|
|
|
|
} else {
|
|
|
|
|
binding.slider.isVisible = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private inner class ErrorDialogListener(
|
|
|
|
|
|