Commit 5e4e82b3 authored by Mygod's avatar Mygod

Refine code style

parent 4315b91b
...@@ -121,8 +121,7 @@ class Acl { ...@@ -121,8 +121,7 @@ class Acl {
val blocks = (line as java.lang.String).split("#", 2) val blocks = (line as java.lang.String).split("#", 2)
val url = networkAclParser.matchEntire(blocks.getOrElse(1) { "" })?.groupValues?.getOrNull(1) val url = networkAclParser.matchEntire(blocks.getOrElse(1) { "" })?.groupValues?.getOrNull(1)
if (url != null) urls.add(URL(url)) if (url != null) urls.add(URL(url))
val input = blocks[0].trim() when (val input = blocks[0].trim()) {
when (input) {
"[outbound_block_list]" -> { "[outbound_block_list]" -> {
hostnames = null hostnames = null
subnets = null subnets = null
......
...@@ -40,7 +40,7 @@ object LocalDnsService { ...@@ -40,7 +40,7 @@ object LocalDnsService {
.lineSequence().map(Subnet.Companion::fromString).filterNotNull().toList() .lineSequence().map(Subnet.Companion::fromString).filterNotNull().toList()
} }
private val servers = WeakHashMap<LocalDnsService.Interface, LocalDnsServer>() private val servers = WeakHashMap<Interface, LocalDnsServer>()
interface Interface : BaseService.Interface { interface Interface : BaseService.Interface {
override suspend fun startProcesses() { override suspend fun startProcesses() {
......
...@@ -129,11 +129,11 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -129,11 +129,11 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (DataStore.serviceMode == Key.modeVpn) if (DataStore.serviceMode == Key.modeVpn) {
if (BaseVpnService.prepare(this) != null) if (prepare(this) != null) {
startActivity(Intent(this, VpnRequestActivity::class.java) startActivity(Intent(this, VpnRequestActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) } else return super<LocalDnsService.Interface>.onStartCommand(intent, flags, startId)
else return super<LocalDnsService.Interface>.onStartCommand(intent, flags, startId) }
stopRunner() stopRunner()
return Service.START_NOT_STICKY return Service.START_NOT_STICKY
} }
......
...@@ -62,7 +62,7 @@ object DefaultNetworkListener { ...@@ -62,7 +62,7 @@ object DefaultNetworkListener {
check(listeners.isNotEmpty()) { "Getting network without any listeners is not supported" } check(listeners.isNotEmpty()) { "Getting network without any listeners is not supported" }
if (network == null) pendingRequests += message else message.response.complete(network) if (network == null) pendingRequests += message else message.response.complete(network)
} }
is NetworkMessage.Stop -> if (!listeners.isEmpty() && // was not empty is NetworkMessage.Stop -> if (listeners.isNotEmpty() && // was not empty
listeners.remove(message.key) != null && listeners.isEmpty()) { listeners.remove(message.key) != null && listeners.isEmpty()) {
network = null network = null
unregister() unregister()
......
...@@ -44,7 +44,7 @@ object DataStore : OnPreferenceDataStoreChangeListener { ...@@ -44,7 +44,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
override fun onPreferenceDataStoreChanged(store: PreferenceDataStore, key: String?) { override fun onPreferenceDataStoreChanged(store: PreferenceDataStore, key: String?) {
when (key) { when (key) {
Key.id -> if (DataStore.directBootAware) DirectBoot.update() Key.id -> if (directBootAware) DirectBoot.update()
} }
} }
......
...@@ -69,7 +69,7 @@ class AppManager : AppCompatActivity() { ...@@ -69,7 +69,7 @@ class AppManager : AppCompatActivity() {
receiver = null receiver = null
cachedApps = null cachedApps = null
} }
AppManager.instance?.loadApps() instance?.loadApps()
} }
// Labels and icons can change on configuration (locale, etc.) changes, therefore they are not cached. // Labels and icons can change on configuration (locale, etc.) changes, therefore they are not cached.
val cachedApps = cachedApps ?: pm.getInstalledPackages(PackageManager.GET_PERMISSIONS) val cachedApps = cachedApps ?: pm.getInstalledPackages(PackageManager.GET_PERMISSIONS)
...@@ -109,7 +109,7 @@ class AppManager : AppCompatActivity() { ...@@ -109,7 +109,7 @@ class AppManager : AppCompatActivity() {
} }
fun handlePayload(payloads: List<String>) { fun handlePayload(payloads: List<String>) {
if (payloads.contains(AppManager.SWITCH)) itemView.itemcheck.isChecked = isProxiedApp(item) if (payloads.contains(SWITCH)) itemView.itemcheck.isChecked = isProxiedApp(item)
} }
override fun onClick(v: View?) { override fun onClick(v: View?) {
...@@ -117,7 +117,7 @@ class AppManager : AppCompatActivity() { ...@@ -117,7 +117,7 @@ class AppManager : AppCompatActivity() {
DataStore.individual = apps.filter { isProxiedApp(it) }.joinToString("\n") { it.packageName } DataStore.individual = apps.filter { isProxiedApp(it) }.joinToString("\n") { it.packageName }
DataStore.dirty = true DataStore.dirty = true
appsAdapter.notifyItemRangeChanged(0, appsAdapter.itemCount, AppManager.SWITCH) appsAdapter.notifyItemRangeChanged(0, appsAdapter.itemCount, SWITCH)
} }
} }
...@@ -281,7 +281,7 @@ class AppManager : AppCompatActivity() { ...@@ -281,7 +281,7 @@ class AppManager : AppCompatActivity() {
DataStore.dirty = true DataStore.dirty = true
Snackbar.make(list, R.string.action_import_msg, Snackbar.LENGTH_LONG).show() Snackbar.make(list, R.string.action_import_msg, Snackbar.LENGTH_LONG).show()
initProxiedUids(apps) initProxiedUids(apps)
appsAdapter.notifyItemRangeChanged(0, appsAdapter.itemCount, AppManager.SWITCH) appsAdapter.notifyItemRangeChanged(0, appsAdapter.itemCount, SWITCH)
return true return true
} catch (_: IllegalArgumentException) { } } catch (_: IllegalArgumentException) { }
} }
......
...@@ -41,7 +41,7 @@ class QuickToggleShortcut : Activity(), ShadowsocksConnection.Callback { ...@@ -41,7 +41,7 @@ class QuickToggleShortcut : Activity(), ShadowsocksConnection.Callback {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
if (intent.action == Intent.ACTION_CREATE_SHORTCUT) { if (intent.action == Intent.ACTION_CREATE_SHORTCUT) {
setResult(Activity.RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this,
ShortcutInfoCompat.Builder(this, "toggle") ShortcutInfoCompat.Builder(this, "toggle")
.setIntent(Intent(this, QuickToggleShortcut::class.java).setAction(Intent.ACTION_MAIN)) .setIntent(Intent(this, QuickToggleShortcut::class.java).setAction(Intent.ACTION_MAIN))
.setIcon(IconCompat.createWithResource(this, R.drawable.ic_qu_shadowsocks_launcher)) .setIcon(IconCompat.createWithResource(this, R.drawable.ic_qu_shadowsocks_launcher))
......
...@@ -42,25 +42,22 @@ class PluginOptions : HashMap<String, String?> { ...@@ -42,25 +42,22 @@ class PluginOptions : HashMap<String, String?> {
val tokenizer = StringTokenizer("$options;", "\\=;", true) val tokenizer = StringTokenizer("$options;", "\\=;", true)
val current = StringBuilder() val current = StringBuilder()
var key: String? = null var key: String? = null
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) when (val nextToken = tokenizer.nextToken()) {
val nextToken = tokenizer.nextToken() "\\" -> current.append(tokenizer.nextToken())
when (nextToken) { "=" -> if (key == null) {
"\\" -> current.append(tokenizer.nextToken()) key = current.toString()
"=" -> if (key == null) { current.setLength(0)
key = current.toString() } else current.append(nextToken)
current.setLength(0) ";" -> {
} else current.append(nextToken) if (key != null) {
";" -> { put(key, current.toString())
if (key != null) { key = null
put(key, current.toString()) } else if (current.isNotEmpty())
key = null if (parseId) id = current.toString() else put(current.toString(), null)
} else if (current.isNotEmpty()) current.setLength(0)
if (parseId) id = current.toString() else put(current.toString(), null) parseId = false
current.setLength(0)
parseId = false
}
else -> current.append(nextToken)
} }
else -> current.append(nextToken)
} }
} }
......
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