Prevent some views from being obscured by system UI

Fixes #2171
pull/2194/head
Alinson S. Xavier 3 months ago
parent e608c6ea62
commit e4348a2144

@ -20,11 +20,14 @@
package org.isoron.uhabits.activities.habits.list.views package org.isoron.uhabits.activities.habits.list.views
import android.content.Context import android.content.Context
import android.graphics.Rect
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.GestureDetector import android.view.GestureDetector
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.ItemTouchHelper.DOWN import androidx.recyclerview.widget.ItemTouchHelper.DOWN
import androidx.recyclerview.widget.ItemTouchHelper.END import androidx.recyclerview.widget.ItemTouchHelper.END
@ -75,9 +78,30 @@ class HabitCardListView(
setHasFixedSize(true) setHasFixedSize(true)
isLongClickable = true isLongClickable = true
layoutManager = LinearLayoutManager(context) layoutManager = LinearLayoutManager(context)
applyBottomInset()
super.setAdapter(adapter) super.setAdapter(adapter)
} }
private fun applyBottomInset() {
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
addItemDecoration(object : ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: State
) {
val itemCount = parent.adapter?.itemCount
if (parent.getChildAdapterPosition(view) == itemCount?.minus(1)) {
outRect.bottom = systemBarsInsets.bottom
}
}
})
insets
}
}
fun createHabitCardView(): HabitCardView { fun createHabitCardView(): HabitCardView {
return cardViewFactory.create() return cardViewFactory.create()
} }

@ -25,6 +25,7 @@ import android.widget.FrameLayout
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitState import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitState
import org.isoron.uhabits.databinding.ShowHabitBinding import org.isoron.uhabits.databinding.ShowHabitBinding
import org.isoron.uhabits.utils.applyBottomInset
import org.isoron.uhabits.utils.applyToolbarInsets import org.isoron.uhabits.utils.applyToolbarInsets
import org.isoron.uhabits.utils.setupToolbar import org.isoron.uhabits.utils.setupToolbar
@ -57,6 +58,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
} else { } else {
binding.targetCard.visibility = GONE binding.targetCard.visibility = GONE
} }
binding.linearLayout.applyBottomInset()
} }
fun setListener(presenter: ShowHabitPresenter) { fun setListener(presenter: ShowHabitPresenter) {

@ -260,6 +260,14 @@ fun View.applyRootViewInsets() {
} }
} }
fun View.applyBottomInset() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
view.setPadding(0, 0, 0, systemBarsInsets.bottom)
insets
}
}
fun View.applyToolbarInsets() { fun View.applyToolbarInsets() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets -> ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())

@ -17,8 +17,7 @@
~ with this program. If not, see <http://www.gnu.org/licenses/>. ~ with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<RelativeLayout <RelativeLayout android:id="@+id/container"
android:id="@+id/container"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -41,6 +40,7 @@
<LinearLayout <LinearLayout
style="@style/CardList" style="@style/CardList"
android:id="@+id/linearLayout"
android:clipToPadding="false"> android:clipToPadding="false">
<org.isoron.uhabits.activities.habits.show.views.SubtitleCardView <org.isoron.uhabits.activities.habits.show.views.SubtitleCardView

Loading…
Cancel
Save