Converting main activity to binding

This commit is contained in:
Jays2Kings 2021-03-28 22:24:52 -04:00
parent 63c8775854
commit bde20b8135
11 changed files with 142 additions and 133 deletions

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.base.activity
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.viewbinding.ViewBinding
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.main.SearchActivity import eu.kanade.tachiyomi.ui.main.SearchActivity
import eu.kanade.tachiyomi.ui.security.BiometricActivity import eu.kanade.tachiyomi.ui.security.BiometricActivity
@ -11,9 +12,10 @@ import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.ThemeUtil import eu.kanade.tachiyomi.util.system.ThemeUtil
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
abstract class BaseActivity : AppCompatActivity() { abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
val preferences: PreferencesHelper by injectLazy() val preferences: PreferencesHelper by injectLazy()
lateinit var binding: VB
init { init {
@Suppress("LeakingThis") @Suppress("LeakingThis")

View File

@ -77,6 +77,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getBottomGestureInsets import eu.kanade.tachiyomi.util.system.getBottomGestureInsets
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.getItemView import eu.kanade.tachiyomi.util.view.getItemView
@ -96,7 +97,6 @@ import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.util.view.visibleIf
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import eu.kanade.tachiyomi.widget.EndAnimatorListener import eu.kanade.tachiyomi.widget.EndAnimatorListener
import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -256,7 +256,7 @@ class LibraryController(
} }
fun updateFilterSheetY() { fun updateFilterSheetY() {
val bottomBar = activity?.bottom_nav val bottomBar = activityBinding?.bottomNav
if (bottomBar != null) { if (bottomBar != null) {
if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) { if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) {
val pad = bottomBar.translationY - bottomBar.height val pad = bottomBar.translationY - bottomBar.height
@ -292,8 +292,8 @@ class LibraryController(
if (preferences.autohideHopper().get()) { if (preferences.autohideHopper().get()) {
// Flow same snap rules as bottom nav // Flow same snap rules as bottom nav
val closerToHopperBottom = hopperOffset > 25f.dpToPx val closerToHopperBottom = hopperOffset > 25f.dpToPx
val halfWayBottom = activity!!.bottom_nav.height.toFloat() / 2 val halfWayBottom = activityBinding?.bottomNav?.height?.toFloat()?.div(2) ?: 0f
val closerToBottom = activity!!.bottom_nav.translationY > halfWayBottom val closerToBottom = (activityBinding?.bottomNav?.translationY ?: 0f) > halfWayBottom
val atTop = !binding.libraryGridRecycler.recycler.canScrollVertically(-1) val atTop = !binding.libraryGridRecycler.recycler.canScrollVertically(-1)
val closerToEdge = if (preferences.hideBottomNavOnScroll().get()) (closerToBottom && !atTop) else closerToHopperBottom val closerToEdge = if (preferences.hideBottomNavOnScroll().get()) (closerToBottom && !atTop) else closerToHopperBottom
val end = if (closerToEdge) 55f.dpToPx else 0f val end = if (closerToEdge) 55f.dpToPx else 0f
@ -362,8 +362,9 @@ class LibraryController(
private fun showFilterTip() { private fun showFilterTip() {
if (preferences.shownFilterTutorial().get() || !hasExpanded) return if (preferences.shownFilterTutorial().get() || !hasExpanded) return
val activityBinding = activityBinding ?: return
val activity = activity ?: return val activity = activity ?: return
val icon = activity.bottom_nav.getItemView(R.id.nav_library) ?: return val icon = activityBinding.bottomNav.getItemView(R.id.nav_library) ?: return
filterTooltip = filterTooltip =
ViewTooltip.on(activity, icon).autoHide(false, 0L).align(ViewTooltip.ALIGN.START) ViewTooltip.on(activity, icon).autoHide(false, 0L).align(ViewTooltip.ALIGN.START)
.position(ViewTooltip.Position.TOP).text(R.string.tap_library_to_show_filters) .position(ViewTooltip.Position.TOP).text(R.string.tap_library_to_show_filters)
@ -582,7 +583,7 @@ class LibraryController(
} }
binding.roundedCategoryHopper.categoryButton.setOnLongClickListener { binding.roundedCategoryHopper.categoryButton.setOnLongClickListener {
activity?.toolbar?.menu?.performIdentifierAction(R.id.action_search, 0) activityBinding?.toolbar?.menu?.performIdentifierAction(R.id.action_search, 0)
true true
} }
@ -627,7 +628,7 @@ class LibraryController(
val view = view ?: return val view = view ?: return
val listOfYs = mutableListOf( val listOfYs = mutableListOf(
binding.filterBottomSheet.filterBottomSheet.y, binding.filterBottomSheet.filterBottomSheet.y,
activity?.bottom_nav?.y ?: binding.filterBottomSheet.filterBottomSheet.y activityBinding?.bottomNav?.y ?: binding.filterBottomSheet.filterBottomSheet.y
) )
val insetBottom = view.rootWindowInsets?.systemWindowInsetBottom ?: 0 val insetBottom = view.rootWindowInsets?.systemWindowInsetBottom ?: 0
if (!preferences.autohideHopper().get()) { if (!preferences.autohideHopper().get()) {
@ -639,8 +640,8 @@ class LibraryController(
binding.libraryGridRecycler.recycler.translationY binding.libraryGridRecycler.recycler.translationY
if (view.height - insetBottom < binding.categoryHopperFrame.y) { if (view.height - insetBottom < binding.categoryHopperFrame.y) {
binding.jumperCategoryText.translationY = binding.jumperCategoryText.translationY =
-(binding.categoryHopperFrame.y - (view.height - insetBottom)) -(binding.categoryHopperFrame.y - (view.height - insetBottom)) +
+binding.libraryGridRecycler.recycler.translationY binding.libraryGridRecycler.recycler.translationY
} else { } else {
binding.jumperCategoryText.translationY = binding.libraryGridRecycler.recycler.translationY binding.jumperCategoryText.translationY = binding.libraryGridRecycler.recycler.translationY
} }
@ -730,7 +731,7 @@ class LibraryController(
return binding.root return binding.root
} }
private fun anchorView(): View? { private fun anchorView(): View {
return if (binding.categoryHopperFrame.isVisible()) { return if (binding.categoryHopperFrame.isVisible()) {
binding.categoryHopperFrame binding.categoryHopperFrame
} else { } else {
@ -753,7 +754,7 @@ class LibraryController(
private fun setRecyclerLayout() { private fun setRecyclerLayout() {
binding.libraryGridRecycler.recycler.post { binding.libraryGridRecycler.recycler.post {
binding.libraryGridRecycler.recycler.updatePaddingRelative(bottom = 50.dpToPx + (activity?.bottom_nav?.height ?: 0)) binding.libraryGridRecycler.recycler.updatePaddingRelative(bottom = 50.dpToPx + (activityBinding?.bottomNav?.height ?: 0))
} }
if (libraryLayout == 0) { if (libraryLayout == 0) {
binding.libraryGridRecycler.recycler.spanCount = 1 binding.libraryGridRecycler.recycler.spanCount = 1
@ -792,14 +793,14 @@ class LibraryController(
if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) { if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) {
binding.filterBottomSheet.filterBottomSheet.invisible() binding.filterBottomSheet.filterBottomSheet.invisible()
} }
activity?.toolbar?.hideDropdown() activityBinding?.toolbar?.hideDropdown()
} }
} }
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeEnded(handler, type) super.onChangeEnded(handler, type)
if (!type.isEnter) { if (!type.isEnter) {
activity?.toolbar?.hideDropdown() activityBinding?.toolbar?.hideDropdown()
} }
} }
@ -859,7 +860,7 @@ class LibraryController(
scrollToHeader(activeCategory) scrollToHeader(activeCategory)
} }
binding.libraryGridRecycler.recycler.post { binding.libraryGridRecycler.recycler.post {
elevateAppBar(binding.libraryGridRecycler.recycler.canScrollVertically(-1) == true) elevateAppBar(binding.libraryGridRecycler.recycler.canScrollVertically(-1))
setActiveCategory() setActiveCategory()
} }
@ -876,7 +877,7 @@ class LibraryController(
shouldScrollToTop = false shouldScrollToTop = false
} }
if (onRoot) { if (onRoot) {
listOf(activity?.toolbar, binding.headerTitle).forEach { listOf(activityBinding?.toolbar, binding.headerTitle).forEach {
it?.setOnClickListener { it?.setOnClickListener {
val recycler = binding.libraryGridRecycler.recycler val recycler = binding.libraryGridRecycler.recycler
if (singleCategory) { if (singleCategory) {
@ -896,9 +897,9 @@ class LibraryController(
private fun showDropdown() { private fun showDropdown() {
if (onRoot) { if (onRoot) {
if (!singleCategory) { if (!singleCategory) {
activity?.toolbar?.showDropdown() activityBinding?.toolbar?.showDropdown()
} else { } else {
activity?.toolbar?.hideDropdown() activityBinding?.toolbar?.hideDropdown()
} }
} }
} }
@ -939,7 +940,7 @@ class LibraryController(
val translateY = if (show) full else 0f val translateY = if (show) full else 0f
binding.libraryGridRecycler.recycler.animate().translationY(translateY).apply { binding.libraryGridRecycler.recycler.animate().translationY(translateY).apply {
setUpdateListener { setUpdateListener {
activity?.appbar?.y = 0f activityBinding?.appBar?.y = 0f
updateHopperY() updateHopperY()
} }
}.start() }.start()
@ -947,13 +948,13 @@ class LibraryController(
binding.recyclerCover.animate().translationY(translateY).start() binding.recyclerCover.animate().translationY(translateY).start()
binding.recyclerCover.animate().alpha(if (show) 0.75f else 0f).start() binding.recyclerCover.animate().alpha(if (show) 0.75f else 0f).start()
binding.libraryGridRecycler.recycler.suppressLayout(show) binding.libraryGridRecycler.recycler.suppressLayout(show)
activity?.toolbar?.showDropdown(!show) activityBinding?.toolbar?.showDropdown(!show)
binding.swipeRefresh.isEnabled = !show binding.swipeRefresh.isEnabled = !show
setTitle() setTitle()
if (show) { if (show) {
binding.categoryRecycler.scrollToCategory(activeCategory) binding.categoryRecycler.scrollToCategory(activeCategory)
binding.fastScroller.hideScrollbar() binding.fastScroller.hideScrollbar()
activity?.appbar?.y = 0f activityBinding?.appBar?.y = 0f
elevateAppBar(false) elevateAppBar(false)
binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide() binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide()
} else { } else {
@ -972,7 +973,7 @@ class LibraryController(
} }
val headerPosition = adapter.indexOf(pos) val headerPosition = adapter.indexOf(pos)
if (headerPosition > -1) { if (headerPosition > -1) {
val appbar = activity?.appbar val appbar = activityBinding?.appBar
binding.libraryGridRecycler.recycler.suppressLayout(true) binding.libraryGridRecycler.recycler.suppressLayout(true)
val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else ( val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else (
appbar?.y?.plus( appbar?.y?.plus(

View File

@ -45,6 +45,7 @@ import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.updater.UpdateChecker import eu.kanade.tachiyomi.data.updater.UpdateChecker
import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdateResult
import eu.kanade.tachiyomi.databinding.MainActivityBinding
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.BaseController
@ -73,7 +74,6 @@ import eu.kanade.tachiyomi.util.view.updatePadding
import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.util.view.visibleIf
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import eu.kanade.tachiyomi.widget.EndAnimatorListener import eu.kanade.tachiyomi.widget.EndAnimatorListener
import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -85,7 +85,7 @@ import java.util.Date
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.math.abs import kotlin.math.abs
open class MainActivity : BaseActivity(), DownloadServiceListener { open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceListener {
protected lateinit var router: Router protected lateinit var router: Router
@ -119,8 +119,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
extraViewForUndo = extraViewToCheck extraViewForUndo = extraViewToCheck
} }
lateinit var tabAnimator: TabsAnimator
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
// Create a webview before extensions do or else they will break night mode theme // Create a webview before extensions do or else they will break night mode theme
// https://stackoverflow.com/questions/54191883 // https://stackoverflow.com/questions/54191883
@ -138,10 +136,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
return return
} }
gestureDetector = GestureDetectorCompat(this, GestureListener()) gestureDetector = GestureDetectorCompat(this, GestureListener())
binding = MainActivityBinding.inflate(layoutInflater)
setContentView(R.layout.main_activity) setContentView(binding.root)
setSupportActionBar(binding.toolbar)
setSupportActionBar(toolbar)
drawerArrow = DrawerArrowDrawable(this) drawerArrow = DrawerArrowDrawable(this)
drawerArrow?.color = getResourceColor(R.attr.actionBarTintColor) drawerArrow?.color = getResourceColor(R.attr.actionBarTintColor)
@ -155,11 +153,11 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
) )
var continueSwitchingTabs = false var continueSwitchingTabs = false
bottom_nav.getItemView(R.id.nav_library)?.setOnLongClickListener { binding.bottomNav.getItemView(R.id.nav_library)?.setOnLongClickListener {
if (!LibraryUpdateService.isRunning()) { if (!LibraryUpdateService.isRunning()) {
LibraryUpdateService.start(this) LibraryUpdateService.start(this)
main_content.snack(R.string.updating_library) { binding.mainContent.snack(R.string.updating_library) {
anchorView = bottom_nav anchorView = binding.bottomNav
setAction(R.string.cancel) { setAction(R.string.cancel) {
LibraryUpdateService.stop(context) LibraryUpdateService.stop(context)
Handler().post { NotificationReceiver.dismissNotification(context, Notifications.ID_LIBRARY_PROGRESS) } Handler().post { NotificationReceiver.dismissNotification(context, Notifications.ID_LIBRARY_PROGRESS) }
@ -169,9 +167,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
true true
} }
for (id in listOf(R.id.nav_recents, R.id.nav_browse)) { for (id in listOf(R.id.nav_recents, R.id.nav_browse)) {
bottom_nav.getItemView(id)?.setOnLongClickListener { binding.bottomNav.getItemView(id)?.setOnLongClickListener {
bottom_nav.selectedItemId = id binding.bottomNav.selectedItemId = id
bottom_nav.post { binding.bottomNav.post {
val controller = val controller =
router.backstack.firstOrNull()?.controller() as? BottomSheetController router.backstack.firstOrNull()?.controller() as? BottomSheetController
controller?.showSheet() controller?.showSheet()
@ -179,13 +177,13 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
true true
} }
} }
bottom_nav.setOnNavigationItemSelectedListener { item -> binding.bottomNav.setOnNavigationItemSelectedListener { item ->
val id = item.itemId val id = item.itemId
val currentController = router.backstack.lastOrNull()?.controller() val currentController = router.backstack.lastOrNull()?.controller()
if (!continueSwitchingTabs && currentController is BottomNavBarInterface) { if (!continueSwitchingTabs && currentController is BottomNavBarInterface) {
if (!currentController.canChangeTabs { if (!currentController.canChangeTabs {
continueSwitchingTabs = true continueSwitchingTabs = true
this@MainActivity.bottom_nav.selectedItemId = id this@MainActivity.binding.bottomNav.selectedItemId = id
} }
) return@setOnNavigationItemSelectedListener false ) return@setOnNavigationItemSelectedListener false
} }
@ -209,9 +207,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
true true
} }
val container: ViewGroup = findViewById(R.id.controller_container) val container: ViewGroup = binding.controllerContainer
val content: ViewGroup = findViewById(R.id.main_content) val content: ViewGroup = binding.mainContent
DownloadService.addListener(this) DownloadService.addListener(this)
content.systemUiVisibility = content.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
@ -221,7 +219,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
supportActionBar?.setDisplayShowCustomEnabled(true) supportActionBar?.setDisplayShowCustomEnabled(true)
setNavBarColor(content.rootWindowInsets) setNavBarColor(content.rootWindowInsets)
bottom_view.gone() binding.bottomView.gone()
content.doOnApplyWindowInsets { v, insets, _ -> content.doOnApplyWindowInsets { v, insets, _ ->
setNavBarColor(insets) setNavBarColor(insets)
val contextView = window?.decorView?.findViewById<View>(R.id.action_mode_bar) val contextView = window?.decorView?.findViewById<View>(R.id.action_mode_bar)
@ -235,12 +233,12 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
left = insets.systemWindowInsetLeft, left = insets.systemWindowInsetLeft,
right = insets.systemWindowInsetRight right = insets.systemWindowInsetRight
) )
appbar.updatePadding( binding.appBar.updatePadding(
top = insets.systemWindowInsetTop top = insets.systemWindowInsetTop
) )
bottom_nav.updatePadding(bottom = insets.systemWindowInsetBottom) binding.bottomNav.updatePadding(bottom = insets.systemWindowInsetBottom)
bottom_view.visibleIf(insets.systemWindowInsetBottom > 0) binding.bottomView.visibleIf(insets.systemWindowInsetBottom > 0)
bottom_view.updateLayoutParams<ViewGroup.LayoutParams> { binding.bottomView.updateLayoutParams<ViewGroup.LayoutParams> {
height = insets.systemWindowInsetBottom height = insets.systemWindowInsetBottom
} }
} }
@ -253,16 +251,16 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
} }
toolbar.setNavigationOnClickListener { binding.toolbar.setNavigationOnClickListener {
val rootSearchController = router.backstack.lastOrNull()?.controller() val rootSearchController = router.backstack.lastOrNull()?.controller()
if (rootSearchController is RootSearchInterface) { if (rootSearchController is RootSearchInterface) {
rootSearchController.expandSearch() rootSearchController.expandSearch()
} else onBackPressed() } else onBackPressed()
} }
bottom_nav.visibleIf(!hideBottomNav) binding.bottomNav.visibleIf(!hideBottomNav)
bottom_view.visibility = if (hideBottomNav) View.GONE else bottom_view.visibility binding.bottomView.visibility = if (hideBottomNav) View.GONE else binding.bottomView.visibility
bottom_nav.alpha = if (hideBottomNav) 0f else 1f binding.bottomNav.alpha = if (hideBottomNav) 0f else 1f
router.addChangeListener( router.addChangeListener(
object : ControllerChangeHandler.ControllerChangeListener { object : ControllerChangeHandler.ControllerChangeListener {
override fun onChangeStarted( override fun onChangeStarted(
@ -273,9 +271,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
handler: ControllerChangeHandler handler: ControllerChangeHandler
) { ) {
syncActivityViewWithController(to, from, isPush) syncActivityViewWithController(to, from, isPush)
appbar.y = 0f binding.appBar.y = 0f
if (!isPush || router.backstackSize == 1) { if (!isPush || router.backstackSize == 1) {
bottom_nav.translationY = 0f binding.bottomNav.translationY = 0f
} }
snackBar?.dismiss() snackBar?.dismiss()
} }
@ -287,8 +285,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
container: ViewGroup, container: ViewGroup,
handler: ControllerChangeHandler handler: ControllerChangeHandler
) { ) {
appbar.y = 0f binding.appBar.y = 0f
bottom_nav.translationY = 0f binding.bottomNav.translationY = 0f
showDLQueueTutorial() showDLQueueTutorial()
} }
} }
@ -296,7 +294,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
syncActivityViewWithController(router.backstack.lastOrNull()?.controller()) syncActivityViewWithController(router.backstack.lastOrNull()?.controller())
toolbar.navigationIcon = if (router.backstackSize > 1) drawerArrow else searchDrawable binding.toolbar.navigationIcon = if (router.backstackSize > 1) drawerArrow else searchDrawable
(router.backstack.lastOrNull()?.controller() as? BaseController<*>)?.setTitle() (router.backstack.lastOrNull()?.controller() as? BaseController<*>)?.setTitle()
(router.backstack.lastOrNull()?.controller() as? SettingsController)?.setTitle() (router.backstack.lastOrNull()?.controller() as? SettingsController)?.setTitle()
@ -317,7 +315,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
fun setDismissIcon(enabled: Boolean) { fun setDismissIcon(enabled: Boolean) {
toolbar.navigationIcon = if (enabled) dismissDrawable else searchDrawable binding.toolbar.navigationIcon = if (enabled) dismissDrawable else searchDrawable
} }
private fun setNavBarColor(insets: WindowInsets?) { private fun setNavBarColor(insets: WindowInsets?) {
@ -373,10 +371,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
private fun setExtensionsBadge() { private fun setExtensionsBadge() {
val updates = preferences.extensionUpdatesCount().getOrDefault() val updates = preferences.extensionUpdatesCount().getOrDefault()
if (updates > 0) { if (updates > 0) {
val badge = bottom_nav.getOrCreateBadge(R.id.nav_browse) val badge = binding.bottomNav.getOrCreateBadge(R.id.nav_browse)
badge.number = updates badge.number = updates
} else { } else {
bottom_nav.removeBadge(R.id.nav_browse) binding.bottomNav.removeBadge(R.id.nav_browse)
} }
} }
@ -392,7 +390,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
if (router.backstackSize == 1 && this !is SearchActivity && if (router.backstackSize == 1 && this !is SearchActivity &&
downloadManager.hasQueue() && !preferences.shownDownloadQueueTutorial().get() downloadManager.hasQueue() && !preferences.shownDownloadQueueTutorial().get()
) { ) {
val recentsItem = bottom_nav.getItemView(R.id.nav_recents) ?: return val recentsItem = binding.bottomNav.getItemView(R.id.nav_recents) ?: return
preferences.shownDownloadQueueTutorial().set(true) preferences.shownDownloadQueueTutorial().set(true)
TapTargetView.showFor( TapTargetView.showFor(
this, this,
@ -408,7 +406,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
object : TapTargetView.Listener() { object : TapTargetView.Listener() {
override fun onTargetClick(view: TapTargetView) { override fun onTargetClick(view: TapTargetView) {
super.onTargetClick(view) super.onTargetClick(view)
bottom_nav.selectedItemId = R.id.nav_recents binding.bottomNav.selectedItemId = R.id.nav_recents
} }
} }
) )
@ -472,20 +470,20 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
intent.getIntExtra("groupId", 0) intent.getIntExtra("groupId", 0)
) )
when (intent.action) { when (intent.action) {
SHORTCUT_LIBRARY -> bottom_nav.selectedItemId = R.id.nav_library SHORTCUT_LIBRARY -> binding.bottomNav.selectedItemId = R.id.nav_library
SHORTCUT_RECENTLY_UPDATED, SHORTCUT_RECENTLY_READ -> { SHORTCUT_RECENTLY_UPDATED, SHORTCUT_RECENTLY_READ -> {
bottom_nav.selectedItemId = R.id.nav_recents binding.bottomNav.selectedItemId = R.id.nav_recents
val controller: Controller = when (intent.action) { val controller: Controller = when (intent.action) {
SHORTCUT_RECENTLY_UPDATED -> RecentChaptersController() SHORTCUT_RECENTLY_UPDATED -> RecentChaptersController()
else -> RecentlyReadController() else -> RecentlyReadController()
} }
router.pushController(controller.withFadeTransaction()) router.pushController(controller.withFadeTransaction())
} }
SHORTCUT_BROWSE -> bottom_nav.selectedItemId = R.id.nav_browse SHORTCUT_BROWSE -> binding.bottomNav.selectedItemId = R.id.nav_browse
SHORTCUT_EXTENSIONS -> { SHORTCUT_EXTENSIONS -> {
bottom_nav.selectedItemId = R.id.nav_browse binding.bottomNav.selectedItemId = R.id.nav_browse
router.popToRoot() router.popToRoot()
bottom_nav.post { binding.bottomNav.post {
val controller = val controller =
router.backstack.firstOrNull()?.controller() as? SourceController router.backstack.firstOrNull()?.controller() as? SourceController
controller?.showSheet() controller?.showSheet()
@ -493,13 +491,13 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
SHORTCUT_MANGA -> { SHORTCUT_MANGA -> {
val extras = intent.extras ?: return false val extras = intent.extras ?: return false
if (router.backstack.isEmpty()) bottom_nav.selectedItemId = R.id.nav_library if (router.backstack.isEmpty()) binding.bottomNav.selectedItemId = R.id.nav_library
router.pushController(MangaDetailsController(extras).withFadeTransaction()) router.pushController(MangaDetailsController(extras).withFadeTransaction())
} }
SHORTCUT_DOWNLOADS -> { SHORTCUT_DOWNLOADS -> {
bottom_nav.selectedItemId = R.id.nav_recents binding.bottomNav.selectedItemId = R.id.nav_recents
router.popToRoot() router.popToRoot()
bottom_nav.post { binding.bottomNav.post {
val controller = val controller =
router.backstack.firstOrNull()?.controller() as? RecentsController router.backstack.firstOrNull()?.controller() as? RecentsController
controller?.showSheet() controller?.showSheet()
@ -513,7 +511,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
DownloadService.removeListener(this) DownloadService.removeListener(this)
toolbar?.setNavigationOnClickListener(null) binding.toolbar.setNavigationOnClickListener(null)
} }
override fun onBackPressed() { override fun onBackPressed() {
@ -522,7 +520,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
else !router.handleBack() else !router.handleBack()
) { ) {
if (preferences.backReturnsToStart().get() && this !is SearchActivity && if (preferences.backReturnsToStart().get() && this !is SearchActivity &&
startingTab() != bottom_nav?.selectedItemId startingTab() != binding.bottomNav.selectedItemId
) { ) {
goToStartingTab() goToStartingTab()
} else { } else {
@ -536,12 +534,11 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
private fun setStartingTab() { private fun setStartingTab() {
if (bottom_nav?.selectedItemId != R.id.nav_browse && if (binding.bottomNav.selectedItemId != R.id.nav_browse &&
bottom_nav?.selectedItemId != null &&
preferences.startingTab().get() >= 0 preferences.startingTab().get() >= 0
) { ) {
preferences.startingTab().set( preferences.startingTab().set(
when (bottom_nav?.selectedItemId) { when (binding.bottomNav.selectedItemId) {
R.id.nav_library -> 0 R.id.nav_library -> 0
else -> 1 else -> 1
} }
@ -560,7 +557,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
private fun goToStartingTab() { private fun goToStartingTab() {
bottom_nav.selectedItemId = startingTab() binding.bottomNav.selectedItemId = startingTab()
} }
private fun setRoot(controller: Controller, id: Int) { private fun setRoot(controller: Controller, id: Int) {
@ -620,27 +617,27 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
val onRoot = router.backstackSize == 1 val onRoot = router.backstackSize == 1
if (onRoot) { if (onRoot) {
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
toolbar.navigationIcon = searchDrawable binding.toolbar.navigationIcon = searchDrawable
} else { } else {
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
toolbar.navigationIcon = drawerArrow binding.toolbar.navigationIcon = drawerArrow
} }
drawerArrow?.progress = 1f drawerArrow?.progress = 1f
bottom_nav.visibility = if (!hideBottomNav) View.VISIBLE else bottom_nav.visibility binding.bottomNav.visibility = if (!hideBottomNav) View.VISIBLE else binding.bottomNav.visibility
animationSet?.cancel() animationSet?.cancel()
animationSet = AnimatorSet() animationSet = AnimatorSet()
val alphaAnimation = ValueAnimator.ofFloat( val alphaAnimation = ValueAnimator.ofFloat(
bottom_nav.alpha, binding.bottomNav.alpha,
if (hideBottomNav) 0f else 1f if (hideBottomNav) 0f else 1f
) )
alphaAnimation.addUpdateListener { valueAnimator -> alphaAnimation.addUpdateListener { valueAnimator ->
bottom_nav.alpha = valueAnimator.animatedValue as Float binding.bottomNav.alpha = valueAnimator.animatedValue as Float
} }
alphaAnimation.addListener( alphaAnimation.addListener(
EndAnimatorListener { EndAnimatorListener {
bottom_nav.visibleIf(!hideBottomNav) binding.bottomNav.visibleIf(!hideBottomNav)
bottom_view.visibility = if (hideBottomNav) View.GONE else bottom_view.visibility binding.bottomView.visibility = if (hideBottomNav) View.GONE else binding.bottomView.visibility
} }
) )
alphaAnimation.duration = 200 alphaAnimation.duration = 200
@ -653,10 +650,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
val hasQueue = downloading || downloadManager.hasQueue() val hasQueue = downloading || downloadManager.hasQueue()
launchUI { launchUI {
if (hasQueue) { if (hasQueue) {
bottom_nav?.getOrCreateBadge(R.id.nav_recents) binding.bottomNav.getOrCreateBadge(R.id.nav_recents)
showDLQueueTutorial() showDLQueueTutorial()
} else { } else {
bottom_nav?.removeBadge(R.id.nav_recents) binding.bottomNav.removeBadge(R.id.nav_recents)
} }
} }
} }
@ -677,7 +674,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
val diffX = e2.x - e1.x val diffX = e2.x - e1.x
if (abs(diffX) <= abs(diffY)) { if (abs(diffX) <= abs(diffY)) {
val sheetRect = Rect() val sheetRect = Rect()
bottom_nav.getGlobalVisibleRect(sheetRect) binding.bottomNav.getGlobalVisibleRect(sheetRect)
if (sheetRect.contains(e1.x.toInt(), e1.y.toInt()) && if (sheetRect.contains(e1.x.toInt(), e1.y.toInt()) &&
abs(diffY) > Companion.SWIPE_THRESHOLD && abs(diffY) > Companion.SWIPE_THRESHOLD &&
abs(velocityY) > Companion.SWIPE_VELOCITY_THRESHOLD && abs(velocityY) > Companion.SWIPE_VELOCITY_THRESHOLD &&
@ -720,7 +717,7 @@ interface BottomNavBarInterface {
interface RootSearchInterface { interface RootSearchInterface {
fun expandSearch() { fun expandSearch() {
if (this is Controller) activity?.toolbar?.menu?.findItem(R.id.action_search) if (this is Controller) (activity as? MainActivity)?.binding?.toolbar?.menu?.findItem(R.id.action_search)
?.expandActionView() ?.expandActionView()
} }
} }

View File

@ -16,14 +16,13 @@ import eu.kanade.tachiyomi.ui.setting.SettingsReaderController
import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import kotlinx.android.synthetic.main.main_activity.*
class SearchActivity : MainActivity() { class SearchActivity : MainActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
toolbar?.navigationIcon = drawerArrow binding.toolbar?.navigationIcon = drawerArrow
toolbar?.setNavigationOnClickListener { binding.toolbar?.setNavigationOnClickListener {
popToRoot() popToRoot()
} }
} }
@ -56,10 +55,11 @@ class SearchActivity : MainActivity() {
if (from is DialogController || to is DialogController) { if (from is DialogController || to is DialogController) {
return return
} }
toolbar.navigationIcon = drawerArrow binding.toolbar.navigationIcon = drawerArrow
drawerArrow?.progress = 1f drawerArrow?.progress = 1f
bottom_nav.gone() binding.bottomNav.gone()
binding.bottomView.gone()
} }
override fun handleIntentAction(intent: Intent): Boolean { override fun handleIntentAction(intent: Intent): Boolean {

View File

@ -92,6 +92,7 @@ import eu.kanade.tachiyomi.util.system.isInNightMode
import eu.kanade.tachiyomi.util.system.isOnline import eu.kanade.tachiyomi.util.system.isOnline
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.getText import eu.kanade.tachiyomi.util.view.getText
import eu.kanade.tachiyomi.util.view.requestPermissionsSafe import eu.kanade.tachiyomi.util.view.requestPermissionsSafe
import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.scrollViewWith
@ -199,7 +200,7 @@ class MangaDetailsController :
setPaletteColor() setPaletteColor()
adapter?.fastScroller = fast_scroller adapter?.fastScroller = fast_scroller
fast_scroller.addOnScrollStateChangeListener { fast_scroller.addOnScrollStateChangeListener {
activity?.appbar?.y = 0f activityBinding?.appBar?.y = 0f
} }
presenter.onCreate() presenter.onCreate()
@ -234,7 +235,7 @@ class MangaDetailsController :
val offset = 10.dpToPx val offset = 10.dpToPx
swipe_refresh.setStyle() swipe_refresh.setStyle()
swipe_refresh.setDistanceToTriggerSync(70.dpToPx) swipe_refresh.setDistanceToTriggerSync(70.dpToPx)
activity!!.appbar.elevation = 0f activityBinding!!.appBar.elevation = 0f
scrollViewWith( scrollViewWith(
recycler, recycler,
@ -365,13 +366,14 @@ class MangaDetailsController :
/** Set toolbar theme for themes that are inverted (ie. light blue theme) */ /** Set toolbar theme for themes that are inverted (ie. light blue theme) */
private fun setActionBar(forThis: Boolean) { private fun setActionBar(forThis: Boolean) {
val activity = activity ?: return val activity = activity as? MainActivity ?: return
val activityBinding = activityBinding ?: return
// if the theme is using inverted toolbar color // if the theme is using inverted toolbar color
if (!activity.isInNightMode() && ThemeUtil.isBlueTheme(presenter.preferences.theme())) { if (!activity.isInNightMode() && ThemeUtil.isBlueTheme(presenter.preferences.theme())) {
if (forThis) (activity as MainActivity).appbar.context.setTheme( if (forThis) activityBinding.appBar.context.setTheme(
R.style.ThemeOverlay_AppCompat_DayNight_ActionBar R.style.ThemeOverlay_AppCompat_DayNight_ActionBar
) )
else (activity as MainActivity).appbar.context.setTheme( else activityBinding.appBar.context.setTheme(
R.style.Theme_ActionBar_Dark_DayNight R.style.Theme_ActionBar_Dark_DayNight
) )
@ -399,8 +401,8 @@ class MangaDetailsController :
(activity as MainActivity).toolbar.setBackgroundColor(translucentColor) (activity as MainActivity).toolbar.setBackgroundColor(translucentColor)
translucentColor translucentColor
} else Color.TRANSPARENT } else Color.TRANSPARENT
(activity as MainActivity).appbar.setBackgroundColor(Color.TRANSPARENT) activityBinding?.appBar?.setBackgroundColor(Color.TRANSPARENT)
(activity as MainActivity).toolbar.setBackgroundColor( activityBinding?.toolbar?.setBackgroundColor(
activity?.window?.statusBarColor activity?.window?.statusBarColor
?: Color.TRANSPARENT ?: Color.TRANSPARENT
) )
@ -450,8 +452,8 @@ class MangaDetailsController :
if (router.backstackSize > 0 && if (router.backstackSize > 0 &&
router.backstack.last().controller() !is MangaDetailsController router.backstack.last().controller() !is MangaDetailsController
) { ) {
(activity as? MainActivity)?.appbar?.setBackgroundColor(colorSecondary) activityBinding?.appBar?.setBackgroundColor(colorSecondary)
(activity as? MainActivity)?.toolbar?.setBackgroundColor(colorSecondary) activityBinding?.toolbar?.setBackgroundColor(colorSecondary)
activity?.window?.statusBarColor = activity?.getResourceColor( activity?.window?.statusBarColor = activity?.getResourceColor(
android.R.attr.statusBarColor android.R.attr.statusBarColor
@ -975,7 +977,7 @@ class MangaDetailsController :
override fun updateScroll() { override fun updateScroll() {
if (recycler?.canScrollVertically(-1) == false) { if (recycler?.canScrollVertically(-1) == false) {
getHeader()?.backdrop?.translationY = 0f getHeader()?.backdrop?.translationY = 0f
activity?.appbar?.y = 0f activityBinding?.appBar?.y = 0f
colorToolbar(isColor = false, animate = false) colorToolbar(isColor = false, animate = false)
} }
} }
@ -1377,10 +1379,10 @@ class MangaDetailsController :
expandedImageView.requestLayout() expandedImageView.requestLayout()
val activity = activity as? MainActivity ?: return val activity = activity as? MainActivity ?: return
val currTheme = activity.appbar.context.theme val currTheme = activityBinding!!.appBar.context.theme
val currColor = activity.drawerArrow?.color val currColor = activity.drawerArrow?.color
if (!activity.isInNightMode()) { if (!activity.isInNightMode()) {
activity.appbar.context.setTheme(R.style.ThemeOverlay_AppCompat_Dark_ActionBar) activityBinding?.appBar?.context?.setTheme(R.style.ThemeOverlay_AppCompat_Dark_ActionBar)
val iconPrimary = Color.WHITE val iconPrimary = Color.WHITE
activity.toolbar.setTitleTextColor(iconPrimary) activity.toolbar.setTitleTextColor(iconPrimary)
@ -1474,7 +1476,7 @@ class MangaDetailsController :
interpolator = DecelerateInterpolator() interpolator = DecelerateInterpolator()
if (!activity.isInNightMode()) { if (!activity.isInNightMode()) {
activity.appbar.context.setTheme( activityBinding?.appBar?.context?.setTheme(
ThemeUtil.theme(presenter.preferences.theme()) ThemeUtil.theme(presenter.preferences.theme())
) )

View File

@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.ui.recently_read.RemoveHistoryDialog
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.spToPx import eu.kanade.tachiyomi.util.system.spToPx
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isExpanded
import eu.kanade.tachiyomi.util.view.requestPermissionsSafe import eu.kanade.tachiyomi.util.view.requestPermissionsSafe
@ -163,12 +164,12 @@ class RecentsController(bundle: Bundle? = null) :
val shadow2 = shadow2 ?: return val shadow2 = shadow2 ?: return
shadow2.alpha = (1 - abs(progress)) * 0.25f shadow2.alpha = (1 - abs(progress)) * 0.25f
shadow.alpha = (1 - abs(progress)) * 0.5f shadow.alpha = (1 - abs(progress)) * 0.5f
if (progress >= 0) activity?.appbar?.elevation = max( if (progress >= 0) activityBinding?.appBar?.elevation = max(
progress * 15f, progress * 15f,
if (recycler.canScrollVertically(-1)) 15f else 0f if (recycler.canScrollVertically(-1)) 15f else 0f
) )
sheet_layout.alpha = 1 - progress sheet_layout.alpha = 1 - progress
activity?.appbar?.y = max(activity!!.appbar.y, -headerHeight * (1 - progress)) activityBinding?.appBar?.y = max(activityBinding!!.appBar.y, -headerHeight * (1 - progress))
val oldShow = showingDownloads val oldShow = showingDownloads
showingDownloads = progress > 0.92f showingDownloads = progress > 0.92f
if (oldShow != showingDownloads) { if (oldShow != showingDownloads) {
@ -179,7 +180,7 @@ class RecentsController(bundle: Bundle? = null) :
override fun onStateChanged(p0: View, state: Int) { override fun onStateChanged(p0: View, state: Int) {
if (this@RecentsController.view == null) return if (this@RecentsController.view == null) return
if (state == BottomSheetBehavior.STATE_EXPANDED) activity?.appbar?.y = 0f if (state == BottomSheetBehavior.STATE_EXPANDED) activityBinding?.appBar?.y = 0f
if (state == BottomSheetBehavior.STATE_EXPANDED || state == BottomSheetBehavior.STATE_COLLAPSED) { if (state == BottomSheetBehavior.STATE_EXPANDED || state == BottomSheetBehavior.STATE_COLLAPSED) {
sheet_layout.alpha = sheet_layout.alpha =
if (state == BottomSheetBehavior.STATE_COLLAPSED) 1f else 0f if (state == BottomSheetBehavior.STATE_COLLAPSED) 1f else 0f

View File

@ -3,12 +3,13 @@ package eu.kanade.tachiyomi.ui.security
import android.os.Bundle import android.os.Bundle
import androidx.biometric.BiometricPrompt import androidx.biometric.BiometricPrompt
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.MainActivityBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import java.util.Date import java.util.Date
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors import java.util.concurrent.Executors
class BiometricActivity : BaseActivity() { class BiometricActivity : BaseActivity<MainActivityBinding>() {
private val executor: ExecutorService = Executors.newSingleThreadExecutor() private val executor: ExecutorService = Executors.newSingleThreadExecutor()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -41,6 +41,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.spToPx import eu.kanade.tachiyomi.util.system.spToPx
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.isCollapsed import eu.kanade.tachiyomi.util.view.isCollapsed
@ -172,11 +173,11 @@ class SourceController :
override fun onSlide(bottomSheet: View, progress: Float) { override fun onSlide(bottomSheet: View, progress: Float) {
val recycler = recycler ?: return val recycler = recycler ?: return
shadow2?.alpha = (1 - max(0f, progress)) * 0.25f shadow2?.alpha = (1 - max(0f, progress)) * 0.25f
activity?.appbar?.elevation = min( activityBinding?.appBar?.elevation = min(
(1f - progress) * 15f, (1f - progress) * 15f,
if (recycler.canScrollVertically(-1)) 15f else 0f if (recycler.canScrollVertically(-1)) 15f else 0f
) )
activity?.appbar?.y = max(activity!!.appbar.y, -headerHeight * (1 - progress)) activityBinding?.appBar?.y = max(activityBinding!!.appBar.y, -headerHeight * (1 - progress))
val oldShow = showingExtensions val oldShow = showingExtensions
showingExtensions = progress > 0.92f showingExtensions = progress > 0.92f
if (oldShow != showingExtensions) { if (oldShow != showingExtensions) {
@ -189,7 +190,7 @@ class SourceController :
override fun onStateChanged(p0: View, state: Int) { override fun onStateChanged(p0: View, state: Int) {
val extBottomSheet = ext_bottom_sheet ?: return val extBottomSheet = ext_bottom_sheet ?: return
if (state == BottomSheetBehavior.STATE_EXPANDED) { if (state == BottomSheetBehavior.STATE_EXPANDED) {
activity?.appbar?.y = 0f activityBinding?.appBar?.y = 0f
} }
if (state == BottomSheetBehavior.STATE_EXPANDED || if (state == BottomSheetBehavior.STATE_EXPANDED ||
state == BottomSheetBehavior.STATE_COLLAPSED state == BottomSheetBehavior.STATE_COLLAPSED
@ -227,7 +228,7 @@ class SourceController :
fun setBottomSheetTabs(progress: Float) { fun setBottomSheetTabs(progress: Float) {
val bottomSheet = ext_bottom_sheet ?: return val bottomSheet = ext_bottom_sheet ?: return
ext_bottom_sheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> { ext_bottom_sheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = ((activity?.appbar?.height?.minus(9f.dpToPx) ?: 0f) * progress).toInt() topMargin = ((activityBinding?.appBar?.height?.minus(9f.dpToPx) ?: 0f) * progress).toInt()
} }
val selectedColor = ColorUtils.setAlphaComponent( val selectedColor = ColorUtils.setAlphaComponent(
ContextCompat.getColor(ext_bottom_sheet.tabs.context, R.color.colorAccent), ContextCompat.getColor(ext_bottom_sheet.tabs.context, R.color.colorAccent),
@ -320,7 +321,7 @@ class SourceController :
} }
if (!type.isEnter) { if (!type.isEnter) {
ext_bottom_sheet.canExpand = false ext_bottom_sheet.canExpand = false
activity?.appbar?.elevation = activityBinding?.appBar?.elevation =
when { when {
ext_bottom_sheet.sheetBehavior.isExpanded() -> 0f ext_bottom_sheet.sheetBehavior.isExpanded() -> 0f
recycler.canScrollVertically(-1) -> 15f recycler.canScrollVertically(-1) -> 15f

View File

@ -12,6 +12,7 @@ import android.webkit.WebView
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.util.system.ThemeUtil import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
@ -26,7 +27,7 @@ import eu.kanade.tachiyomi.util.view.updatePadding
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.webview_activity.* import kotlinx.android.synthetic.main.webview_activity.*
open class BaseWebViewActivity : BaseActivity() { open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
private var bundle: Bundle? = null private var bundle: Bundle? = null

View File

@ -25,13 +25,14 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.MainActivityBinding
import eu.kanade.tachiyomi.ui.main.BottomSheetController import eu.kanade.tachiyomi.ui.main.BottomSheetController
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.main_activity.*
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import kotlin.math.abs import kotlin.math.abs
@ -77,11 +78,11 @@ fun Controller.liftAppbarWith(recycler: RecyclerView) {
elevate = el elevate = el
elevationAnim?.cancel() elevationAnim?.cancel()
elevationAnim = ValueAnimator.ofFloat( elevationAnim = ValueAnimator.ofFloat(
activity?.appbar?.elevation ?: 0f, activityBinding?.appBar?.elevation ?: 0f,
if (el) 15f else 0f if (el) 15f else 0f
) )
elevationAnim?.addUpdateListener { valueAnimator -> elevationAnim?.addUpdateListener { valueAnimator ->
activity?.appbar?.elevation = valueAnimator.animatedValue as Float activityBinding?.appBar?.elevation = valueAnimator.animatedValue as Float
} }
elevationAnim?.start() elevationAnim?.start()
} }
@ -112,7 +113,7 @@ fun Controller.scrollViewWith(
onBottomNavUpdate: (() -> Unit)? = null onBottomNavUpdate: (() -> Unit)? = null
): ((Boolean) -> Unit) { ): ((Boolean) -> Unit) {
var statusBarHeight = -1 var statusBarHeight = -1
activity?.appbar?.y = 0f activityBinding?.appBar?.y = 0f
val attrsArray = intArrayOf(R.attr.actionBarSize) val attrsArray = intArrayOf(R.attr.actionBarSize)
val array = recycler.context.obtainStyledAttributes(attrsArray) val array = recycler.context.obtainStyledAttributes(attrsArray)
var appBarHeight = if (activity!!.toolbar.height > 0) activity!!.toolbar.height var appBarHeight = if (activity!!.toolbar.height > 0) activity!!.toolbar.height
@ -166,11 +167,11 @@ fun Controller.scrollViewWith(
} else { } else {
elevationAnim?.cancel() elevationAnim?.cancel()
elevationAnim = ValueAnimator.ofFloat( elevationAnim = ValueAnimator.ofFloat(
activity?.appbar?.elevation ?: 0f, activityBinding?.appBar?.elevation ?: 0f,
if (el) 15f else 0f if (el) 15f else 0f
) )
elevationAnim?.addUpdateListener { valueAnimator -> elevationAnim?.addUpdateListener { valueAnimator ->
activity?.appbar?.elevation = valueAnimator.animatedValue as Float activityBinding?.appBar?.elevation = valueAnimator.animatedValue as Float
} }
elevationAnim?.start() elevationAnim?.start()
} }
@ -247,14 +248,14 @@ fun Controller.scrollViewWith(
super.onScrolled(recyclerView, dx, dy) super.onScrolled(recyclerView, dx, dy)
if (router?.backstack?.lastOrNull() if (router?.backstack?.lastOrNull()
?.controller() == this@scrollViewWith && statusBarHeight > -1 && ?.controller() == this@scrollViewWith && statusBarHeight > -1 &&
activity != null && activity!!.appbar.height > 0 && activity != null && activityBinding!!.appBar.height > 0 &&
recycler.translationY == 0f recycler.translationY == 0f
) { ) {
if (!recycler.canScrollVertically(-1)) { if (!recycler.canScrollVertically(-1)) {
val shortAnimationDuration = resources?.getInteger( val shortAnimationDuration = resources?.getInteger(
android.R.integer.config_shortAnimTime android.R.integer.config_shortAnimTime
) ?: 0 ) ?: 0
activity!!.appbar.animate().y(0f) activityBinding!!.appBar.animate().y(0f)
.setDuration(shortAnimationDuration.toLong()) .setDuration(shortAnimationDuration.toLong())
.start() .start()
if (router.backstackSize == 1 && isInView) { if (router.backstackSize == 1 && isInView) {
@ -270,15 +271,14 @@ fun Controller.scrollViewWith(
lastY = 0f lastY = 0f
if (elevate) elevateFunc(false) if (elevate) elevateFunc(false)
} else { } else {
activity!!.appbar.y -= dy activityBinding!!.appBar.y -= dy
activity!!.appbar.y = MathUtils.clamp( activityBinding!!.appBar.y = MathUtils.clamp(
activity!!.appbar.y, activityBinding!!.appBar.y,
-activity!!.appbar.height.toFloat(), -activityBinding!!.appBar.height.toFloat(),
0f 0f
) )
val tabBar = activity!!.bottom_nav val tabBar = activity!!.bottom_nav
if (tabBar != null && tabBar.isVisible() && isInView) { if (tabBar != null && tabBar.isVisible() && isInView) {
val preferences: PreferencesHelper = Injekt.get()
if (preferences.hideBottomNavOnScroll().get()) { if (preferences.hideBottomNavOnScroll().get()) {
tabBar.translationY += dy tabBar.translationY += dy
tabBar.translationY = MathUtils.clamp( tabBar.translationY = MathUtils.clamp(
@ -295,14 +295,14 @@ fun Controller.scrollViewWith(
if (!elevate && ( if (!elevate && (
dy == 0 || dy == 0 ||
( (
activity!!.appbar.y <= -activity!!.appbar.height.toFloat() || activityBinding!!.appBar.y <= -activityBinding!!.appBar.height.toFloat() ||
dy == 0 && activity!!.appbar.y == 0f dy == 0 && activityBinding!!.appBar.y == 0f
) )
) )
) { ) {
elevateFunc(true) elevateFunc(true)
} }
lastY = activity!!.appbar.y lastY = activityBinding!!.appBar.y
} }
} }
} }
@ -312,14 +312,14 @@ fun Controller.scrollViewWith(
if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (newState == RecyclerView.SCROLL_STATE_IDLE) {
if (router?.backstack?.lastOrNull() if (router?.backstack?.lastOrNull()
?.controller() == this@scrollViewWith && statusBarHeight > -1 && ?.controller() == this@scrollViewWith && statusBarHeight > -1 &&
activity != null && activity!!.appbar.height > 0 && activity != null && activityBinding!!.appBar.height > 0 &&
recycler.translationY == 0f recycler.translationY == 0f
) { ) {
val halfWay = activity!!.appbar.height.toFloat() / 2 val halfWay = activityBinding!!.appBar.height.toFloat() / 2
val shortAnimationDuration = resources?.getInteger( val shortAnimationDuration = resources?.getInteger(
android.R.integer.config_shortAnimTime android.R.integer.config_shortAnimTime
) ?: 0 ) ?: 0
val closerToTop = abs(activity!!.appbar.y) > halfWay val closerToTop = abs(activityBinding!!.appBar.y) > halfWay
val halfWayBottom = activity!!.bottom_nav.height.toFloat() / 2 val halfWayBottom = activity!!.bottom_nav.height.toFloat() / 2
val closerToBottom = activity!!.bottom_nav.translationY > halfWayBottom val closerToBottom = activity!!.bottom_nav.translationY > halfWayBottom
val atTop = !recycler.canScrollVertically(-1) val atTop = !recycler.canScrollVertically(-1)
@ -328,8 +328,8 @@ fun Controller.scrollViewWith(
preferences.hideBottomNavOnScroll().get() preferences.hideBottomNavOnScroll().get()
) closerToBottom else closerToTop ) closerToBottom else closerToTop
lastY = lastY =
if (closerToEdge && !atTop) (-activity!!.appbar.height.toFloat()) else 0f if (closerToEdge && !atTop) (-activityBinding!!.appBar.height.toFloat()) else 0f
activity!!.appbar.animate().y(lastY) activityBinding!!.appBar.animate().y(lastY)
.setDuration(shortAnimationDuration.toLong()).start() .setDuration(shortAnimationDuration.toLong()).start()
if (activity!!.bottom_nav.isVisible && isInView && preferences.hideBottomNavOnScroll().get()) { if (activity!!.bottom_nav.isVisible && isInView && preferences.hideBottomNavOnScroll().get()) {
activity!!.bottom_nav?.let { activity!!.bottom_nav?.let {
@ -376,3 +376,6 @@ fun Controller.openInBrowser(url: String) {
activity?.toast(e.message) activity?.toast(e.message)
} }
} }
val Controller.activityBinding: MainActivityBinding?
get() = (activity as? MainActivity)?.binding

View File

@ -21,7 +21,7 @@
</com.bluelinelabs.conductor.ChangeHandlerFrameLayout> </com.bluelinelabs.conductor.ChangeHandlerFrameLayout>
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" android:id="@+id/app_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/colorSecondary" android:background="?attr/colorSecondary"