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
import android.content.Context
import android.graphics.Rect
import android.os.Bundle
import android.os.Parcelable
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.ItemTouchHelper.DOWN
import androidx.recyclerview.widget.ItemTouchHelper.END
@ -75,9 +78,30 @@ class HabitCardListView(
setHasFixedSize(true)
isLongClickable = true
layoutManager = LinearLayoutManager(context)
applyBottomInset()
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 {
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.ShowHabitState
import org.isoron.uhabits.databinding.ShowHabitBinding
import org.isoron.uhabits.utils.applyBottomInset
import org.isoron.uhabits.utils.applyToolbarInsets
import org.isoron.uhabits.utils.setupToolbar
@ -57,6 +58,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
} else {
binding.targetCard.visibility = GONE
}
binding.linearLayout.applyBottomInset()
}
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() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())

@ -17,8 +17,7 @@
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout
android:id="@+id/container"
<RelativeLayout android:id="@+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
@ -29,7 +28,7 @@
android:id="@+id/toolbar"
style="@style/Toolbar"
app:popupTheme="?toolbarPopupTheme"
android:layout_alignParentTop="true"/>
android:layout_alignParentTop="true" />
<ScrollView
android:id="@+id/scrollView"
@ -41,11 +40,12 @@
<LinearLayout
style="@style/CardList"
android:id="@+id/linearLayout"
android:clipToPadding="false">
<org.isoron.uhabits.activities.habits.show.views.SubtitleCardView
android:id="@+id/subtitleCard"
style="@style/ShowHabit.Subtitle"/>
style="@style/ShowHabit.Subtitle" />
<org.isoron.uhabits.activities.habits.show.views.NotesCardView
android:id="@+id/notesCard"
@ -55,36 +55,36 @@
<org.isoron.uhabits.activities.habits.show.views.OverviewCardView
android:id="@+id/overviewCard"
style="@style/Card"
android:paddingTop="12dp"/>
android:paddingTop="12dp" />
<org.isoron.uhabits.activities.habits.show.views.TargetCardView
android:id="@+id/targetCard"
style="@style/Card"
android:paddingTop="12dp"/>
android:paddingTop="12dp" />
<org.isoron.uhabits.activities.habits.show.views.ScoreCardView
android:id="@+id/scoreCard"
style="@style/Card"
android:gravity="center"/>
android:gravity="center" />
<org.isoron.uhabits.activities.habits.show.views.BarCardView
android:id="@+id/barCard"
style="@style/Card"
android:gravity="center"/>
android:gravity="center" />
<org.isoron.uhabits.activities.habits.show.views.HistoryCardView
android:id="@+id/historyCard"
style="@style/Card"
android:gravity="center"
android:paddingBottom="0dp"/>
android:paddingBottom="0dp" />
<org.isoron.uhabits.activities.habits.show.views.StreakCardView
android:id="@+id/streakCard"
style="@style/Card"/>
style="@style/Card" />
<org.isoron.uhabits.activities.habits.show.views.FrequencyCardView
android:id="@+id/frequencyCard"
style="@style/Card"/>
style="@style/Card" />
</LinearLayout>
</ScrollView>

Loading…
Cancel
Save