home: make edge-to-edge
Make the home fragment span from edge-to-edge. This also adds a nice effect for the toolbar to fade out when it collapses.
This commit is contained in:
parent
c5b1d7d735
commit
e142c17fca
4 changed files with 26 additions and 4 deletions
|
@ -22,11 +22,13 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import org.oxycblt.auxio.databinding.FragmentMainBinding
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.util.applyEdge
|
||||
import org.oxycblt.auxio.util.isLandscape
|
||||
import org.oxycblt.auxio.util.logD
|
||||
|
||||
|
@ -49,6 +51,10 @@ class MainFragment : Fragment() {
|
|||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.applyEdge { bars ->
|
||||
binding.root.updatePadding(bottom = bars.bottom)
|
||||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
playbackModel.setupPlayback(requireContext())
|
||||
|
|
|
@ -22,12 +22,14 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import org.oxycblt.auxio.MainFragmentDirections
|
||||
import org.oxycblt.auxio.R
|
||||
|
@ -39,6 +41,7 @@ import org.oxycblt.auxio.music.Genre
|
|||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.DisplayMode
|
||||
import org.oxycblt.auxio.util.applyEdge
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logE
|
||||
|
||||
|
@ -67,6 +70,21 @@ class HomeFragment : Fragment() {
|
|||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.applyEdge { bars ->
|
||||
binding.homeAppbar.updatePadding(top = bars.top)
|
||||
}
|
||||
|
||||
// There is basically no way to prevent the toolbar to draw under the status bar when
|
||||
// it collapses, so do the next best thing and fade it out so it doesn't stick out like
|
||||
// a sore thumb. As a side effect, this looks really cool.
|
||||
binding.homeAppbar.addOnOffsetChangedListener(
|
||||
AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
|
||||
binding.homeToolbar.apply {
|
||||
alpha = (height + verticalOffset) / height.toFloat()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
binding.homeToolbar.setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
R.id.action_settings -> {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorSurface"
|
||||
android:clickable="true"
|
||||
android:clipChildren="true"
|
||||
android:elevation="@dimen/elevation_normal"
|
||||
android:focusable="true">
|
||||
|
||||
|
@ -24,7 +25,6 @@
|
|||
android:id="@+id/home_toolbar"
|
||||
style="@style/Widget.Toolbar"
|
||||
android:elevation="0dp"
|
||||
android:fitsSystemWindows="true"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:menu="@menu/menu_home"
|
||||
app:title="@string/info_app_name" />
|
||||
|
@ -33,8 +33,6 @@
|
|||
android:id="@+id/home_tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
app:tabContentStart="@dimen/spacing_medium"
|
||||
app:tabIndicatorColor="?attr/colorAccent"
|
||||
app:tabMode="scrollable"
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
|
@ -27,6 +26,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:elevation="@dimen/elevation_normal"
|
||||
android:clipToPadding="true"
|
||||
android:background="?attr/colorSurface"
|
||||
tools:layout="@layout/fragment_compact_playback" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in a new issue