Fix grid columns on tablets, split out common main_activity layout sections

This commit is contained in:
arkon 2021-05-14 17:48:11 -04:00
parent c68e7c8da7
commit ef53d4ec07
8 changed files with 118 additions and 161 deletions

View File

@ -70,7 +70,7 @@ class BrowseController :
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type) super.onChangeStarted(handler, type)
if (type.isEnter) { if (type.isEnter) {
(activity as? MainActivity)?.binding?.tabs?.apply { (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.apply {
setupWithViewPager(binding.pager) setupWithViewPager(binding.pager)
// Show badge on tab for extension updates // Show badge on tab for extension updates
@ -92,7 +92,7 @@ class BrowseController :
} }
fun setExtensionUpdateBadge() { fun setExtensionUpdateBadge() {
(activity as? MainActivity)?.binding?.tabs?.apply { (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.apply {
val updates = preferences.extensionUpdatesCount().get() val updates = preferences.extensionUpdatesCount().get()
if (updates > 0) { if (updates > 0) {
val badge: BadgeDrawable? = getTabAt(1)?.orCreateBadge val badge: BadgeDrawable? = getTabAt(1)?.orCreateBadge

View File

@ -218,7 +218,7 @@ class LibraryController(
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type) super.onChangeStarted(handler, type)
if (type.isEnter) { if (type.isEnter) {
(activity as? MainActivity)?.binding?.tabs?.setupWithViewPager(binding.libraryPager) (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.setupWithViewPager(binding.libraryPager)
presenter.subscribeLibrary() presenter.subscribeLibrary()
} }
} }
@ -297,7 +297,7 @@ class LibraryController(
// Delay the scroll position to allow the view to be properly measured. // Delay the scroll position to allow the view to be properly measured.
view.post { view.post {
if (isAttached) { if (isAttached) {
(activity as? MainActivity)?.binding?.tabs?.setScrollPosition(binding.libraryPager.currentItem, 0f, true) (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.setScrollPosition(binding.libraryPager.currentItem, 0f, true)
} }
} }

View File

@ -96,16 +96,16 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
} }
setContentView(binding.root) setContentView(binding.root)
setSupportActionBar(binding.toolbar) setSupportActionBar(binding.toolbarLayout.toolbar)
// Draw edge-to-edge // Draw edge-to-edge
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
binding.appbar.applyInsetter { binding.toolbarLayout.appbar.applyInsetter {
type(navigationBars = true, statusBars = true) { type(navigationBars = true, statusBars = true) {
padding(left = true, top = true, right = true) padding(left = true, top = true, right = true)
} }
} }
binding.rootFab.applyInsetter { binding.fabLayout.rootFab.applyInsetter {
type(navigationBars = true) { type(navigationBars = true) {
margin() margin()
} }
@ -131,13 +131,13 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
insets insets
} }
tabAnimator = ViewHeightAnimator(binding.tabs, 0L) tabAnimator = ViewHeightAnimator(binding.toolbarLayout.tabs, 0L)
if (binding.bottomNav != null) { if (binding.bottomNav != null) {
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav!!) bottomNavAnimator = ViewHeightAnimator(binding.bottomNav!!)
// If bottom nav is hidden, make it visible again when the app bar is expanded // If bottom nav is hidden, make it visible again when the app bar is expanded
binding.appbar.addOnOffsetChangedListener( binding.toolbarLayout.appbar.addOnOffsetChangedListener(
AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
if (verticalOffset == 0) { if (verticalOffset == 0) {
showNav(true) showNav(true)
@ -186,7 +186,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
} }
} }
binding.toolbar.setNavigationOnClickListener { binding.toolbarLayout.toolbar.setNavigationOnClickListener {
onBackPressed() onBackPressed()
} }
@ -227,13 +227,13 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
.launchIn(lifecycleScope) .launchIn(lifecycleScope)
preferences.downloadedOnly() preferences.downloadedOnly()
.asImmediateFlow { binding.downloadedOnly.isVisible = it } .asImmediateFlow { binding.toolbarLayout.downloadedOnly.isVisible = it }
.launchIn(lifecycleScope) .launchIn(lifecycleScope)
preferences.incognitoMode().asFlow() preferences.incognitoMode().asFlow()
.drop(1) .drop(1)
.onEach { .onEach {
binding.incognitoMode.isVisible = it binding.toolbarLayout.incognitoMode.isVisible = it
// Close BrowseSourceController and its MangaController child when incognito mode is disabled // Close BrowseSourceController and its MangaController child when incognito mode is disabled
if (!it) { if (!it) {
@ -355,7 +355,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
// Binding sometimes isn't actually instantiated yet somehow // Binding sometimes isn't actually instantiated yet somehow
nav.setOnItemSelectedListener(null) nav.setOnItemSelectedListener(null)
binding?.toolbar.setNavigationOnClickListener(null) binding?.toolbarLayout?.toolbar.setNavigationOnClickListener(null)
} }
override fun onBackPressed() { override fun onBackPressed() {
@ -408,7 +408,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1) supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1)
// Always show appbar again when changing controllers // Always show appbar again when changing controllers
binding.appbar.setExpanded(true) binding.toolbarLayout.appbar.setExpanded(true)
if ((from == null || from is RootController) && to !is RootController) { if ((from == null || from is RootController) && to !is RootController) {
showNav(visible = false, collapse = true) showNav(visible = false, collapse = true)
@ -419,34 +419,34 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
} }
if (from is TabbedController) { if (from is TabbedController) {
from.cleanupTabs(binding.tabs) from.cleanupTabs(binding.toolbarLayout.tabs)
} }
if (to is TabbedController) { if (to is TabbedController) {
tabAnimator.expand() tabAnimator.expand()
to.configureTabs(binding.tabs) to.configureTabs(binding.toolbarLayout.tabs)
} else { } else {
tabAnimator.collapse() tabAnimator.collapse()
binding.tabs.setupWithViewPager(null) binding.toolbarLayout.tabs.setupWithViewPager(null)
} }
if (from is FabController) { if (from is FabController) {
binding.rootFab.isVisible = false binding.fabLayout.rootFab.isVisible = false
from.cleanupFab(binding.rootFab) from.cleanupFab(binding.fabLayout.rootFab)
} }
if (to is FabController) { if (to is FabController) {
binding.rootFab.isVisible = true binding.fabLayout.rootFab.isVisible = true
to.configureFab(binding.rootFab) to.configureFab(binding.fabLayout.rootFab)
} }
when (to) { when (to) {
is NoToolbarElevationController -> { is NoToolbarElevationController -> {
binding.appbar.disableElevation() binding.toolbarLayout.appbar.disableElevation()
} }
is ToolbarLiftOnScrollController -> { is ToolbarLiftOnScrollController -> {
binding.appbar.enableElevation(true) binding.toolbarLayout.appbar.enableElevation(true)
} }
else -> { else -> {
binding.appbar.enableElevation(false) binding.toolbarLayout.appbar.enableElevation(false)
} }
} }
} }
@ -482,16 +482,16 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
*/ */
fun fixViewToBottom(view: View) { fun fixViewToBottom(view: View) {
val listener = AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset -> val listener = AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
val maxAbsOffset = appBarLayout.measuredHeight - binding.tabs.measuredHeight val maxAbsOffset = appBarLayout.measuredHeight - binding.toolbarLayout.tabs.measuredHeight
view.translationY = -maxAbsOffset - verticalOffset.toFloat() + appBarLayout.marginTop view.translationY = -maxAbsOffset - verticalOffset.toFloat() + appBarLayout.marginTop
} }
binding.appbar.addOnOffsetChangedListener(listener) binding.toolbarLayout.appbar.addOnOffsetChangedListener(listener)
fixedViewsToBottom[view] = listener fixedViewsToBottom[view] = listener
} }
fun clearFixViewToBottom(view: View) { fun clearFixViewToBottom(view: View) {
val listener = fixedViewsToBottom.remove(view) val listener = fixedViewsToBottom.remove(view)
binding.appbar.removeOnOffsetChangedListener(listener) binding.toolbarLayout.appbar.removeOnOffsetChangedListener(listener)
} }
private fun setBottomNavBehaviorOnScroll() { private fun setBottomNavBehaviorOnScroll() {

View File

@ -277,7 +277,7 @@ class MangaController :
else -> min(binding.recycler.computeVerticalScrollOffset(), 255) else -> min(binding.recycler.computeVerticalScrollOffset(), 255)
} }
(activity as? MainActivity)?.binding?.toolbar?.setTitleTextColor( (activity as? MainActivity)?.binding?.toolbarLayout?.toolbar?.setTitleTextColor(
Color.argb( Color.argb(
calculatedAlpha, calculatedAlpha,
toolbarTextColor.red, toolbarTextColor.red,

View File

@ -1,71 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_coordinator" android:id="@+id/root_coordinator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout <include
android:id="@+id/appbar" android:id="@+id/toolbar_layout"
android:layout_width="match_parent" layout="@layout/main_activity_toolbar" />
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"
app:layout_scrollFlags="scroll|enterAlways" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
style="@style/Theme.Widget.Tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/downloaded_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="@string/label_downloaded_only"
android:textColor="@color/md_white_1000" />
</FrameLayout>
<FrameLayout
android:id="@+id/incognito_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/md_grey_800"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="@string/pref_incognito_mode"
android:textColor="@color/md_white_1000" />
</FrameLayout>
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> app:layout_behavior="@string/appbar_scrolling_view_behavior">
@ -78,22 +23,24 @@
app:itemIconTint="@color/nav_selector" app:itemIconTint="@color/nav_selector"
app:itemTextColor="@color/nav_selector" app:itemTextColor="@color/nav_selector"
app:labelVisibilityMode="labeled" app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/main_nav" /> app:menu="@menu/main_nav" />
<com.bluelinelabs.conductor.ChangeHandlerFrameLayout <com.bluelinelabs.conductor.ChangeHandlerFrameLayout
android:id="@+id/controller_container" android:id="@+id/controller_container"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" /> app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/side_nav"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton <include
android:id="@+id/root_fab" android:id="@+id/fab_layout"
style="@style/Theme.Widget.FAB" layout="@layout/main_activity_fab" />
android:visibility="gone"
tools:icon="@drawable/ic_add_24dp"
tools:text="Action"
tools:visibility="visible" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,69 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_coordinator" android:id="@+id/root_coordinator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout <include
android:id="@+id/appbar" android:id="@+id/toolbar_layout"
android:layout_width="match_parent" layout="@layout/main_activity_toolbar" />
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"
app:layout_scrollFlags="scroll|enterAlways" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
style="@style/Theme.Widget.Tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/downloaded_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="@string/label_downloaded_only"
android:textColor="@color/md_white_1000" />
</FrameLayout>
<FrameLayout
android:id="@+id/incognito_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/md_grey_800"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="@string/pref_incognito_mode"
android:textColor="@color/md_white_1000" />
</FrameLayout>
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>
<com.bluelinelabs.conductor.ChangeHandlerFrameLayout <com.bluelinelabs.conductor.ChangeHandlerFrameLayout
android:id="@+id/controller_container" android:id="@+id/controller_container"
@ -71,13 +16,9 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton <include
android:id="@+id/root_fab" android:id="@+id/fab_layout"
style="@style/Theme.Widget.FAB" layout="@layout/main_activity_fab" />
android:visibility="gone"
tools:icon="@drawable/ic_add_24dp"
tools:text="Action"
tools:visibility="visible" />
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav" android:id="@+id/bottom_nav"

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_fab"
style="@style/Theme.Widget.FAB"
android:visibility="gone"
tools:icon="@drawable/ic_add_24dp"
tools:text="Action"
tools:visibility="visible" />

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"
app:layout_scrollFlags="scroll|enterAlways" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
style="@style/Theme.Widget.Tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/downloaded_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="@string/label_downloaded_only"
android:textColor="@color/md_white_1000" />
</FrameLayout>
<FrameLayout
android:id="@+id/incognito_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/md_grey_800"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="@string/pref_incognito_mode"
android:textColor="@color/md_white_1000" />
</FrameLayout>
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>