Skip to content

Commit a752532

Browse files
committed
Fix landscape immersive theme
1 parent b39f1f6 commit a752532

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

core/src/main/java/com/github/shadowsocks/utils/Utils.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ import android.os.Build
3434
import android.system.Os
3535
import android.system.OsConstants
3636
import android.util.TypedValue
37-
import android.view.WindowInsets
37+
import android.view.View
38+
import android.view.ViewGroup
3839
import androidx.annotation.AttrRes
40+
import androidx.appcompat.app.AppCompatActivity
41+
import androidx.core.view.updateLayoutParams
3942
import androidx.preference.Preference
4043
import com.crashlytics.android.Crashlytics
4144
import kotlinx.coroutines.Dispatchers
@@ -115,9 +118,17 @@ fun Resources.Theme.resolveResourceId(@AttrRes resId: Int): Int {
115118

116119
val Intent.datas get() = listOfNotNull(data) + (clipData?.asIterable()?.mapNotNull { it.uri } ?: emptyList())
117120

118-
@Suppress("DEPRECATION")
119-
fun WindowInsets.consumeSystemWindowInsetTop() = replaceSystemWindowInsets(
120-
systemWindowInsetLeft, 0, systemWindowInsetRight, systemWindowInsetBottom)
121+
fun AppCompatActivity.consumeSystemWindowInsetsWithList() {
122+
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
123+
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
124+
leftMargin = insets.systemWindowInsetLeft
125+
topMargin = insets.systemWindowInsetTop
126+
rightMargin = insets.systemWindowInsetRight
127+
}
128+
@Suppress("DEPRECATION")
129+
insets.replaceSystemWindowInsets(0, 0, 0, insets.systemWindowInsetBottom)
130+
}
131+
}
121132

122133
fun printLog(t: Throwable) {
123134
Crashlytics.logException(t)

mobile/src/main/java/com/github/shadowsocks/AppManager.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import androidx.annotation.UiThread
4242
import androidx.appcompat.app.AppCompatActivity
4343
import androidx.core.content.getSystemService
4444
import androidx.core.util.set
45-
import androidx.core.view.updateLayoutParams
4645
import androidx.core.view.updatePadding
4746
import androidx.recyclerview.widget.DefaultItemAnimator
4847
import androidx.recyclerview.widget.LinearLayoutManager
@@ -53,7 +52,7 @@ import com.github.shadowsocks.preference.DataStore
5352
import com.github.shadowsocks.utils.DirectBoot
5453
import com.github.shadowsocks.utils.Key
5554
import com.github.shadowsocks.utils.SingleInstanceActivity
56-
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
55+
import com.github.shadowsocks.utils.consumeSystemWindowInsetsWithList
5756
import com.google.android.material.snackbar.Snackbar
5857
import kotlinx.android.synthetic.main.layout_apps.*
5958
import kotlinx.android.synthetic.main.layout_apps_item.view.*
@@ -215,10 +214,7 @@ class AppManager : AppCompatActivity() {
215214
super.onCreate(savedInstanceState)
216215
SingleInstanceActivity.register(this) ?: return
217216
setContentView(R.layout.layout_apps)
218-
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
219-
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = insets.systemWindowInsetTop }
220-
insets.consumeSystemWindowInsetTop()
221-
}
217+
consumeSystemWindowInsetsWithList()
222218
setSupportActionBar(toolbar)
223219
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
224220

mobile/src/main/java/com/github/shadowsocks/ProfileConfigActivity.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ import android.content.Intent
2626
import android.os.Bundle
2727
import android.view.Menu
2828
import android.view.MenuItem
29-
import android.view.View
30-
import android.view.ViewGroup
3129
import androidx.appcompat.app.AlertDialog
3230
import androidx.appcompat.app.AppCompatActivity
33-
import androidx.core.view.updateLayoutParams
3431
import com.github.shadowsocks.plugin.AlertDialogFragment
3532
import com.github.shadowsocks.plugin.Empty
3633
import com.github.shadowsocks.plugin.PluginContract
3734
import com.github.shadowsocks.preference.DataStore
3835
import com.github.shadowsocks.utils.SingleInstanceActivity
39-
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
36+
import com.github.shadowsocks.utils.consumeSystemWindowInsetsWithList
4037

