Skip to content

Commit

Permalink
Reworking Reader Activity Menus
Browse files Browse the repository at this point in the history
Reader settings sheet now in a tabbed layout
Reader settings sheet also contains filter options
Reader menu now holds the long tap options (Share, Save, Set as cover)
Reader menu also has option to go to manga details (was on toolbar tap)
Also has the option to jump straight to reader settings
Removing long tap gesture on Reader since no longer needed
  • Loading branch information
Jays2Kings committed Mar 24, 2021
1 parent 6b06833 commit fe2543b
Show file tree
Hide file tree
Showing 35 changed files with 1,089 additions and 1,083 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ object PreferenceKeys {

const val readWithTapping = "reader_tap"

const val readWithLongTap = "reader_long_tap"

const val readWithVolumeKeys = "reader_volume_keys"

const val readWithVolumeKeysInverted = "reader_volume_keys_inverted"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ class PreferencesHelper(val context: Context) {

fun readWithTapping() = flowPrefs.getBoolean(Keys.readWithTapping, true)

fun readWithLongTap() = flowPrefs.getBoolean(Keys.readWithLongTap, true)

fun readWithVolumeKeys() = flowPrefs.getBoolean(Keys.readWithVolumeKeys, false)

fun readWithVolumeKeysInverted() = flowPrefs.getBoolean(Keys.readWithVolumeKeysInverted, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.library.display

import android.content.Context
import android.util.AttributeSet
import eu.kanade.tachiyomi.ui.library.LibraryController
import eu.kanade.tachiyomi.util.bindToPreference
import kotlinx.android.synthetic.main.library_badges_layout.view.*

class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.library.display

import android.content.Context
import android.util.AttributeSet
import eu.kanade.tachiyomi.util.bindToPreference
import kotlinx.android.synthetic.main.library_category_layout.view.*

class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.library.display

import android.content.Context
import android.util.AttributeSet
import eu.kanade.tachiyomi.util.bindToPreference
import kotlinx.android.synthetic.main.library_display_layout.view.*

class LibraryDisplayView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,4 @@ abstract class LibraryPreferenceView @JvmOverloads constructor(context: Context,
super.onFinishInflate()
initGeneralPreferences()
}

/**
* Binds a checkbox or switch view with a boolean preference.
*/
internal fun CompoundButton.bindToPreference(pref: Preference<Boolean>, block: (() -> Unit)? = null) {
isChecked = pref.getOrDefault()
setOnCheckedChangeListener { _, isChecked ->
pref.set(isChecked)
block?.invoke()
}
}

/**
* Binds a checkbox or switch view with a boolean preference.
*/
internal fun CompoundButton.bindToPreference(
pref: com.tfcporciuncula.flow
.Preference<Boolean>,
block: ((Boolean) -> Unit)? = null
) {
isChecked = pref.get()
setOnCheckedChangeListener { _, isChecked ->
pref.set(isChecked)
block?.invoke(isChecked)
}
}

/**
* Binds a radio group with a int preference.
*/
internal fun RadioGroup.bindToPreference(pref: Preference<Int>, block: (() -> Unit)? = null) {
(getChildAt(pref.getOrDefault()) as RadioButton).isChecked = true
setOnCheckedChangeListener { _, checkedId ->
val index = indexOfChild(findViewById(checkedId))
pref.set(index)
block?.invoke()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
import kotlinx.android.synthetic.main.tabbed_bottom_sheet.*

open class TabbedLibraryDisplaySheet(controller: LibraryController):
TabbedBottomSheetDialog(controller) {
TabbedBottomSheetDialog(controller.activity!!) {

private val displayView: LibraryDisplayView = inflate(controller.activity!!, R.layout.library_display_layout, null) as LibraryDisplayView
private val badgesView: LibraryBadgesView = inflate(controller.activity!!, R.layout.library_badges_layout, null) as LibraryBadgesView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
const val SHORTCUT_BROWSE = "eu.kanade.tachiyomi.SHOW_BROWSE"
const val SHORTCUT_DOWNLOADS = "eu.kanade.tachiyomi.SHOW_DOWNLOADS"
const val SHORTCUT_MANGA = "eu.kanade.tachiyomi.SHOW_MANGA"
const val SHORTCUT_READER_SETTINGS = "eu.kanade.tachiyomi.READER_SETTINGS"
const val SHORTCUT_EXTENSIONS = "eu.kanade.tachiyomi.EXTENSIONS"

const val INTENT_SEARCH = "eu.kanade.tachiyomi.SEARCH"
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
import eu.kanade.tachiyomi.ui.setting.SettingsReaderController
import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.withFadeTransaction
Expand All @@ -35,7 +36,7 @@ class SearchActivity : MainActivity() {
}

private fun popToRoot() {
if (intent.action == SHORTCUT_MANGA) {
if (intent.action == SHORTCUT_MANGA || intent.action == SHORTCUT_READER_SETTINGS) {
onBackPressed()
} else if (!router.handleBack()) {
val intent = Intent(this, MainActivity::class.java).apply {
Expand Down Expand Up @@ -97,6 +98,13 @@ class SearchActivity : MainActivity() {
.popChangeHandler(FadeChangeHandler())
)
}
SHORTCUT_READER_SETTINGS -> {
router.replaceTopController(
RouterTransaction.with(SettingsReaderController())
.pushChangeHandler(SimpleSwapChangeHandler())
.popChangeHandler(FadeChangeHandler())
)
}
else -> return false
}
return true
Expand All @@ -112,5 +120,14 @@ class SearchActivity : MainActivity() {
action = SHORTCUT_MANGA
putExtra(MangaDetailsController.MANGA_EXTRA, id)
}

fun openReaderSettings(context: Context) = Intent(
context,
SearchActivity::class
.java
)
.apply {
action = SHORTCUT_READER_SETTINGS
}
}
}
83 changes: 34 additions & 49 deletions app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
Expand Down Expand Up @@ -279,21 +280,46 @@ class ReaderActivity :
return true
}

override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
val detailsItem = menu?.findItem(R.id.action_manga_details)
if (presenter.manga?.mangaType(this) != null) {
detailsItem?.title = getString(R.string._details,
presenter.manga?.mangaType(this)?.capitalize(Locale.ROOT) ?: "")
} else {
detailsItem?.title = getString(R.string.details)
}
return super.onPrepareOptionsMenu(menu)
}

/**
* Called when an item of the options menu was clicked. Used to handle clicks on our menu
* entries.
*/
override fun onOptionsItemSelected(item: MenuItem): Boolean {
coroutine?.cancel()
bottomSheet = when (item.itemId) {
R.id.action_settings -> ReaderSettingsSheet(this)
R.id.action_custom_filter -> ReaderColorFilterSheet(this)
when (item.itemId) {
R.id.action_display_settings -> TabbedReaderSettingsSheet(this).show()
R.id.action_manga_details -> {
presenter.manga?.id?.let { id ->
val intent = SearchActivity.openMangaIntent(this, id)
startActivity(intent)
}
}
R.id.action_share_page, R.id.action_set_page_as_cover, R.id.action_save_page -> {
val currentChapter = presenter.getCurrentChapter() ?: return true
val page = currentChapter.pages?.getOrNull(page_seekbar.progress) ?: return true
when (item.itemId) {
R.id.action_share_page -> shareImage(page)
R.id.action_set_page_as_cover -> showSetCoverPrompt(page)
R.id.action_save_page -> saveImage(page)
}
}
R.id.action_reader_settings -> {
val intent = SearchActivity.openReaderSettings(this)
startActivity(intent)
}
else -> return super.onOptionsItemSelected(item)
}
bottomSheet?.show()
if (chapters_bottom_sheet.sheetBehavior.isExpanded()) {
chapters_bottom_sheet.sheetBehavior?.collapse()
}
return true
}

Expand Down Expand Up @@ -357,13 +383,6 @@ class ReaderActivity :
popToMain()
}

toolbar.setOnClickListener {
presenter.manga?.id?.let { id ->
val intent = SearchActivity.openMangaIntent(this, id)
startActivity(intent)
}
}

// Init listeners on bottom menu
page_seekbar.setOnSeekBarChangeListener(
object : SimpleSeekBarListener() {
Expand Down Expand Up @@ -477,6 +496,7 @@ class ReaderActivity :
val prevViewer = viewer
val noDefault = manga.viewer == -1
val mangaViewer = presenter.getMangaViewer()
invalidateOptionsMenu()
val newViewer = when (mangaViewer) {
RIGHT_TO_LEFT -> R2LPagerViewer(this)
VERTICAL -> VerticalPagerViewer(this)
Expand Down Expand Up @@ -615,41 +635,6 @@ class ReaderActivity :
page_seekbar.progress = page.index
}

/**
* Called from the viewer whenever a [page] is long clicked. A bottom sheet with a list of
* actions to perform is shown.
*/
fun onPageLongTap(page: ReaderPage) {
val items = listOf(
MaterialMenuSheet.MenuSheetItem(
0,
R.drawable.ic_photo_24dp,
R.string.set_as_cover
),
MaterialMenuSheet.MenuSheetItem(
1,
R.drawable.ic_share_24dp,
R.string.share
),
MaterialMenuSheet.MenuSheetItem(
2,
R.drawable.ic_save_24dp,
R.string.save
)
)
MaterialMenuSheet(this, items) { _, item ->
when (item) {
0 -> showSetCoverPrompt(page)
1 -> shareImage(page)
2 -> saveImage(page)
}
true
}.show()
if (chapters_bottom_sheet.sheetBehavior.isExpanded()) {
chapters_bottom_sheet.sheetBehavior?.collapse()
}
}

/**
* Called from the viewer when the given [chapter] should be preloaded. It should be called when
* the viewer is reaching the beginning or end of a chapter or the transition page is active.
Expand Down
Loading

0 comments on commit fe2543b

Please sign in to comment.