Unverified Commit c996fa26 authored by Max Lv's avatar Max Lv Committed by GitHub

Merge pull request #1869 from onlymash/master-night_mode

Fix night mode
parents 1a890b12 06da1726
...@@ -22,6 +22,7 @@ package com.github.shadowsocks ...@@ -22,6 +22,7 @@ package com.github.shadowsocks
import android.app.Activity import android.app.Activity
import android.app.PendingIntent import android.app.PendingIntent
import android.app.UiModeManager
import android.app.backup.BackupManager import android.app.backup.BackupManager
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
...@@ -57,6 +58,7 @@ import com.github.shadowsocks.preference.DataStore ...@@ -57,6 +58,7 @@ import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.preference.OnPreferenceDataStoreChangeListener import com.github.shadowsocks.preference.OnPreferenceDataStoreChangeListener
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import com.github.shadowsocks.utils.responseLength import com.github.shadowsocks.utils.responseLength
import com.github.shadowsocks.utils.systemService
import com.github.shadowsocks.utils.thread import com.github.shadowsocks.utils.thread
import com.github.shadowsocks.widget.ServiceButton import com.github.shadowsocks.widget.ServiceButton
import com.mikepenz.materialdrawer.Drawer import com.mikepenz.materialdrawer.Drawer
...@@ -290,6 +292,11 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe ...@@ -290,6 +292,11 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe
val intent = this.intent val intent = this.intent
if (intent != null) handleShareIntent(intent) if (intent != null) handleShareIntent(intent)
if (savedInstanceState != null
&& DataStore.nightMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
&& AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
} }
override fun onNewIntent(intent: Intent) { override fun onNewIntent(intent: Intent) {
...@@ -328,7 +335,12 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe ...@@ -328,7 +335,12 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe
connection.connect() connection.connect()
} }
Key.nightMode -> { Key.nightMode -> {
AppCompatDelegate.setDefaultNightMode(DataStore.nightMode) val mode = DataStore.nightMode
AppCompatDelegate.setDefaultNightMode(when (mode) {
AppCompatDelegate.getDefaultNightMode() -> return
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> systemService<UiModeManager>().nightMode
else -> mode
})
recreate() recreate()
} }
} }
......
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