Improve edge-to-edge

Do some weird android styling wizardry to get edge-to-edge working better.
This commit is contained in:
OxygenCobalt 2020-12-01 20:01:03 -07:00
parent 91b8d226c8
commit 0079f41776
9 changed files with 21 additions and 16 deletions

View file

@ -15,12 +15,15 @@ import org.oxycblt.auxio.playback.PlaybackService
import org.oxycblt.auxio.settings.SettingsManager import org.oxycblt.auxio.settings.SettingsManager
import org.oxycblt.auxio.ui.accent import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.handleTransparentSystemBars import org.oxycblt.auxio.ui.handleTransparentSystemBars
import org.oxycblt.auxio.ui.toColor
// FIXME: Fix bug where fast navigation will break the animations and // FIXME: Fix bug where fast navigation will break the animations and
// lead to nothing being displayed [Possibly Un-fixable] // lead to nothing being displayed [Possibly Un-fixable]
// TODO: Landscape UI layouts // TODO: Landscape UI layouts
// FIXME: Compat issue with Versions 5 that leads to progress bar looking off // FIXME: Compat issue with Versions 5 that leads to progress bar looking off
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -45,13 +48,14 @@ class MainActivity : AppCompatActivity() {
if (settingsManager.getEdgeToEdge() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (settingsManager.getEdgeToEdge() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
window?.apply { window?.apply {
statusBarColor = Color.TRANSPARENT statusBarColor = Color.TRANSPARENT
navigationBarColor = R.color.nav_color.toColor(this@MainActivity)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Log.d(this::class.simpleName, "Doing R+ edge-to-edge.") Log.d(this::class.simpleName, "Doing R+ edge-to-edge.")
setDecorFitsSystemWindows(false) setDecorFitsSystemWindows(false)
binding.root.setOnApplyWindowInsetsListener { v, insets -> binding.root.setOnApplyWindowInsetsListener { _, insets ->
WindowInsets.Builder() WindowInsets.Builder()
.setInsets( .setInsets(
WindowInsets.Type.systemBars(), WindowInsets.Type.systemBars(),
@ -60,18 +64,13 @@ class MainActivity : AppCompatActivity() {
.build() .build()
} }
} else { } else {
Log.d(this::class.simpleName, "Doing deprec edge-to-edge.") Log.d(this::class.simpleName, "Doing legacy edge-to-edge.")
binding.root.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or binding.root.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE View.SYSTEM_UI_FLAG_LAYOUT_STABLE
} }
navigationBarColor = Color.TRANSPARENT
handleTransparentSystemBars(resources.configuration) handleTransparentSystemBars(resources.configuration)
// I barely know how insets work so here's another third party library
// that I think does things
// binding.root.applySystemWindowInsetsToMargin(top = false, bottom = false)
} }
} }
} }

View file

@ -120,7 +120,6 @@ class MainFragment : Fragment() {
return binding.root return binding.root
} }
// Functions that check if MainFragment should nav over to LibraryFragment, or whether // Functions that check if MainFragment should nav over to LibraryFragment, or whether
// it should stay put. Mostly by checking if the navController is currently in a detail // it should stay put. Mostly by checking if the navController is currently in a detail
// fragment, and if the playing item is already being shown. // fragment, and if the playing item is already being shown.

View file

