Commit 468560a0 authored by Max Lv's avatar Max Lv

Merge pull request #415 from Mygod/master

Adjust preference order
parents a7d72938 a88ec04c
......@@ -4,12 +4,13 @@
<string name="app_name">Shadowsocks</string>
<string name="screen_name">shadowsocks</string>
<!-- global category -->
<!-- global/misc category -->
<string name="global_cat">Global Settings</string>
<string name="misc_cat">Misc</string>
<string name="profile">Profile</string>
<string name="profile_summary">Switch to another profile</string>
<string name="nat">NAT mode</string>
<string name="nat_summary">Use NAT/VPN mode.</string>
<string name="nat">NAT mode (deprecated)</string>
<string name="nat_summary">Use NAT mode instead of VPN mode.</string>
<string name="nat_summary_no_root">NAT mode is disabled without root.</string>
<!-- proxy category -->
......
......@@ -2,12 +2,21 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.github.shadowsocks">
<PreferenceCategory
android:title="@string/proxy_cat">
<PreferenceCategory android:title="@string/global_cat">
<Preference android:summary="@string/profile_summary" android:title="@string/profiles">
<Preference android:key="profiles" android:summary="@string/profile_summary" android:title="@string/profiles">
<intent android:action="com.github.shadowsocks.ProfileManagerActivity"/>
</Preference>
<SwitchPreference
android:key="isAutoConnect"
android:summary="@string/auto_connect_summary"
android:title="@string/auto_connect"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/proxy_cat">
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue="Default"
android:key="profileName"
......@@ -86,18 +95,16 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/global_cat">
<PreferenceCategory android:title="@string/misc_cat">
<com.github.shadowsocks.preferences.NatSwitchPreference android:key="isNAT"
android:title="@string/nat"
android:summary="@string/nat_summary"/>
<SwitchPreference
android:key="isAutoConnect"
android:summary="@string/auto_connect_summary"
android:title="@string/auto_connect"/>
<Preference android:key="recovery" android:title="@string/recovery"
android:summary="@string/recovery_summary"/>
<Preference android:key="flush_dnscache" android:title="@string/flush_dnscache"
android:summary="@string/flush_dnscache_summary"/>
android:summary="@string/flush_dnscache_summary"/>
<Preference android:key="about" android:title="@string/about"/>
</PreferenceCategory>
......
......@@ -43,11 +43,11 @@ import java.util
import java.util.Locale
import android.app.backup.BackupManager
import android.app.{Activity, AlertDialog, ProgressDialog}
import android.app.{Activity, ProgressDialog}
import android.content._
import android.content.res.AssetManager
import android.graphics.Typeface
import android.net.{Uri, VpnService}
import android.net.VpnService
import android.os._
import android.preference.{Preference, SwitchPreference}
import android.support.design.widget.{FloatingActionButton, Snackbar}
......@@ -56,7 +56,6 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.util.Log
import android.view.{View, ViewGroup, ViewParent}
import android.webkit.{WebView, WebViewClient}
import android.widget._
import com.github.jorgecastilloprz.FABProgressCircle
import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback}
......@@ -97,7 +96,7 @@ object Shadowsocks {
val REQUEST_CONNECT = 1
val PREFS_NAME = "Shadowsocks"
val PROXY_PREFS = Array(Key.proxy, Key.remotePort, Key.localPort, Key.sitekey, Key.encMethod)
val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey, Key.encMethod)
val FEATURE_PREFS = Array(Key.route, Key.isGlobalProxy, Key.proxyedApps, Key.isUdpDns, Key.isAuth, Key.isIpv6)
val EXECUTABLES = Array(Executable.PDNSD, Executable.REDSOCKS, Executable.SS_TUNNEL, Executable.SS_LOCAL,
Executable.TUN2SOCKS)
......@@ -141,7 +140,6 @@ object Shadowsocks {
class Shadowsocks
extends AppCompatActivity {
import Shadowsocks._
// Variables
private var serviceStarted = false
......@@ -377,10 +375,6 @@ class Shadowsocks
val title: TextView = field.get(toolbar).asInstanceOf[TextView]
val tf: Typeface = Typefaces.get(this, "fonts/Iceland.ttf")
if (tf != null) title.setTypeface(tf)
title.setOnClickListener((view: View) => {
ShadowsocksApplication.track(TAG, "about")
showAbout()
})
fab = findViewById(R.id.fab).asInstanceOf[FloatingActionButton]
fabProgressCircle = findViewById(R.id.fabProgressCircle).asInstanceOf[FABProgressCircle]
......@@ -496,6 +490,7 @@ class Shadowsocks
}
private def setPreferenceEnabled(enabled: Boolean) {
preferences.findPreference(Key.profiles).setEnabled(enabled)
preferences.findPreference(Key.isNAT).setEnabled(enabled)
for (name <- Shadowsocks.PROXY_PREFS) {
val pref = preferences.findPreference(name)
......@@ -518,7 +513,6 @@ class Shadowsocks
private def updatePreferenceScreen() {
val profile = currentProfile
Shadowsocks.updatePreference(preferences.findPreference(Key.profileName), Key.profileName, profile)
for (name <- Shadowsocks.PROXY_PREFS) {
val pref = preferences.findPreference(name)
Shadowsocks.updatePreference(pref, name, profile)
......@@ -636,26 +630,6 @@ class Shadowsocks
}
}
private def showAbout() {
val web = new WebView(this)
web.loadUrl("file:///android_asset/pages/about.html")
web.setWebViewClient(new WebViewClient() {
override def shouldOverrideUrlLoading(view: WebView, url: String): Boolean = {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)))
true
}
})
new AlertDialog.Builder(this)
.setTitle(getString(R.string.about_title).formatLocal(Locale.ENGLISH, ShadowsocksApplication.getVersionName))
.setCancelable(false)
.setNegativeButton(getString(android.R.string.ok),
((dialog: DialogInterface, id: Int) => dialog.cancel()): DialogInterface.OnClickListener)
.setView(web)
.create()
.show()
}
def clearDialog() {
if (progressDialog != null) {
progressDialog.dismiss()
......
package com.github.shadowsocks
import java.util.Locale
import android.app.AlertDialog
import android.content.{DialogInterface, Intent}
import android.net.Uri
import android.os.Bundle
import android.preference.{Preference, PreferenceFragment}
import android.webkit.{WebViewClient, WebView}
import com.github.shadowsocks.utils.Key
// TODO: Move related logic here
......@@ -11,20 +17,45 @@ class ShadowsocksSettings extends PreferenceFragment {
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.pref_all)
findPreference(Key.isNAT).setOnPreferenceChangeListener((preference: Preference, newValue: Any) =>
if (ShadowsocksApplication.isRoot) activity.handler.post(() => {
activity.deattachService()
activity.attachService()
}) else false)
findPreference("recovery").setOnPreferenceClickListener((preference: Preference) => {
ShadowsocksApplication.track(Shadowsocks.TAG, "reset")
activity.recovery()
true
})
findPreference("flush_dnscache").setOnPreferenceClickListener((preference: Preference) => {
ShadowsocksApplication.track(Shadowsocks.TAG, "flush_dnscache")
activity.flushDnsCache()
true
})
findPreference("about").setOnPreferenceClickListener((preference: Preference) => {
ShadowsocksApplication.track(Shadowsocks.TAG, "about")
val web = new WebView(activity)
web.loadUrl("file:///android_asset/pages/about.html")
web.setWebViewClient(new WebViewClient() {
override def shouldOverrideUrlLoading(view: WebView, url: String): Boolean = {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)))
true
}
})
new AlertDialog.Builder(activity)
.setTitle(getString(R.string.about_title).formatLocal(Locale.ENGLISH, ShadowsocksApplication.getVersionName))
.setCancelable(false)
.setNegativeButton(getString(android.R.string.ok),
((dialog: DialogInterface, id: Int) => dialog.cancel()): DialogInterface.OnClickListener)
.setView(web)
.create()
.show()
true
})
}
}
......@@ -65,6 +65,7 @@ object Key {
val proxied = "Proxyed"
val profiles = "profiles"
val isNAT = "isNAT"
val proxyedApps = "proxyedApps"
val route = "route"
......
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