Using popup menu helper for reading mode

This commit is contained in:
Jays2Kings 2021-04-26 01:19:02 -04:00
parent cd81df0cf2
commit 7a90d1bf06

View File

@ -559,7 +559,7 @@ class ReaderActivity :
/** /**
* Initializes the reader menu. It sets up click listeners and the initial visibility. * Initializes the reader menu. It sets up click listeners and the initial visibility.
*/ */
@SuppressLint("ClickableViewAccessibility", "RestrictedApi") @SuppressLint("ClickableViewAccessibility")
private fun initializeMenu() { private fun initializeMenu() {
// Set binding.toolbar // Set binding.toolbar
setSupportActionBar(binding.toolbar) setSupportActionBar(binding.toolbar)
@ -635,38 +635,13 @@ class ReaderActivity :
true true
} }
readingMode.setOnClickListener { readingMode.setOnClickListener { readingMode ->
val popup = PopupMenu(this@ReaderActivity, readingMode, Gravity.END) readingMode.popupMenu(
val enumConstants = ReadingModeType::class.java.enumConstants items = ReadingModeType.values().map { it.prefValue to it.stringRes },
val array = enumConstants?.map { it.stringRes }.orEmpty().toTypedArray() selectedItemId = presenter.manga?.viewer,
array.forEachIndexed { index, entry -> ) {
popup.menu.add(0, index, 0, entry) presenter.setMangaViewer(itemId)
} }
if (popup.menu is MenuBuilder) {
val m = popup.menu as MenuBuilder
m.setOptionalIconsVisible(true)
}
val blendedAccent = ColorUtils.blendARGB(
this@ReaderActivity.getResourceColor(android.R.attr.colorAccent),
this@ReaderActivity.getResourceColor(android.R.attr.textColorPrimary),
0.5f
)
popup.menu.forEach {
it.icon =
ContextCompat.getDrawable(this@ReaderActivity, R.drawable.ic_blank_24dp)
}
popup.menu.getItem(presenter.manga?.viewer ?: 0)?.let { menuItem ->
menuItem.icon =
ContextCompat.getDrawable(this@ReaderActivity, R.drawable.ic_check_24dp)
?.mutate()?.apply { setTint(blendedAccent) }
menuItem.title =
menuItem.title?.tintText(blendedAccent)
}
popup.setOnMenuItemClickListener { menuItem ->
presenter.setMangaViewer(menuItem.itemId)
true
}
popup.show()
} }
} }