Hide manga title in toolbar when at top
(cherry picked from commit bdc441a5be2503ff35c783d37e44ebd74b87a2b1) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
This commit is contained in:
parent
b2059288b7
commit
17e5ebd171
@ -74,7 +74,7 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
|
||||
return null
|
||||
}
|
||||
|
||||
fun setTitle() {
|
||||
fun setTitle(title: String? = null) {
|
||||
var parentController = parentController
|
||||
while (parentController != null) {
|
||||
if (parentController is BaseController<*> && parentController.getTitle() != null) {
|
||||
@ -83,7 +83,7 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
|
||||
parentController = parentController.parentController
|
||||
}
|
||||
|
||||
(activity as? AppCompatActivity)?.supportActionBar?.title = getTitle()
|
||||
(activity as? AppCompatActivity)?.supportActionBar?.title = title ?: getTitle()
|
||||
}
|
||||
|
||||
private fun Controller.instance(): String {
|
||||
|
@ -156,7 +156,7 @@ class LibraryController(
|
||||
retainViewMode = RetainViewMode.RETAIN_DETACH
|
||||
}
|
||||
|
||||
private var title: String? = null
|
||||
private var currentTitle: String? = null
|
||||
set(value) {
|
||||
if (field != value) {
|
||||
field = value
|
||||
@ -165,15 +165,15 @@ class LibraryController(
|
||||
}
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return title ?: resources?.getString(R.string.label_library)
|
||||
return currentTitle ?: resources?.getString(R.string.label_library)
|
||||
}
|
||||
|
||||
private fun updateTitle() {
|
||||
if (preferences.categoryTabs().get()) {
|
||||
title = resources?.getString(R.string.label_library)
|
||||
currentTitle = resources?.getString(R.string.label_library)
|
||||
} else {
|
||||
adapter?.categories?.get(binding.libraryPager.currentItem)?.let {
|
||||
title = it.name
|
||||
currentTitle = it.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
@ -65,6 +66,7 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.hasCustomCover
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.getCoordinates
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
@ -74,7 +76,9 @@ import eu.kanade.tachiyomi.util.view.visible
|
||||
import exh.metadata.metadata.base.FlatMetadata
|
||||
import exh.metadata.metadata.base.RaisedSearchMetadata
|
||||
import java.io.IOException
|
||||
import kotlin.math.min
|
||||
import kotlinx.android.synthetic.main.main_activity.root_coordinator
|
||||
import kotlinx.android.synthetic.main.main_activity.toolbar
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
@ -82,6 +86,7 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.withContext
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
import reactivecircus.flowbinding.recyclerview.scrollEvents
|
||||
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@ -133,6 +138,9 @@ class MangaController :
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val coverCache: CoverCache by injectLazy()
|
||||
|
||||
private val toolbarTextColor by lazy { view!!.context.getResourceColor(R.attr.colorOnPrimary) }
|
||||
private var toolbarTextAlpha = 255
|
||||
|
||||
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
|
||||
private var mangaInfoItemAdapter: MangaInfoItemAdapter? = null
|
||||
private var mangaInfoButtonsAdapter: MangaInfoButtonsAdapter? = null
|
||||
@ -177,10 +185,6 @@ class MangaController :
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return manga?.title
|
||||
}
|
||||
|
||||
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
super.onChangeEnded(handler, type)
|
||||
if (manga == null || source == null) {
|
||||
@ -246,8 +250,18 @@ class MangaController :
|
||||
if (!fromSource && preferences.jumpToChapters()) {
|
||||
(binding.recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0)
|
||||
}
|
||||
|
||||
// Delayed in case we need to jump to chapters
|
||||
binding.recycler.post {
|
||||
updateToolbarTitleAlpha()
|
||||
setTitle(manga?.title)
|
||||
}
|
||||
}
|
||||
|
||||
binding.recycler.scrollEvents()
|
||||
.onEach { updateToolbarTitleAlpha() }
|
||||
.launchIn(scope)
|
||||
|
||||
binding.swipeRefresh.refreshes()
|
||||
.onEach {
|
||||
fetchMangaInfoFromSource(manualFetch = true)
|
||||
@ -267,6 +281,32 @@ class MangaController :
|
||||
updateFilterIconState()
|
||||
}
|
||||
|
||||
private fun updateToolbarTitleAlpha(alpha: Int? = null) {
|
||||
val calculatedAlpha = when {
|
||||
// Specific alpha provided
|
||||
alpha != null -> alpha
|
||||
|
||||
// First item isn't in view, full opacity
|
||||
((binding.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 0) -> 255
|
||||
|
||||
// Based on scroll amount when first item is in view
|
||||
else -> min(binding.recycler.computeVerticalScrollOffset(), 255)
|
||||
}
|
||||
|
||||
if (calculatedAlpha != toolbarTextAlpha) {
|
||||
toolbarTextAlpha = calculatedAlpha
|
||||
|
||||
activity?.toolbar?.setTitleTextColor(
|
||||
Color.argb(
|
||||
toolbarTextAlpha,
|
||||
Color.red(toolbarTextColor),
|
||||
Color.green(toolbarTextColor),
|
||||
Color.blue(toolbarTextColor)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFilterIconState() {
|
||||
chaptersHeaderAdapter?.setHasActiveFilters(settingsSheet?.filters?.hasActiveFilters() == true)
|
||||
}
|
||||
@ -316,6 +356,7 @@ class MangaController :
|
||||
chaptersHeaderAdapter = null
|
||||
chaptersAdapter = null
|
||||
settingsSheet = null
|
||||
updateToolbarTitleAlpha(255)
|
||||
super.onDestroyView(view)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user