Prevent some views from being obscured by system UI

Fixes #2171
This commit is contained in:
2025-07-08 20:51:21 -05:00
parent e608c6ea62
commit e4348a2144
4 changed files with 45 additions and 11 deletions

View File

@@ -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()
} }

View File

@@ -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) {

View File

@@ -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())

View File

@@ -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"
@@ -29,7 +28,7 @@
android:id="@+id/toolbar" android:id="@+id/toolbar"
style="@style/Toolbar" style="@style/Toolbar"
app:popupTheme="?toolbarPopupTheme" app:popupTheme="?toolbarPopupTheme"
android:layout_alignParentTop="true"/> android:layout_alignParentTop="true" />
<ScrollView <ScrollView
android:id="@+id/scrollView" android:id="@+id/scrollView"
@@ -41,11 +40,12 @@
<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
android:id="@+id/subtitleCard" android:id="@+id/subtitleCard"
style="@style/ShowHabit.Subtitle"/> style="@style/ShowHabit.Subtitle" />
<org.isoron.uhabits.activities.habits.show.views.NotesCardView <org.isoron.uhabits.activities.habits.show.views.NotesCardView
android:id="@+id/notesCard" android:id="@+id/notesCard"
@@ -55,36 +55,36 @@
<org.isoron.uhabits.activities.habits.show.views.OverviewCardView <org.isoron.uhabits.activities.habits.show.views.OverviewCardView
android:id="@+id/overviewCard" android:id="@+id/overviewCard"
style="@style/Card" style="@style/Card"
android:paddingTop="12dp"/> android:paddingTop="12dp" />
<org.isoron.uhabits.activities.habits.show.views.TargetCardView <org.isoron.uhabits.activities.habits.show.views.TargetCardView
android:id="@+id/targetCard" android:id="@+id/targetCard"
style="@style/Card" style="@style/Card"
android:paddingTop="12dp"/> android:paddingTop="12dp" />
<org.isoron.uhabits.activities.habits.show.views.ScoreCardView <org.isoron.uhabits.activities.habits.show.views.ScoreCardView
android:id="@+id/scoreCard" android:id="@+id/scoreCard"
style="@style/Card" style="@style/Card"
android:gravity="center"/> android:gravity="center" />
<org.isoron.uhabits.activities.habits.show.views.BarCardView <org.isoron.uhabits.activities.habits.show.views.BarCardView
android:id="@+id/barCard" android:id="@+id/barCard"
style="@style/Card" style="@style/Card"
android:gravity="center"/> android:gravity="center" />
<org.isoron.uhabits.activities.habits.show.views.HistoryCardView <org.isoron.uhabits.activities.habits.show.views.HistoryCardView
android:id="@+id/historyCard" android:id="@+id/historyCard"
style="@style/Card" style="@style/Card"
android:gravity="center" android:gravity="center"
android:paddingBottom="0dp"/> android:paddingBottom="0dp" />
<org.isoron.uhabits.activities.habits.show.views.StreakCardView <org.isoron.uhabits.activities.habits.show.views.StreakCardView
android:id="@+id/streakCard" android:id="@+id/streakCard"
style="@style/Card"/> style="@style/Card" />
<org.isoron.uhabits.activities.habits.show.views.FrequencyCardView <org.isoron.uhabits.activities.habits.show.views.FrequencyCardView
android:id="@+id/frequencyCard" android:id="@+id/frequencyCard"
style="@style/Card"/> style="@style/Card" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>