Add icon for crop border shortcut off state

This commit is contained in:
arkon 2021-03-30 18:27:09 -04:00
parent 468cdf603c
commit 4054f2a6a0
3 changed files with 60 additions and 11 deletions

View file

@ -343,7 +343,15 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
}
}
with(binding.actionReaderMode) {
initBottomShortcuts()
// Set initial visibility
setMenuVisibility(menuVisible)
}
private fun initBottomShortcuts() {
// Reading mode
with(binding.actionReadingMode) {
setTooltip(R.string.viewer)
setOnClickListener {
@ -352,10 +360,13 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
presenter.setMangaViewer(newReadingMode.prefValue)
menuToggleToast?.cancel()
menuToggleToast = toast(newReadingMode.stringRes)
if (!preferences.showReadingMode()) {
menuToggleToast = toast(newReadingMode.stringRes)
}
}
}
// Rotation
with(binding.actionRotation) {
setTooltip(R.string.pref_rotation_type)
@ -371,11 +382,9 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
}
}
preferences.rotation().asImmediateFlow { updateRotationShortcut(it) }
.onEach {
updateRotationShortcut(it)
}
.launchIn(lifecycleScope)
// Crop borders
with(binding.actionCropBorders) {
setTooltip(R.string.pref_crop_borders)
@ -388,7 +397,15 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
}
}
}
updateCropBordersShortcut()
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
.forEach { pref ->
pref.asFlow()
.onEach { updateCropBordersShortcut() }
.launchIn(lifecycleScope)
}
// Settings sheet
with(binding.actionSettings) {
setTooltip(R.string.action_settings)
@ -396,9 +413,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
ReaderSettingsSheet(this@ReaderActivity).show()
}
}
// Set initial visibility
setMenuVisibility(menuVisible)
}
private fun updateRotationShortcut(preference: Int) {
@ -406,6 +420,23 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
binding.actionRotation.setImageResource(orientation.iconRes)
}
private fun updateCropBordersShortcut() {
val isPagerType = ReadingModeType.isPagerType(presenter.getMangaViewer())
val enabled = if (isPagerType) {
preferences.cropBorders().get()
} else {
preferences.cropBordersWebtoon().get()
}
binding.actionCropBorders.setImageResource(
if (enabled) {
R.drawable.ic_crop_24dp
} else {
R.drawable.ic_crop_off_24dp
}
)
}
/**
* Sets the visibility of the menu according to [visible] and with an optional parameter to
* [animate] the views.
@ -483,7 +514,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
val prevViewer = viewer
val viewerMode = ReadingModeType.fromPreference(presenter.getMangaViewer(resolveDefault = false))
binding.actionReaderMode.setImageResource(viewerMode.iconRes)
binding.actionReadingMode.setImageResource(viewerMode.iconRes)
val newViewer = when (presenter.getMangaViewer()) {
ReadingModeType.LEFT_TO_RIGHT.prefValue -> L2RPagerViewer(this)

View file

@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M7,1l-2,0l0,1.18l2,2l0,-3.18z" />
<path
android:fillColor="@android:color/black"
android:pathData="M17,7v7.18l0.82,0.82H19V7a2.0059,2.0059 0,0 0,-2 -2H9V6.18L9.82,7Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M19.0001,19l-2,-2h0L2.1,2.1 0.68,3.51 2.1707,5H1V7H4.1718L5,7.8278V17a2.0059,2.0059 0,0 0,2 2h9.1778L17,19.8218V23h2V21.8207L20.49,23.31 21.9,21.9l-2.9,-2.9ZM7,17V9.8268L14.1768,17Z" />
<path
android:fillColor="@android:color/black"
android:pathData="M19.82,17l2,2l1.18,0l0,-2l-3.18,0z" />
</vector>

View file

@ -152,7 +152,7 @@
android:background="?attr/colorPrimary">
<ImageButton
android:id="@+id/action_reader_mode"
android:id="@+id/action_reading_mode"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
@ -172,7 +172,7 @@
android:contentDescription="@string/pref_rotation_type"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
app:layout_constraintEnd_toStartOf="@id/action_crop_borders"
app:layout_constraintStart_toEndOf="@+id/action_reader_mode"
app:layout_constraintStart_toEndOf="@+id/action_reading_mode"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_screen_rotation_24dp"
app:tint="?attr/colorOnPrimary" />