feat: App bar mode is also reflected in Home tab and Settings now (Compact / Expanded)

This commit is contained in:
Prathamesh More 2023-03-09 12:08:26 +05:30
parent 210d9afa1a
commit bb99213848
10 changed files with 24 additions and 102 deletions

View file

@ -45,7 +45,7 @@ android {
versionNameSuffix ' DEBUG'
}
}
flavorDimensions "version"
flavorDimensions = ["version"]
productFlavors {
normal {
dimension "version"

View file

@ -147,8 +147,10 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (_binding != null) {
outState.putParcelable(CRUMBS, binding.breadCrumbs.stateWrapper)
}
}
private fun setUpTitle() {
toolbar.setNavigationOnClickListener {

View file

@ -9,7 +9,7 @@ class HomeBinding(
val container = homeBinding.container
val contentContainer = homeBinding.contentContainer
val appBarLayout = homeBinding.appBarLayout
val toolbar = homeBinding.toolbar
val toolbar = homeBinding.appBarLayout.toolbar
val bannerImage = homeBinding.imageLayout.bannerImage
val userImage = homeBinding.imageLayout.userImage
val lastAdded = homeBinding.homeContent.absPlaylists.lastAdded
@ -18,6 +18,5 @@ class HomeBinding(
val history = homeBinding.homeContent.absPlaylists.history
val recyclerView = homeBinding.homeContent.recyclerView
val titleWelcome = homeBinding.imageLayout.titleWelcome
val appNameText = homeBinding.appNameText
val suggestions = homeBinding.homeContent.suggestions
}

View file

@ -179,7 +179,7 @@ class HomeFragment :
}
val hexColor = String.format("#%06X", 0xFFFFFF and accentColor())
val appName = "Retro <span style='color:$hexColor';>Music</span>".parseAsHtml()
binding.appNameText.text = appName
binding.appBarLayout.title = appName
}
private fun loadProfile() {

View file

@ -17,6 +17,7 @@ package code.name.monkey.retromusic.fragments.settings
import android.os.Bundle
import android.view.View
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
import code.name.monkey.retromusic.APPBAR_MODE
import code.name.monkey.retromusic.HOME_ALBUM_GRID_STYLE
import code.name.monkey.retromusic.HOME_ARTIST_GRID_STYLE
import code.name.monkey.retromusic.R
@ -47,5 +48,10 @@ class PersonalizeSettingsFragment : AbsSettingsFragment() {
setSummary(prefs, newValue)
true
}
val appBarMode: ATEListPreference? = findPreference(APPBAR_MODE)
appBarMode?.setOnPreferenceChangeListener { _, _ ->
restartActivity()
true
}
}
}

View file

@ -39,14 +39,11 @@ class SettingsFragment : Fragment(R.layout.fragment_settings), ColorCallback {
}
private fun setupToolbar() {
applyToolbar(binding.toolbar)
binding.toolbar.setNavigationOnClickListener {
requireActivity().onBackPressedDispatcher.onBackPressed()
}
val navController: NavController = findNavController(R.id.contentFrame)
binding.appBarLayout.toolbar.setNavigationIcon(R.drawable.ic_arrow_back)
navController.addOnDestinationChangedListener { _, _, _ ->
binding.collapsingToolbarLayout.title =
navController.currentDestination?.let { getStringFromDestination(it) }
binding.appBarLayout.title =
navController.currentDestination?.let { getStringFromDestination(it) }.toString()
}
}

View file

@ -59,7 +59,7 @@ class TopAppBarLayout @JvmOverloads constructor(
simpleAppbarBinding?.toolbar!!
}
var title: String
var title: CharSequence
get() = if (mode == AppBarMode.COLLAPSING) {
collapsingAppbarBinding?.collapsingToolbarLayout?.title.toString()
} else {

View file

@ -18,42 +18,12 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
<code.name.monkey.retromusic.views.TopAppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_search"
app:popupTheme="?attr/toolbarPopupTheme"
app:title="@null"
tools:ignore="UnusedAttribute">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/appNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold" />
</androidx.appcompat.widget.Toolbar>
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height" />
</FrameLayout>
</com.google.android.material.appbar.AppBarLayout>
app:liftOnScroll="true" />
<androidx.core.widget.NestedScrollView
android:id="@+id/container"

View file

@ -18,42 +18,13 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
<code.name.monkey.retromusic.views.TopAppBarLayout
android:id="@+id/appBarLayout"
style="?appBarLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_search"
app:popupTheme="?attr/toolbarPopupTheme"
app:title="@null"
tools:ignore="UnusedAttribute">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/appNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold" />
</androidx.appcompat.widget.Toolbar>
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height" />
</FrameLayout>
</com.google.android.material.appbar.AppBarLayout>
android:theme="@style/CenteredCheckBoxTheme" />
<androidx.core.widget.NestedScrollView
android:id="@+id/container"

View file

@ -16,34 +16,11 @@
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
app:navGraph="@navigation/settings_graph" />
<com.google.android.material.appbar.AppBarLayout
<code.name.monkey.retromusic.views.TopAppBarLayout
android:id="@+id/appBarLayout"
style="?appBarLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
style="?attr/collapsingToolbarLayoutLargeStyle"
android:layout_width="match_parent"
android:layout_height="?attr/collapsingToolbarLayoutLargeSize"
app:collapsedTitleTextAppearance="@style/TextViewHeadline6"
app:expandedTitleMarginBottom="24dp"
app:expandedTitleMarginEnd="24dp"
app:expandedTitleMarginStart="24dp"
app:expandedTitleTextAppearance="@style/TextViewHeadline4"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlwaysCollapsed">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_collapseMode="pin"
app:navigationIcon="@drawable/ic_arrow_back"
app:titleTextAppearance="@style/ToolbarTextAppearanceNormal"
tools:title="@string/action_settings" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
android:theme="@style/CenteredCheckBoxTheme" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>