浏览代码

Add option to show stop button force

世界 4 年之前
父节点
当前提交
f2c23c853f

+ 1 - 1
README.md

@@ -49,7 +49,7 @@ The application is designed to be used whenever possible.
     <li><a href="https://github.com/nekohasekai/AndroidLibV2rayLite">AndroidLibV2rayLite</a>: LGPL 3.0</li>
     <li><a href="https://github.com/shadowsocksRb/shadowsocksr-libev/blob/master/LICENSE">shadowsocksr-libev</a>: GPL 3.0</li>
     <li><a href="https://github.com/XTLS/Xray-core/blob/main/LICENSE">Xray-core</a>: MPL 2.0</li>
-    <li><a href="https://github.com/p4gefau1t/trojan-go/blob/master/LICENSE">Trojan-Go: GPL 3.0</a> </li>
+    <li><a href="https://github.com/p4gefau1t/trojan-go/blob/master/LICENSE">Trojan-Go</a>: GPL 3.0</li>
 </ul>
 
 ### LICENSE

+ 1 - 0
app/src/main/java/io/nekohasekai/sagernet/Constants.kt

@@ -63,6 +63,7 @@ object Key {
 
     const val ENABLE_MUX = "enableMux"
     const val MUX_CONCURRENCY = "muxConcurrency"
+    const val SHOW_STOP_BUTTON = "showStopButton"
 
     const val PROFILE_DIRTY = "profileDirty"
     const val PROFILE_ID = "profileId"

+ 1 - 2
app/src/main/java/io/nekohasekai/sagernet/SagerNet.kt

@@ -123,8 +123,7 @@ class SagerNet : Application() {
         DataStore.init()
         updateNotificationChannels()
 
-        Seq.setContext(applicationContext)
-
+        Seq.setContext(this)
         application.filesDir.mkdirs()
         Libv2ray.setAssetsPath(application.filesDir.absolutePath, "v2ray/")
     }

+ 1 - 1
app/src/main/java/io/nekohasekai/sagernet/bg/ServiceNotification.kt

@@ -98,7 +98,7 @@ class ServiceNotification(
                 0)).apply {
             setShowsUserInterface(false)
         }.build()
