Commit 858a7f1d authored by Max Lv's avatar Max Lv

Merge branch 'Mygod-p-night'

parents 77ca235b 026f07e8
......@@ -62,13 +62,6 @@ object DataStore : OnPreferenceDataStoreChangeListener {
val canToggleLocked: Boolean get() = publicStore.getBoolean(Key.directBootAware) == true
val directBootAware: Boolean get() = Core.directBootSupported && canToggleLocked
val tcpFastOpen: Boolean get() = TcpFastOpen.sendEnabled && DataStore.publicStore.getBoolean(Key.tfo, true)
@AppCompatDelegate.NightMode
val nightMode get() = when (publicStore.getString(Key.nightMode)) {
Key.nightModeAuto -> AppCompatDelegate.MODE_NIGHT_AUTO
Key.nightModeOff -> AppCompatDelegate.MODE_NIGHT_NO
Key.nightModeOn -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
val serviceMode get() = publicStore.getString(Key.serviceMode) ?: Key.modeVpn
val listenAddress get() = if (publicStore.getBoolean(Key.shareOverLan, false)) "0.0.0.0" else "127.0.0.1"
var portProxy: Int
......
......@@ -32,12 +32,6 @@ object Key {
const val individual = "Proxyed"
const val nightMode = "nightMode"
const val nightModeSystem = "system"
const val nightModeAuto = "auto"
const val nightModeOff = "off"
const val nightModeOn = "on"
const val serviceMode = "serviceMode"
const val modeProxy = "proxy"
const val modeVpn = "vpn"
......
......@@ -32,6 +32,7 @@ import android.net.Uri
import android.os.Build
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.preference.Preference
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.JniHelper
import java.net.InetAddress
......@@ -88,3 +89,5 @@ fun printLog(t: Throwable) {
Crashlytics.logException(t)
t.printStackTrace()
}
fun Preference.remove() = parent!!.removePreference(this)
......@@ -59,11 +59,6 @@
<string name="tcp_fastopen_summary_unsupported">Unsupported kernel version: %s &lt; 3.7.1</string>
<string name="udp_dns">DNS Forwarding</string>
<string name="udp_dns_summary">Forward all DNS requests to remote</string>
<string name="night_mode">Night mode</string>
<string name="night_mode_system">Follow system</string>
<string name="night_mode_auto">Auto</string>
<string name="night_mode_on">On</string>
<string name="night_mode_off">Off</string>
<!-- notification category -->
<string name="service_vpn">VPN Service</string>
......
......@@ -35,7 +35,6 @@ class App : Application() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
PreferenceFragmentCompat.registerPreferenceFragment(IconListPreference::class.java,
BottomSheetPreferenceDialogFragment::class.java)
AppCompatDelegate.setDefaultNightMode(DataStore.nightMode)
}
override fun onConfigurationChanged(newConfig: Configuration) {
......
......@@ -29,6 +29,7 @@ import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.Key
import com.github.shadowsocks.utils.TcpFastOpen
import com.github.shadowsocks.utils.remove
import com.takisoft.preferencex.PreferenceFragmentCompat
class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
......@@ -48,7 +49,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
if (Build.VERSION.SDK_INT >= 24) canToggleLocked.setOnPreferenceChangeListener { _, newValue ->
if (Core.directBootSupported && newValue as Boolean) DirectBoot.update() else DirectBoot.clean()
true
} else canToggleLocked.parent!!.removePreference(canToggleLocked)
} else canToggleLocked.remove()
val tfo = findPreference(Key.tfo) as SwitchPreference
tfo.isChecked = DataStore.tcpFastOpen
......
......@@ -21,7 +21,7 @@
package com.github.shadowsocks
import android.app.Activity
import android.app.UiModeManager
import android.app.PendingIntent
import android.app.backup.BackupManager
import android.content.ActivityNotFoundException
import android.content.Intent
......@@ -36,11 +36,9 @@ import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.browser.customtabs.CustomTabsIntent
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.core.view.GravityCompat
import androidx.core.view.updateLayoutParams
......@@ -179,11 +177,6 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
val intent = this.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) {
......@@ -221,15 +214,6 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
connection.disconnect()
connection.connect()
}
Key.nightMode -> {
val mode = DataStore.nightMode
AppCompatDelegate.setDefaultNightMode(when (mode) {
AppCompatDelegate.getDefaultNightMode() -> return
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> getSystemService<UiModeManager>()!!.nightMode
else -> mode
})
recreate()
}
}
}
......
......@@ -156,8 +156,7 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
val intent = PluginManager.buildIntent(pluginConfiguration.selected, PluginContract.ACTION_CONFIGURE)
if (intent.resolveActivity(requireContext().packageManager) == null) showPluginEditor() else
startActivityForResult(intent
.putExtra(PluginContract.EXTRA_OPTIONS, pluginConfiguration.selectedOptions.toString())
.putExtra(PluginContract.EXTRA_NIGHT_MODE, DataStore.nightMode),
.putExtra(PluginContract.EXTRA_OPTIONS, pluginConfiguration.selectedOptions.toString()),
REQUEST_CODE_PLUGIN_CONFIGURE)
} else super.onDisplayPreferenceDialog(preference)
}
......
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="?attr/colorControlNormal">
<path android:fillColor="#FF000000" android:pathData="M9,2c-1.05,0 -2.05,0.16 -3,0.46 4.06,1.27 7,5.06 7,9.54 0,4.48 -2.94,8.27 -7,9.54 0.95,0.3 1.95,0.46 3,0.46 5.52,0 10,-4.48 10,-10S14.52,2 9,2z"/>
</vector>
......@@ -25,16 +25,14 @@
<item>@string/acl_rule_online_config</item>
</string-array>
<string-array name="night_modes">
<item>@string/night_mode_system</item>
<item>@string/night_mode_auto</item>
<item>@string/night_mode_off</item>
<item>@string/night_mode_on</item>
<string-array name="service_modes">
<item>@string/service_mode_proxy</item>
<item>@string/service_mode_vpn</item>
<item>@string/service_mode_transproxy</item>
</string-array>
<string-array name="night_mode_values" translatable="false">
<item>system</item>
<item>auto</item>
<item>off</item>
<item>on</item>
<string-array name="service_mode_values" translatable="false">
<item>proxy</item>
<item>vpn</item>
<item>transproxy</item>
</string-array>
</resources>
......@@ -15,14 +15,6 @@
android:icon="@drawable/ic_action_offline_bolt"
android:summary="@string/tcp_fastopen_summary"
android:title="TCP Fast Open"/>
<SimpleMenuPreference
android:key="nightMode"
android:icon="@drawable/ic_image_brightness_3"
android:entries="@array/night_modes"
android:entryValues="@array/night_mode_values"
android:defaultValue="system"
android:summary="%s"
android:title="@string/night_mode"/>
<PreferenceCategory
android:title="@string/advanced">
<SimpleMenuPreference
......
......@@ -24,7 +24,6 @@ import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
/**
* Activity that's capable of getting EXTRA_OPTIONS input.
......@@ -44,13 +43,6 @@ abstract class OptionsCapableActivity : AppCompatActivity() {
*/
protected abstract fun onInitializePluginOptions(options: PluginOptions = pluginOptions())
override fun onCreate(savedInstanceState: Bundle?) {
val nightMode = intent.getIntExtra(PluginContract.EXTRA_NIGHT_MODE, -100) // MODE_NIGHT_UNSPECIFIED
if (nightMode >= AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM && nightMode <= AppCompatDelegate.MODE_NIGHT_YES)
AppCompatDelegate.setDefaultNightMode(nightMode)
super.onCreate(savedInstanceState) // applyDayNight is called in AppCompatActivity.onCreate
}
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
if (savedInstanceState == null) onInitializePluginOptions()
......
......@@ -20,8 +20,6 @@
package com.github.shadowsocks.plugin
import androidx.appcompat.app.AppCompatDelegate
/**
* The contract between the plugin provider and host. Contains definitions for the supported actions, extras, etc.
*
......@@ -73,13 +71,6 @@ object PluginContract {
* Constant Value: "com.github.shadowsocks.plugin.EXTRA_HELP_MESSAGE"
</host_name> */
const val EXTRA_HELP_MESSAGE = "com.github.shadowsocks.plugin.EXTRA_HELP_MESSAGE"
/**
* The lookup key for an @NightMode int that suggests a night mode that is being used in the main app.
*
* Constant Value: "com.github.shadowsocks.plugin.EXTRA_NIGHT_MODE"
*/
@AppCompatDelegate.NightMode
const val EXTRA_NIGHT_MODE = "com.github.shadowsocks.plugin.EXTRA_NIGHT_MODE"
/**
* The metadata key to retrieve plugin id. Required for plugins.
......
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