Skip to content

Commit e4348a2

Browse files
committed
Prevent some views from being obscured by system UI
Fixes #2171
1 parent e608c6e commit e4348a2

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardListView.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
package org.isoron.uhabits.activities.habits.list.views
2121

2222
import android.content.Context
23+
import android.graphics.Rect
2324
import android.os.Bundle
2425
import android.os.Parcelable
2526
import android.view.GestureDetector
2627
import android.view.MotionEvent
2728
import android.view.View
29+
import androidx.core.view.ViewCompat
30+
import androidx.core.view.WindowInsetsCompat
2831
import androidx.recyclerview.widget.ItemTouchHelper
2932
import androidx.recyclerview.widget.ItemTouchHelper.DOWN
3033
import androidx.recyclerview.widget.ItemTouchHelper.END
@@ -75,9 +78,30 @@ class HabitCardListView(
7578
setHasFixedSize(true)
7679
isLongClickable = true
7780
layoutManager = LinearLayoutManager(context)
81+
applyBottomInset()
7882
super.setAdapter(adapter)
7983
}
8084

85+
private fun applyBottomInset() {
86+
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
87+
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
88+
addItemDecoration(object : ItemDecoration() {
89+
override fun getItemOffsets(
90+
outRect: Rect,
91+
view: View,
92+
parent: RecyclerView,
93+
state: State
94+
) {
95+
val itemCount = parent.adapter?.itemCount
96+
if (parent.getChildAdapterPosition(view) == itemCount?.minus(1)) {
97+
outRect.bottom = systemBarsInsets.bottom
98+
}
99+
}
100+
})
101+
insets
102+
}
103+
}
104+
81105
fun createHabitCardView(): HabitCardView {
82106
return cardViewFactory.create()
83107
}

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import android.widget.FrameLayout
2525
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter
2626
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitState
2727
import org.isoron.uhabits.databinding.ShowHabitBinding
28+
import org.isoron.uhabits.utils.applyBottomInset
2829
import org.isoron.uhabits.utils.applyToolbarInsets
2930
import org.isoron.uhabits.utils.setupToolbar
3031

@@ -57,6 +58,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
5758
} else {
5859
binding.targetCard.visibility = GONE
5960
}
61+
binding.linearLayout.applyBottomInset()
6062
}
6163

6264
fun setListener(presenter: ShowHabitPresenter) {

uhabits-android/src/main/java/org/isoron/uhabits/utils/ViewExtensions.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ fun View.applyRootViewInsets() {
260260
}
261261
}
262262

263+
fun View.applyBottomInset() {
264+
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
265+
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
266+
view.setPadding(0, 0, 0, systemBarsInsets.bottom)
267+
insets
268+
}
269+
}
270+
263271
fun View.applyToolbarInsets() {
264272
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
265273
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())

uhabits-android/src/main/res/layout/show_habit.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
~ with this program. If not, see <http://www.gnu.org/licenses/>.
1818
-->
1919

20-
<RelativeLayout
21-
android:id="@+id/container"
20+
<RelativeLayout android:id="@+id/container"
2221
xmlns:android="http://schemas.android.com/apk/res/android"
2322
xmlns:app="http://schemas.android.com/apk/res-auto"
2423
android:layout_width="match_parent"
@@ -29,7 +28,7 @@
2928
android:id="@+id/toolbar"
3029
style="@style/Toolbar"
3130
app:popupTheme="?toolbarPopupTheme"
32-
android:layout_alignParentTop="true"/>
31+
android:layout_alignParentTop="true" />
3332

3433
<ScrollView
3534
android:id="@+id/scrollView"
@@ -41,11 +40,12 @@
4140

4241
<LinearLayout
4342
style="@style/CardList"
43+
android:id="@+id/linearLayout"
4444
android:clipToPadding="false">
4545

4646
<org.isoron.uhabits.activities.habits.show.views.SubtitleCardView
4747
android:id="@+id/subtitleCard"
48-
style="@style/ShowHabit.Subtitle"/>
48+
style="@style/ShowHabit.Subtitle" />
4949

5050
<org.isoron.uhabits.activities.habits.show.views.NotesCardView
5151
android:id="@+id/notesCard"
@@ -55,36 +55,36 @@
5555
<org.isoron.uhabits.activities.habits.show.views.OverviewCardView
5656
android:id="@+id/overviewCard"
5757
style="@style/Card"
58-
android:paddingTop="12dp"/>
58+
android:paddingTop="12dp" />
5959

6060
<org.isoron.uhabits.activities.habits.show.views.TargetCardView
6161
android:id="@+id/targetCard"
6262
style="@style/Card"
63-
android:paddingTop="12dp"/>
63+
android:paddingTop="12dp" />
6464

6565
<org.isoron.uhabits.activities.habits.show.views.ScoreCardView
6666
android:id="@+id/scoreCard"
6767
style="@style/Card"
68-
android:gravity="center"/>
68+
android:gravity="center" />
6969

7070
<org.isoron.uhabits.activities.habits.show.views.BarCardView
7171
android:id="@+id/barCard"
7272
style="@style/Card"
73-
android:gravity="center"/>
73+
android:gravity="center" />
7474

7575
<org.isoron.uhabits.activities.habits.show.views.HistoryCardView
7676
android:id="@+id/historyCard"
7777
style="@style/Card"
7878
android:gravity="center"
79-
android:paddingBottom="0dp"/>
79+
android:paddingBottom="0dp" />
8080

8181
<org.isoron.uhabits.activities.habits.show.views.StreakCardView
8282
android:id="@+id/streakCard"
83-
style="@style/Card"/>
83+
style="@style/Card" />
8484

8585
<org.isoron.uhabits.activities.habits.show.views.FrequencyCardView
8686
android:id="@+id/frequencyCard"
87-
style="@style/Card"/>
87+
style="@style/Card" />
8888

8989
</LinearLayout>
9090
</ScrollView>

0 commit comments

Comments
 (0)