@ -4,10 +4,12 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import dev.chrisbanes.insetter.applySystemWindowInsetsToMargin
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentQueueBinding import org.oxycblt.auxio.databinding.FragmentQueueBinding
import org.oxycblt.auxio.music.BaseModel import org.oxycblt.auxio.music.BaseModel
@ -75,6 +77,12 @@ class QueueFragment : Fragment() {
return binding.root return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<Toolbar>(R.id.queue_toolbar).applySystemWindowInsetsToMargin(top = true)
}
private fun createQueueData(): MutableList<BaseModel> { private fun createQueueData(): MutableList<BaseModel> {
val queue = mutableListOf<BaseModel>() val queue = mutableListOf<BaseModel>()

View file

@ -1,5 +1,6 @@
package org.oxycblt.auxio.ui package org.oxycblt.auxio.ui
import android.annotation.TargetApi
import android.content.Context import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Configuration import android.content.res.Configuration
@ -15,7 +16,6 @@ import android.widget.ImageButton
import android.widget.Toast import android.widget.Toast
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.MenuRes import androidx.annotation.MenuRes
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
@ -76,7 +76,7 @@ fun Spanned.render(): Spanned {
* Handle transparent system bars on light mode. Adapted from Music Player GO * Handle transparent system bars on light mode. Adapted from Music Player GO
* (https://github.com/enricocid/Music-Player-GO) * (https://github.com/enricocid/Music-Player-GO)
*/ */
@RequiresApi(Build.VERSION_CODES.O_MR1) @TargetApi(Build.VERSION_CODES.O_MR1)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
fun Window.handleTransparentSystemBars(config: Configuration) { fun Window.handleTransparentSystemBars(config: Configuration) {
fun isNight() = config.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES fun isNight() = config.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES

View file

@ -11,6 +11,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
android:orientation="vertical"> android:orientation="vertical">
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
@ -28,7 +29,6 @@
android:name="org.oxycblt.auxio.playback.CompactPlaybackFragment" android:name="org.oxycblt.auxio.playback.CompactPlaybackFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"
android:outlineProvider="bounds" android:outlineProvider="bounds"
app:layout_constraintBottom_toTopOf="@+id/nav_bar" app:layout_constraintBottom_toTopOf="@+id/nav_bar"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -40,7 +40,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/background" android:background="@color/background"
app:itemRippleColor="@color/selection_color"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View file

@ -153,7 +153,7 @@
android:id="@+id/playback_play_pause" android:id="@+id/playback_play_pause"
android:layout_width="@dimen/size_play_pause" android:layout_width="@dimen/size_play_pause"
android:layout_height="@dimen/size_play_pause" android:layout_height="@dimen/size_play_pause"
android:layout_marginBottom="30dp" android:layout_marginBottom="@dimen/margin_medium"
android:background="@drawable/ui_circular_button" android:background="@drawable/ui_circular_button"
android:backgroundTint="?attr/colorPrimary" android:backgroundTint="?attr/colorPrimary"
android:contentDescription="@{playbackModel.isPlaying ? @string/description_pause : @string/description_play}" android:contentDescription="@{playbackModel.isPlaying ? @string/description_pause : @string/description_play}"

View file

@ -5,6 +5,7 @@
<color name="selection_color">#484848</color> <color name="selection_color">#484848</color>
<color name="inactive_color">#404040</color> <color name="inactive_color">#404040</color>
<color name="control_color">#ffffff</color> <color name="control_color">#ffffff</color>
<color name="nav_color">#01151515</color>
<!-- <!--
Base color set derived from Music Player GO. Base color set derived from Music Player GO.

View file

@ -5,6 +5,7 @@
<color name="selection_color">#cbcbcb</color> <color name="selection_color">#cbcbcb</color>
<color name="inactive_color">#c4c4c4</color> <color name="inactive_color">#c4c4c4</color>
<color name="control_color">#202020</color> <color name="control_color">#202020</color>
<color name="nav_color">#01fafafa</color>
<!-- <!--
Base color set derived from Music Player GO. Base color set derived from Music Player GO.

View file

@ -3,10 +3,8 @@
<!-- Base theme --> <!-- Base theme -->
<style name="Theme.Base" parent="Theme.AppCompat.DayNight.NoActionBar"> <style name="Theme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowBackground">@color/background</item> <item name="android:windowBackground">@color/background</item>
<item name="android:statusBarColor">@android:color/black</item>
<item name="android:fontFamily">@font/inter</item> <item name="android:fontFamily">@font/inter</item>
<item name="android:textCursorDrawable">@drawable/ui_cursor</item> <item name="android:textCursorDrawable">@drawable/ui_cursor</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:scrollbars">none</item> <item name="android:scrollbars">none</item>
<item name="android:windowIsFloating">false</item> <item name="android:windowIsFloating">false</item>