Skip to content

Commit c1d59a2

Browse files
committed
SettingsActivity: manually apply insets for api 35
The forced EdgeToEdge changes don't work well with PreferenceFragmentCompat, because it's basically abandoned by androidx, so apply the insets manually ourselves. Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 32125b1 commit c1d59a2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ui/src/main/java/com/wireguard/android/activity/SettingsActivity.kt

+24
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ package com.wireguard.android.activity
77
import android.content.Intent
88
import android.os.Build
99
import android.os.Bundle
10+
import android.view.LayoutInflater
1011
import android.view.MenuItem
12+
import android.view.View
13+
import android.view.ViewGroup
1114
import androidx.appcompat.app.AppCompatActivity
15+
import androidx.core.view.ViewCompat
16+
import androidx.core.view.WindowInsetsCompat
17+
import androidx.core.view.updateLayoutParams
1218
import androidx.fragment.app.commit
1319
import androidx.lifecycle.lifecycleScope
1420
import androidx.preference.Preference
@@ -45,6 +51,24 @@ class SettingsActivity : AppCompatActivity() {
4551
}
4652

4753
class SettingsFragment : PreferenceFragmentCompat() {
54+
55+
// Since this is pretty much abandoned by androidx, it never got updated for proper EdgeToEdge support,
56+
// which is enabled everywhere for API 35. So handle the insets manually here.
57+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
58+
val view = super.onCreateView(inflater, container, savedInstanceState)
59+
ViewCompat.setOnApplyWindowInsetsListener(view) { v, windowInsets ->
60+
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
61+
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
62+
leftMargin = insets.left
63+
bottomMargin = insets.bottom
64+
rightMargin = insets.right
65+
topMargin = insets.top
66+
}
67+
WindowInsetsCompat.CONSUMED
68+
}
69+
return view
70+
}
71+
4872
override fun onCreatePreferences(savedInstanceState: Bundle?, key: String?) {
4973
preferenceManager.preferenceDataStore = PreferencesPreferenceDataStore(lifecycleScope, Application.getPreferencesDataStore())
5074
addPreferencesFromResource(R.xml.preferences)

0 commit comments

Comments
 (0)