Fixed Edge-to-Edge
This commit is contained in:
parent
ea4a54d404
commit
09ad243a14
6 changed files with 63 additions and 14 deletions
|
@ -116,7 +116,7 @@ open class SongAdapter(
|
|||
holder.title?.setTextColor(color.primaryTextColor)
|
||||
holder.text?.setTextColor(color.secondaryTextColor)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -162,4 +162,47 @@ fun View.updateMargin(
|
|||
@Px bottom: Int = marginBottom
|
||||
) {
|
||||
(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
|
||||
)
|
|
@ -108,7 +108,6 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
|
|||
}
|
||||
val appName = resources.getString(titleRes)
|
||||
binding.appBarLayout.title = appName
|
||||
//toolbarContainer.drawNextToNavbar()
|
||||
}
|
||||
|
||||
abstract val titleRes: Int
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
@ -100,7 +101,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_
|
|||
private fun checkIsEmpty() {
|
||||
checkForPadding()
|
||||
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() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package code.name.monkey.retromusic.views
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
|
@ -9,6 +10,7 @@ import code.name.monkey.retromusic.databinding.SimpleAppbarLayoutBinding
|
|||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import dev.chrisbanes.insetter.applyInsetter
|
||||
|
||||
class TopAppBarLayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -24,9 +26,20 @@ class TopAppBarLayout @JvmOverloads constructor(
|
|||
if (mode == AppBarMode.COLLAPSING) {
|
||||
collapsingAppbarBinding =
|
||||
CollapsingAppbarLayoutBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
val isLandscape =
|
||||
context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
if (isLandscape) {
|
||||
fitsSystemWindows = false
|
||||
}
|
||||
|
||||
} else {
|
||||
simpleAppbarBinding =
|
||||
SimpleAppbarLayoutBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
simpleAppbarBinding?.root?.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
padding(horizontal = true)
|
||||
}
|
||||
}
|
||||
statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import androidx.annotation.Px
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.drawAboveSystemBarsWithPadding
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
import code.name.monkey.retromusic.extensions.applyBottomInsets
|
||||
|
||||
class InsetsRecyclerView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,8 +12,7 @@ class InsetsRecyclerView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||
init {
|
||||
if (!RetroUtil.isLandscape())
|
||||
drawAboveSystemBarsWithPadding()
|
||||
applyBottomInsets()
|
||||
}
|
||||
|
||||
fun updatePadding(
|
||||
|
@ -25,10 +22,6 @@ class InsetsRecyclerView @JvmOverloads constructor(
|
|||
@Px bottom: Int = paddingBottom
|
||||
) {
|
||||
setPadding(left, top, right, bottom)
|
||||
// Insetter saves initial state i.e. initial padding/margin of the view,
|
||||
// we just clear it for now
|
||||
setTag(R.id.insetter_initial_state, null)
|
||||
if (!RetroUtil.isLandscape())
|
||||
drawAboveSystemBarsWithPadding()
|
||||
applyBottomInsets()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue