Fixes #30, added quick settings icon. (#32)

* Fixes #30, added quick settings icon.
* Added saving of enabled state, added some fixes and refactorings.
* Fixed a bug with turning on/off the VPN.
* Fixed possibility to add duplicate servers in DNS settings.
This commit is contained in:
Revertron 2022-11-19 20:49:34 +01:00 committed by GitHub
parent ee81f4e902
commit aa94ccad26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 441 additions and 60 deletions

View file

@ -11,7 +11,9 @@ import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import eu.neilalexander.yggdrasil.PacketTunnelProvider.Companion.STATE_INTENT
import mobile.Mobile
import org.json.JSONArray
@ -76,6 +78,8 @@ class MainActivity : AppCompatActivity() {
startService(intent)
}
}
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
preferences.edit(commit = true) { putBoolean(PREF_KEY_ENABLED, isChecked) }
}
val enableYggdrasilPanel = findViewById<TableRow>(R.id.enableYggdrasilPanel)
@ -123,7 +127,8 @@ class MainActivity : AppCompatActivity() {
LocalBroadcastManager.getInstance(this).registerReceiver(
receiver, IntentFilter(STATE_INTENT)
)
val preferences = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
enabledSwitch.isChecked = preferences.getBoolean(PREF_KEY_ENABLED, false)
val serverString = preferences.getString(KEY_DNS_SERVERS, "")
if (serverString!!.isNotEmpty()) {
val servers = serverString.split(",")
@ -149,7 +154,6 @@ class MainActivity : AppCompatActivity() {
when (intent.getStringExtra("type")) {
"state" -> {
enabledLabel.text = if (intent.getBooleanExtra("started", false)) {
enabledSwitch.isChecked = true
var count = 0
if (intent.hasExtra("dht")) {
val dht = intent.getStringExtra("dht")
@ -166,7 +170,6 @@ class MainActivity : AppCompatActivity() {
getString(R.string.main_enabled)
}
} else {
enabledSwitch.isChecked = false
enabledLabel.setTextColor(Color.GRAY)
getString(R.string.main_disabled)
}