From 63f777d2c42990f2f1a3672e87d5c6244c18e8f7 Mon Sep 17 00:00:00 2001 From: vadym Date: Sun, 28 Jun 2020 04:55:48 -0700 Subject: [PATCH] 1. VPN DNS refactoring, GUI refactoring --- app/src/main/AndroidManifest.xml | 3 +- .../chronosx88/yggdrasil/MainActivity.kt | 81 +++++---- .../yggdrasil/YggdrasilTunService.kt | 94 +++++----- .../yggdrasil/models/config/Utils.kt | 9 + app/src/main/res/layout/activity_main.xml | 164 +++--------------- app/src/main/res/layout/content_main.xml | 156 +++++++++++++++++ app/src/main/res/layout/menu_switch.xml | 9 +- 7 files changed, 284 insertions(+), 232 deletions(-) create mode 100644 app/src/main/res/layout/content_main.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 418949e..102d634 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,6 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning"> diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index 55792e8..edd6bff 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -10,8 +10,6 @@ import android.net.VpnService import android.os.Bundle import android.util.Log import android.view.Gravity -import android.view.Menu -import android.view.MenuItem import android.view.View import android.widget.* import androidx.appcompat.app.AppCompatActivity @@ -34,6 +32,7 @@ class MainActivity : AppCompatActivity() { const val COMMAND = "COMMAND" const val STOP = "STOP" const val START = "START" + const val UPDATE_DNS = "UPDATE_DNS" const val PARAM_PINTENT = "pendingIntent" const val STATUS_START = 7 const val STATUS_FINISH = 8 @@ -52,6 +51,7 @@ class MainActivity : AppCompatActivity() { private const val VPN_REQUEST_CODE = 0x0F @JvmStatic var isStarted = false + @JvmStatic var isCancelled = false } @@ -62,19 +62,41 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + setSupportActionBar(findViewById(R.id.toolbar)) if(intent.extras!==null) { startVpnFlag = intent.extras!!.getBoolean(START_VPN, false) isStarted = true + //startVpn() } else { isStarted = isYggServiceRunning(this) } - val listView = findViewById(R.id.peers) + + val switchOn = findViewById(R.id.switchOn) + switchOn.isChecked = isStarted + switchOn.setOnCheckedChangeListener { _, isChecked -> + if(currentPeers.isEmpty()){ + switchOn.isChecked = false + return@setOnCheckedChangeListener + } + if(isCancelled){ + switchOn.isChecked = false + isCancelled = false + return@setOnCheckedChangeListener + } + if (isChecked) { + startVpn() + } else { + stopVpn() + } + } + + val peersListView = findViewById(R.id.peers) //save to shared preferences val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext) currentPeers = deserializeStringSet2PeerInfoSet(preferences.getStringSet(CURRENT_PEERS, HashSet())!!) val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping })) - listView.adapter = adapter + peersListView.adapter = adapter val copyAddressButton = findViewById