Skip to content

Commit a4e3134

Browse files
committed
trying to fix insets on samsung
1 parent 5353798 commit a4e3134

7 files changed

Lines changed: 15 additions & 27 deletions

File tree

core/src/main/java/com/example/util/simpletimetracker/core/base/BaseBottomSheetFragment.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ abstract class BaseBottomSheetFragment<T : ViewBinding> : BottomSheetDialogFragm
116116
findViewById<View>(com.google.android.material.R.id.container)?.apply {
117117
fitsSystemWindows = false
118118
doOnApplyWindowInsetsListener {
119-
updatePadding(
120-
top = it.getStatusBarInsets().top,
121-
bottom = 0,
122-
)
119+
updatePadding(top = getStatusBarInsets(), bottom = 0)
123120
}
124121
}
125122

core/src/main/java/com/example/util/simpletimetracker/core/utils/InsetUtils.kt

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.example.util.simpletimetracker.core.utils
22

33
import android.view.View
4-
import androidx.core.graphics.Insets
54
import androidx.core.view.ViewCompat
65
import androidx.core.view.WindowInsetsCompat
76
import androidx.core.view.updatePadding
87
import com.example.util.simpletimetracker.core.manager.KeyboardVisibilityManager
8+
import com.example.util.simpletimetracker.domain.extension.orZero
99

1010
// Can update padding or margin, which would be more appropriate.
1111
fun View.doOnApplyWindowInsetsListener(block: View.(WindowInsetsCompat) -> Unit) {
@@ -17,31 +17,22 @@ fun View.doOnApplyWindowInsetsListener(block: View.(WindowInsetsCompat) -> Unit)
1717
}
1818
}
1919

20-
fun View.applySystemBarInsets() {
21-
doOnApplyWindowInsetsListener {
22-
val insets = it.getSystemBarInsets()
23-
updatePadding(top = insets.top, bottom = insets.bottom)
24-
}
25-
}
26-
2720
fun View.applyStatusBarInsets() {
28-
doOnApplyWindowInsetsListener { updatePadding(top = it.getStatusBarInsets().top) }
21+
doOnApplyWindowInsetsListener { updatePadding(top = getStatusBarInsets()) }
2922
}
3023

3124
fun View.applyNavBarInsets() {
32-
doOnApplyWindowInsetsListener { updatePadding(bottom = it.getNavBarInsets().bottom) }
33-
}
34-
35-
fun WindowInsetsCompat.getStatusBarInsets(): Insets {
36-
return getInsets(WindowInsetsCompat.Type.statusBars())
25+
doOnApplyWindowInsetsListener { updatePadding(bottom = getNavBarInsets()) }
3726
}
3827

39-
fun WindowInsetsCompat.getNavBarInsets(): Insets {
40-
return getInsets(WindowInsetsCompat.Type.navigationBars())
28+
fun View.getStatusBarInsets(): Int {
29+
return ViewCompat.getRootWindowInsets(this)
30+
?.getInsets(WindowInsetsCompat.Type.statusBars())?.top.orZero()
4131
}
4232

43-
fun WindowInsetsCompat.getSystemBarInsets(): Insets {
44-
return getInsets(WindowInsetsCompat.Type.systemBars())
33+
fun View.getNavBarInsets(): Int {
34+
return ViewCompat.getRootWindowInsets(this)
35+
?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom.orZero()
4536
}
4637

4738
// Need windowSoftInputMode="adjustResize" on activity in order to work on api < 30.

features/feature_archive/src/main/java/com/example/util/simpletimetracker/feature_archive/view/ArchiveFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ArchiveFragment :
7373
}
7474

7575
btnArchiveOptions.doOnApplyWindowInsetsListener {
76-
val navBarHeight = it.getNavBarInsets().bottom.pxToDp()
76+
val navBarHeight = getNavBarInsets().pxToDp()
7777
viewModel.onChangeInsets(navBarHeight = navBarHeight)
7878
setMargins(bottom = navBarHeight)
7979
}

features/feature_categories/src/main/java/com/example/util/simpletimetracker/feature_categories/view/CategoriesFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CategoriesFragment :
7979
}
8080

8181
btnCategoriesOptions.doOnApplyWindowInsetsListener {
82-
val navBarHeight = it.getNavBarInsets().bottom.pxToDp()
82+
val navBarHeight = getNavBarInsets().pxToDp()
8383
viewModel.onChangeInsets(navBarHeight = navBarHeight)
8484
setMargins(bottom = navBarHeight)
8585
}

features/feature_running_records/src/main/java/com/example/util/simpletimetracker/feature_running_records/view/RunningRecordsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class RunningRecordsFragment :
125125
}
126126

127127
view?.doOnApplyWindowInsetsListener {
128-
viewModel.onChangeInsets(navBarHeight = it.getNavBarInsets().bottom.pxToDp())
128+
viewModel.onChangeInsets(navBarHeight = getNavBarInsets().pxToDp())
129129
}
130130

131131
setOnPreDrawListener {

features/feature_shortcuts/src/main/java/com/example/util/simpletimetracker/feature_shortcuts/view/ShortcutsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ShortcutsFragment : BaseFragment<Binding>() {
5858
}
5959

6060
view?.doOnApplyWindowInsetsListener {
61-
viewModel.onChangeInsets(navBarHeight = it.getNavBarInsets().bottom.pxToDp())
61+
viewModel.onChangeInsets(navBarHeight = getNavBarInsets().pxToDp())
6262
}
6363
}
6464

features/feature_widget/src/main/java/com/example/util/simpletimetracker/feature_widget/universal/view/WidgetUniversalFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class WidgetUniversalFragment :
7474
}
7575

7676
view?.doOnApplyWindowInsetsListener {
77-
viewModel.onChangeInsets(navBarHeight = it.getNavBarInsets().bottom.pxToDp())
77+
viewModel.onChangeInsets(navBarHeight = getNavBarInsets().pxToDp())
7878
}
7979
}
8080

0 commit comments

Comments
 (0)