-        if (Build.VERSION.SDK_INT < 24) builder.addAction(closeAction) else builder.addInvisibleAction(
+        if (Build.VERSION.SDK_INT < 24 || DataStore.showStopButton) builder.addAction(closeAction) else builder.addInvisibleAction(
             closeAction)
         updateCallback(service.getSystemService<PowerManager>()?.isInteractive != false)
         service.registerReceiver(this, IntentFilter().apply {

+ 1 - 0
app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt

@@ -121,6 +121,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
     var requireHttp by configurationStore.boolean(Key.REQUIRE_HTTP)
     var enableMux by configurationStore.boolean(Key.ENABLE_MUX)
     var muxConcurrency by configurationStore.stringToInt(Key.MUX_CONCURRENCY) { 8 }
+    var showStopButton by configurationStore.boolean(Key.SHOW_STOP_BUTTON)
 
     val persistAcrossReboot by configurationStore.boolean(Key.PERSIST_ACROSS_REBOOT) { true }
     val canToggleLocked: Boolean get() = configurationStore.getBoolean(Key.DIRECT_BOOT_AWARE) == true

+ 5 - 0
app/src/main/java/io/nekohasekai/sagernet/ui/SettingsPreferenceFragment.kt

@@ -51,6 +51,10 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
         val allowAccess = findPreference<Preference>(Key.ALLOW_ACCESS)!!
         val requireHttp = findPreference<SwitchPreference>(Key.REQUIRE_HTTP)!!
         val portHttp = findPreference<EditTextPreference>(Key.HTTP_PORT)!!
+        val showStopButton = findPreference<SwitchPreference>(Key.SHOW_STOP_BUTTON)!!
+        if (Build.VERSION.SDK_INT < 24) {
+            showStopButton.isVisible = false
+        }
 
         portSocks5.setOnBindEditTextListener(EditTextPreferenceModifiers.Port)
         portHttp.setOnBindEditTextListener(EditTextPreferenceModifiers.Port)
@@ -75,6 +79,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
                 portSocks5.isEnabled = stopped
                 requireHttp.isEnabled = stopped
                 portHttp.isEnabled = stopped
+                showStopButton.isEnabled = stopped
 
                 metedNetwork.isEnabled = sMode == Key.MODE_VPN && stopped
 

+ 31 - 0
app/src/main/res/drawable/ic_baseline_multiple_stop_24.xml

@@ -0,0 +1,31 @@
+<!--
+  ~
+  ~ Copyright (C) 2021 by nekohasekai <[email protected]>
+  ~ Copyright (C) 2021 by Max Lv <[email protected]>
+  ~ Copyright (C) 2021 by Mygod Studio <[email protected]>
+  ~
+  ~ This program is free software: you can redistribute it and/or modify
+  ~ it under the terms of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~  (at your option) any later version.
+  ~
+  ~ This program is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  ~ GNU General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
+  ~
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?attr/colorControlNormal">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M17,4l4,4l-4,4V9h-4V7h4V4zM10,7C9.45,7 9,7.45 9,8s0.45,1 1,1s1,-0.45 1,-1S10.55,7 10,7zM6,7C5.45,7 5,7.45 5,8s0.45,1 1,1s1,-0.45 1,-1S6.55,7 6,7zM7,17h4v-2H7v-3l-4,4l4,4V17zM14,17c0.55,0 1,-0.45 1,-1c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1C13,16.55 13.45,17 14,17zM18,17c0.55,0 1,-0.45 1,-1c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1C17,16.55 17.45,17 18,17z" />
+</vector>

+ 3 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -270,5 +270,8 @@
     <string name="deduplication">去重</string>
     <string name="version_x">版本 (%s)</string>
     <string name="flow">流控</string>
+    <string name="show_stop">显示停止按钮</string>
+    <string name="show_stop_sum">如果您不想使用快捷图块</string>
+    <string name="ss_cat">Shadowsocks 设置</string>
 
 </resources>

+ 0 - 7
app/src/main/res/values-zh-rTW/strings.xml

@@ -161,13 +161,6 @@
     <string name="share">分享</string>
     <string name="add_profile">新增設定檔</string>
     <string name="action_profile">設定檔</string>
-    <string name="action_socks">SOCKS</string>
-    <string name="action_http">HTTP</string>
-    <string name="action_shadowsocks">Shadowsocks</string>
-    <string name="action_shadowsocksr">ShadowsocksR</string>
-    <string name="action_vmess">VMess</string>
-    <string name="action_vless">VLESS</string>
-    <string name="action_trojan">Trojan</string>
 
     <string name="action_create_group">空白群組</string>
     <string name="action_from_link">來自訂閱</string>

+ 10 - 8
app/src/main/res/values/strings.xml

@@ -76,6 +76,8 @@
     <string name="speed_interval">Speed notification update interval</string>
     <string name="disable">Disable</string>
     <string name="cag_misc">Misc Settings</string>
+    <string name="show_stop">Show stop button</string>
+    <string name="show_stop_sum">If you don’t want to use Quick Tile as the switch</string>
 
     <string name="traffic">%1$s↑ %2$s↓</string>
     <string name="stat_summary">Sent: \t\t\t\t\t%3$s\t↑\t%1$s\nReceived: \t%4$s\t↓\t%2$s</string>
@@ -195,14 +197,14 @@
     <string name="share">Share</string>
     <string name="add_profile">Add Profile</string>
     <string name="action_profile">Profile</string>
-    <string name="action_socks">SOCKS</string>
-    <string name="action_http">HTTP</string>
-    <string name="action_shadowsocks">Shadowsocks</string>
-    <string name="action_shadowsocksr">ShadowsocksR</string>
-    <string name="action_vmess">VMess</string>
-    <string name="action_vless">VLESS</string>
-    <string name="action_trojan">Trojan</string>
-    <string name="action_trojan_go">Trojan Go</string>
+    <string name="action_socks" translatable="false">SOCKS</string>
+    <string name="action_http" translatable="false">HTTP</string>
+    <string name="action_shadowsocks" translatable="false">Shadowsocks</string>
+    <string name="action_shadowsocksr" translatable="false">ShadowsocksR</string>
+    <string name="action_vmess" translatable="false">VMess</string>
+    <string name="action_vless" translatable="false">VLESS</string>
+    <string name="action_trojan" translatable="false">Trojan</string>
+    <string name="action_trojan_go" translatable="false">Trojan Go</string>
 
     <string name="action_create_group">Empty group</string>
     <string name="action_from_link">From subscription</string>

+ 5 - 0
app/src/main/res/xml/global_preferences.xml

@@ -33,6 +33,11 @@
         app:key="speedInterval"
         app:title="@string/speed_interval"
         app:useSimpleSummaryProvider="true" />
+    <SwitchPreference
+        app:icon="@drawable/ic_baseline_multiple_stop_24"
+        app:key="showStopButton"
+        app:summary="@string/show_stop_sum"
+        app:title="@string/show_stop" />
 
     <SwitchPreference
         app:icon="@drawable/ic_baseline_nat_24"