4138
class ProfileConfigActivity : AppCompatActivity() {
4239
companion object {
@@ -58,10 +55,7 @@ class ProfileConfigActivity : AppCompatActivity() {
5855
super.onCreate(savedInstanceState)
5956
SingleInstanceActivity.register(this) ?: return
6057
setContentView(R.layout.layout_profile_config)
61-
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
62-
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = insets.systemWindowInsetTop }
63-
insets.consumeSystemWindowInsetTop()
64-
}
58+
consumeSystemWindowInsetsWithList()
6559
setSupportActionBar(findViewById(R.id.toolbar))
6660
supportActionBar!!.apply {
6761
setDisplayHomeAsUpEnabled(true)

mobile/src/main/java/com/github/shadowsocks/UdpFallbackProfileActivity.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import android.view.ViewGroup
2828
import android.widget.CheckedTextView
2929
import androidx.appcompat.app.AppCompatActivity
3030
import androidx.appcompat.widget.Toolbar
31-
import androidx.core.view.updateLayoutParams
3231
import androidx.core.view.updatePadding
3332
import androidx.recyclerview.widget.DefaultItemAnimator
3433
import androidx.recyclerview.widget.LinearLayoutManager
@@ -38,7 +37,7 @@ import com.github.shadowsocks.database.ProfileManager
3837
import com.github.shadowsocks.plugin.PluginConfiguration
3938
import com.github.shadowsocks.preference.DataStore
4039
import com.github.shadowsocks.utils.SingleInstanceActivity
41-
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
40+
import com.github.shadowsocks.utils.consumeSystemWindowInsetsWithList
4241
import com.github.shadowsocks.utils.resolveResourceId
4342

4443
class UdpFallbackProfileActivity : AppCompatActivity() {
@@ -88,10 +87,7 @@ class UdpFallbackProfileActivity : AppCompatActivity() {
8887
}
8988
SingleInstanceActivity.register(this) ?: return
9089
setContentView(R.layout.layout_udp_fallback)
91-
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
92-
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = insets.systemWindowInsetTop }
93-
insets.consumeSystemWindowInsetTop()
94-
}
90+
consumeSystemWindowInsetsWithList()
9591

9692
val toolbar = findViewById<Toolbar>(R.id.toolbar)
9793
toolbar.setTitle(R.string.udp_fallback)

mobile/src/main/java/com/github/shadowsocks/tasker/ConfigActivity.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ import android.widget.CheckedTextView
3030
import android.widget.Switch
3131
import androidx.appcompat.app.AppCompatActivity
3232
import androidx.appcompat.widget.Toolbar
33-
import androidx.core.view.updateLayoutParams
3433
import androidx.core.view.updatePadding
3534
import androidx.recyclerview.widget.DefaultItemAnimator
3635
import androidx.recyclerview.widget.LinearLayoutManager
3736
import androidx.recyclerview.widget.RecyclerView
3837
import com.github.shadowsocks.R
3938
import com.github.shadowsocks.database.Profile
4039
import com.github.shadowsocks.database.ProfileManager
41-
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
40+
import com.github.shadowsocks.utils.consumeSystemWindowInsetsWithList
4241
import com.github.shadowsocks.utils.resolveResourceId
4342

4443
class ConfigActivity : AppCompatActivity() {
@@ -95,10 +94,7 @@ class ConfigActivity : AppCompatActivity() {
9594
}
9695
taskerOption = Settings.fromIntent(intent)
9796
setContentView(R.layout.layout_tasker)
98-
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
99-
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = insets.systemWindowInsetTop }
100-
insets.consumeSystemWindowInsetTop()
101-
}
97+
consumeSystemWindowInsetsWithList()
10298

10399
val toolbar = findViewById<Toolbar>(R.id.toolbar)
104100
toolbar.setTitle(R.string.app_name)

0 commit comments

Comments
 (0)