Fixed Edge-to-Edge

This commit is contained in:
Prathamesh More 2022-01-16 18:13:31 +05:30
parent ea4a54d404
commit 09ad243a14
6 changed files with 63 additions and 14 deletions

View file

@ -116,7 +116,7 @@ open class SongAdapter(
holder.title?.setTextColor(color.primaryTextColor) holder.title?.setTextColor(color.primaryTextColor)
holder.text?.setTextColor(color.secondaryTextColor) holder.text?.setTextColor(color.secondaryTextColor)
holder.paletteColorContainer?.setBackgroundColor(color.backgroundColor) holder.paletteColorContainer?.setBackgroundColor(color.backgroundColor)
holder.menu?.imageTintList= ColorStateList.valueOf(color.primaryTextColor) holder.menu?.imageTintList = ColorStateList.valueOf(color.primaryTextColor)
} }
holder.mask?.backgroundTintList = ColorStateList.valueOf(color.primaryTextColor) holder.mask?.backgroundTintList = ColorStateList.valueOf(color.primaryTextColor)
} }

View file

@ -162,4 +162,47 @@ fun View.updateMargin(
@Px bottom: Int = marginBottom @Px bottom: Int = marginBottom
) { ) {
(layoutParams as ViewGroup.MarginLayoutParams).updateMargins(left, top, right, bottom) (layoutParams as ViewGroup.MarginLayoutParams).updateMargins(left, top, right, bottom)
} }
fun View.applyBottomInsets() {
if (PreferenceUtil.isFullScreenMode) return
val initialPadding = recordInitialPaddingForView(this)
ViewCompat.setOnApplyWindowInsetsListener(
(this)
) { v: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
v.updatePadding(
bottom = initialPadding.bottom + insets.bottom
)
windowInsets
}
requestApplyInsetsWhenAttached()
}
fun View.requestApplyInsetsWhenAttached() {
if (isAttachedToWindow) {
// We're already attached, just request as normal
requestApplyInsets()
} else {
// We're not attached to the hierarchy, add a listener to
// request when we are
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
v.removeOnAttachStateChangeListener(this)
v.requestApplyInsets()
}
override fun onViewDetachedFromWindow(v: View) = Unit
})
}
}
data class InitialPadding(
val left: Int, val top: Int,
val right: Int, val bottom: Int
)
fun recordInitialPaddingForView(view: View) = InitialPadding(
view.paddingLeft, view.paddingTop, view.paddingRight, view.paddingBottom
)

View file

@ -108,7 +108,6 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
} }
val appName = resources.getString(titleRes) val appName = resources.getString(titleRes)
binding.appBarLayout.title = appName binding.appBarLayout.title = appName
//toolbarContainer.drawNextToNavbar()
} }
abstract val titleRes: Int abstract val titleRes: Int

View file

@ -21,6 +21,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.doOnPreDraw import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -100,7 +101,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_
private fun checkIsEmpty() { private fun checkIsEmpty() {
checkForPadding() checkForPadding()
binding.emptyEmoji.text = getEmojiByUnicode(0x1F631) binding.emptyEmoji.text = getEmojiByUnicode(0x1F631)
binding.empty.visibility = if (songAdapter.itemCount == 0) View.VISIBLE else View.GONE binding.empty.isVisible = songAdapter.itemCount == 0
} }
private fun checkForPadding() { private fun checkForPadding() {

View file

@ -1,6 +1,7 @@
package code.name.monkey.retromusic.views package code.name.monkey.retromusic.views
import android.content.Context import android.content.Context
import android.content.res.Configuration
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
@ -9,6 +10,7 @@ import code.name.monkey.retromusic.databinding.SimpleAppbarLayoutBinding
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.shape.MaterialShapeDrawable import com.google.android.material.shape.MaterialShapeDrawable
import dev.chrisbanes.insetter.applyInsetter
class TopAppBarLayout @JvmOverloads constructor( class TopAppBarLayout @JvmOverloads constructor(
context: Context, context: Context,
@ -24,9 +26,20 @@ class TopAppBarLayout @JvmOverloads constructor(
if (mode == AppBarMode.COLLAPSING) { if (mode == AppBarMode.COLLAPSING) {
collapsingAppbarBinding = collapsingAppbarBinding =
CollapsingAppbarLayoutBinding.inflate(LayoutInflater.from(context), this, true) CollapsingAppbarLayoutBinding.inflate(LayoutInflater.from(context), this, true)
val isLandscape =
context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
if (isLandscape) {
fitsSystemWindows = false
}
} else { } else {
simpleAppbarBinding = simpleAppbarBinding =
SimpleAppbarLayoutBinding.inflate(LayoutInflater.from(context), this, true) SimpleAppbarLayoutBinding.inflate(LayoutInflater.from(context), this, true)
simpleAppbarBinding?.root?.applyInsetter {
type(navigationBars = true) {
padding(horizontal = true)
}
}
statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context) statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context)
} }
} }

View file

@ -4,9 +4,7 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.annotation.Px import androidx.annotation.Px
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.extensions.applyBottomInsets
import code.name.monkey.retromusic.extensions.drawAboveSystemBarsWithPadding
import code.name.monkey.retromusic.util.RetroUtil
class InsetsRecyclerView @JvmOverloads constructor( class InsetsRecyclerView @JvmOverloads constructor(
context: Context, context: Context,
@ -14,8 +12,7 @@ class InsetsRecyclerView @JvmOverloads constructor(
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr) { ) : RecyclerView(context, attrs, defStyleAttr) {
init { init {
if (!RetroUtil.isLandscape()) applyBottomInsets()
drawAboveSystemBarsWithPadding()
} }
fun updatePadding( fun updatePadding(
@ -25,10 +22,6 @@ class InsetsRecyclerView @JvmOverloads constructor(
@Px bottom: Int = paddingBottom @Px bottom: Int = paddingBottom
) { ) {
setPadding(left, top, right, bottom) setPadding(left, top, right, bottom)
// Insetter saves initial state i.e. initial padding/margin of the view, applyBottomInsets()
// we just clear it for now
setTag(R.id.insetter_initial_state, null)
if (!RetroUtil.isLandscape())
drawAboveSystemBarsWithPadding()
} }
} }