Commit 33223297 authored by Mygod's avatar Mygod

Remove night mode switch on Pie

parent d753b083
...@@ -136,7 +136,7 @@ class App : Application() { ...@@ -136,7 +136,7 @@ class App : Application() {
} }
DataStore.publicStore.putLong(Key.assetUpdateTime, info.lastUpdateTime) DataStore.publicStore.putLong(Key.assetUpdateTime, info.lastUpdateTime)
} }
AppCompatDelegate.setDefaultNightMode(DataStore.nightMode) if (Build.VERSION.SDK_INT < 28) AppCompatDelegate.setDefaultNightMode(DataStore.nightMode)
updateNotificationChannels() updateNotificationChannels()
} }
......
...@@ -30,6 +30,7 @@ import com.github.shadowsocks.preference.DataStore ...@@ -30,6 +30,7 @@ import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.DirectBoot import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import com.github.shadowsocks.utils.TcpFastOpen import com.github.shadowsocks.utils.TcpFastOpen
import com.github.shadowsocks.utils.remove
import com.takisoft.preferencex.PreferenceFragmentCompat import com.takisoft.preferencex.PreferenceFragmentCompat
class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() { class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
...@@ -48,7 +49,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() { ...@@ -48,7 +49,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
if (Build.VERSION.SDK_INT >= 24) canToggleLocked.setOnPreferenceChangeListener { _, newValue -> if (Build.VERSION.SDK_INT >= 24) canToggleLocked.setOnPreferenceChangeListener { _, newValue ->
if (app.directBootSupported && newValue as Boolean) DirectBoot.update() else DirectBoot.clean() if (app.directBootSupported && newValue as Boolean) DirectBoot.update() else DirectBoot.clean()
true true
} else canToggleLocked.parent!!.removePreference(canToggleLocked) } else canToggleLocked.remove()
val tfo = findPreference(Key.tfo) as SwitchPreference val tfo = findPreference(Key.tfo) as SwitchPreference
tfo.isChecked = DataStore.tcpFastOpen tfo.isChecked = DataStore.tcpFastOpen
...@@ -63,6 +64,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() { ...@@ -63,6 +64,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
tfo.isEnabled = false tfo.isEnabled = false
tfo.summary = getString(R.string.tcp_fastopen_summary_unsupported, System.getProperty("os.version")) tfo.summary = getString(R.string.tcp_fastopen_summary_unsupported, System.getProperty("os.version"))
} }
if (Build.VERSION.SDK_INT >= 28) findPreference(Key.nightMode).remove()
val serviceMode = findPreference(Key.serviceMode) val serviceMode = findPreference(Key.serviceMode)
val portProxy = findPreference(Key.portProxy) val portProxy = findPreference(Key.portProxy)
......
...@@ -30,6 +30,7 @@ import android.content.Intent ...@@ -30,6 +30,7 @@ import android.content.Intent
import android.net.VpnService import android.net.VpnService
import android.nfc.NdefMessage import android.nfc.NdefMessage
import android.nfc.NfcAdapter import android.nfc.NfcAdapter
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.MenuItem import android.view.MenuItem
...@@ -184,7 +185,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre ...@@ -184,7 +185,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
val intent = this.intent val intent = this.intent
if (intent != null) handleShareIntent(intent) if (intent != null) handleShareIntent(intent)
if (savedInstanceState != null && if (Build.VERSION.SDK_INT < 28 && savedInstanceState != null &&
DataStore.nightMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM && DataStore.nightMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM &&
AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) { AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
...@@ -226,7 +227,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre ...@@ -226,7 +227,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
connection.disconnect() connection.disconnect()
connection.connect() connection.connect()
} }
Key.nightMode -> { Key.nightMode -> if (Build.VERSION.SDK_INT < 28) {
val mode = DataStore.nightMode val mode = DataStore.nightMode
AppCompatDelegate.setDefaultNightMode(when (mode) { AppCompatDelegate.setDefaultNightMode(when (mode) {
AppCompatDelegate.getDefaultNightMode() -> return AppCompatDelegate.getDefaultNightMode() -> return
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package com.github.shadowsocks.preference package com.github.shadowsocks.preference
import android.os.Binder import android.os.Binder
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import com.github.shadowsocks.App.Companion.app import com.github.shadowsocks.App.Companion.app
import com.github.shadowsocks.database.PrivateDatabase import com.github.shadowsocks.database.PrivateDatabase
...@@ -55,7 +56,7 @@ object DataStore { ...@@ -55,7 +56,7 @@ object DataStore {
val directBootAware: Boolean get() = app.directBootSupported && canToggleLocked val directBootAware: Boolean get() = app.directBootSupported && canToggleLocked
val tcpFastOpen: Boolean get() = TcpFastOpen.sendEnabled && DataStore.publicStore.getBoolean(Key.tfo, true) val tcpFastOpen: Boolean get() = TcpFastOpen.sendEnabled && DataStore.publicStore.getBoolean(Key.tfo, true)
@AppCompatDelegate.NightMode @AppCompatDelegate.NightMode
val nightMode get() = when (publicStore.getString(Key.nightMode)) { val nightMode get() = when (if (Build.VERSION.SDK_INT < 28) publicStore.getString(Key.nightMode) else null) {
Key.nightModeAuto -> AppCompatDelegate.MODE_NIGHT_AUTO Key.nightModeAuto -> AppCompatDelegate.MODE_NIGHT_AUTO
Key.nightModeOff -> AppCompatDelegate.MODE_NIGHT_NO Key.nightModeOff -> AppCompatDelegate.MODE_NIGHT_NO
Key.nightModeOn -> AppCompatDelegate.MODE_NIGHT_YES Key.nightModeOn -> AppCompatDelegate.MODE_NIGHT_YES
......
...@@ -12,6 +12,7 @@ import android.net.Uri ...@@ -12,6 +12,7 @@ import android.net.Uri
import android.os.Build import android.os.Build
import android.util.TypedValue import android.util.TypedValue
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.preference.Preference
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.JniHelper import com.github.shadowsocks.JniHelper
import java.net.InetAddress import java.net.InetAddress
...@@ -68,3 +69,5 @@ fun printLog(t: Throwable) { ...@@ -68,3 +69,5 @@ fun printLog(t: Throwable) {
Crashlytics.logException(t) Crashlytics.logException(t)
t.printStackTrace() t.printStackTrace()
} }
fun Preference.remove() = parent!!.removePreference(this)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment