|
|
|
|
@ -3,6 +3,7 @@ package org.koitharu.kotatsu.reader.ui
|
|
|
|
|
import android.view.Menu
|
|
|
|
|
import android.view.MenuInflater
|
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.core.view.MenuProvider
|
|
|
|
|
import androidx.fragment.app.FragmentActivity
|
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
|
@ -12,6 +13,7 @@ import org.koitharu.kotatsu.core.prefs.ReaderControl
|
|
|
|
|
class ReaderMenuBottomProvider(
|
|
|
|
|
private val activity: FragmentActivity,
|
|
|
|
|
private val readerManager: ReaderManager,
|
|
|
|
|
private val screenOrientationHelper: ScreenOrientationHelper,
|
|
|
|
|
private val viewModel: ReaderViewModel,
|
|
|
|
|
) : MenuProvider {
|
|
|
|
|
|
|
|
|
|
@ -21,18 +23,39 @@ class ReaderMenuBottomProvider(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onPrepareMenu(menu: Menu) {
|
|
|
|
|
val readerControls = viewModel.readerControls.value
|
|
|
|
|
val isPagesSheetEnabled = viewModel.content.value.pages.isNotEmpty() &&
|
|
|
|
|
ReaderControl.PAGES_SHEET in viewModel.readerControls.value
|
|
|
|
|
ReaderControl.PAGES_SHEET in readerControls
|
|
|
|
|
menu.findItem(R.id.action_pages_thumbs).run {
|
|
|
|
|
isVisible = isPagesSheetEnabled
|
|
|
|
|
if (isPagesSheetEnabled) {
|
|
|
|
|
setIcon(if (viewModel.isPagesSheetEnabled.value) R.drawable.ic_grid else R.drawable.ic_list)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
menu.findItem(R.id.action_screen_rotation).run {
|
|
|
|
|
isVisible = ReaderControl.SCREEN_ROTATION in readerControls
|
|
|
|
|
when {
|
|
|
|
|
!isVisible -> Unit
|
|
|
|
|
!screenOrientationHelper.isAutoRotationEnabled -> {
|
|
|
|
|
setTitle(R.string.rotate_screen)
|
|
|
|
|
setIcon(R.drawable.ic_screen_rotation)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
|
setTitle(R.string.lock_screen_rotation)
|
|
|
|
|
setIcon(R.drawable.ic_screen_rotation_lock)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
|
|
|
|
return when (menuItem.itemId) {
|
|
|
|
|
R.id.action_screen_rotation -> {
|
|
|
|
|
toggleScreenRotation()
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
R.id.action_pages_thumbs -> {
|
|
|
|
|
activity.router.showChapterPagesSheet()
|
|
|
|
|
true
|
|
|
|
|
@ -57,4 +80,22 @@ class ReaderMenuBottomProvider(
|
|
|
|
|
else -> false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun toggleScreenRotation() = with(screenOrientationHelper) {
|
|
|
|
|
if (isAutoRotationEnabled) {
|
|
|
|
|
val newValue = !isLocked
|
|
|
|
|
isLocked = newValue
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
activity,
|
|
|
|
|
if (newValue) {
|
|
|
|
|
R.string.screen_rotation_locked
|
|
|
|
|
} else {
|
|
|
|
|
R.string.screen_rotation_unlocked
|
|
|
|
|
},
|
|
|
|
|
Toast.LENGTH_SHORT,
|
|
|
|
|
).show()
|
|
|
|
|
} else {
|
|
|
|
|
isLandscape = !isLandscape
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|