1. style fixes

2. added about screen
This commit is contained in:
vadym 2020-10-13 20:20:12 +03:00
parent 37748ad304
commit 09d4e6b3fa
5 changed files with 73 additions and 23 deletions

View File

@ -3,8 +3,6 @@ package io.github.chronosx88.yggdrasil
import android.app.Activity import android.app.Activity
import android.app.ActivityManager import android.app.ActivityManager
import android.content.* import android.content.*
import android.net.ConnectivityManager
import android.net.Network
import android.net.VpnService import android.net.VpnService
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -13,12 +11,12 @@ import android.view.Gravity
import android.view.View import android.view.View
import android.widget.* import android.widget.*
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import dalvik.system.DexFile import dalvik.system.DexFile
import io.github.chronosx88.yggdrasil.models.DNSInfo import io.github.chronosx88.yggdrasil.models.DNSInfo
import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.PeerInfo
import io.github.chronosx88.yggdrasil.models.config.DNSInfoListAdapter import io.github.chronosx88.yggdrasil.models.config.DNSInfoListAdapter
import io.github.chronosx88.yggdrasil.models.config.NetworkUtils
import io.github.chronosx88.yggdrasil.models.config.PeerInfoListAdapter import io.github.chronosx88.yggdrasil.models.config.PeerInfoListAdapter
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializePeerStringList2PeerInfoSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializePeerStringList2PeerInfoSet
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
@ -74,7 +72,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar)) setSupportActionBar(findViewById(R.id.toolbar))
isStarted = isYggServiceRunning(this) isStarted = isYggServiceRunning(this)
val switchOn = findViewById<Switch>(R.id.switchOn) val switchOn = findViewById<SwitchCompat>(R.id.switchOn)
switchOn.isChecked = isStarted switchOn.isChecked = isStarted
switchOn.setOnCheckedChangeListener { _, isChecked -> switchOn.setOnCheckedChangeListener { _, isChecked ->
@ -92,12 +90,17 @@ class MainActivity : AppCompatActivity() {
//save to shared preferences //save to shared preferences
val preferences = val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext) PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val staticIP = findViewById<Switch>(R.id.staticIP) val staticIP = findViewById<SwitchCompat>(R.id.staticIP)
staticIP.isChecked = staticIP.isChecked =
preferences.getString(STATIC_IP, null) != null preferences.getString(STATIC_IP, null) != null
val peersListView = findViewById<ListView>(R.id.peers) val peersListView = findViewById<ListView>(R.id.peers)
currentPeers = deserializeStringSet2PeerInfoSet(preferences.getStringSet(CURRENT_PEERS, HashSet())!!) currentPeers = deserializeStringSet2PeerInfoSet(
preferences.getStringSet(
CURRENT_PEERS,
HashSet()
)!!
)
val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping })) val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping }))
peersListView.adapter = adapter peersListView.adapter = adapter
if(isStarted && this.currentPeers.isEmpty()) { if(isStarted && this.currentPeers.isEmpty()) {
@ -125,7 +128,12 @@ class MainActivity : AppCompatActivity() {
} }
val listViewDNS = findViewById<ListView>(R.id.dns) val listViewDNS = findViewById<ListView>(R.id.dns)
currentDNS = deserializeStringSet2DNSInfoSet(preferences.getStringSet(CURRENT_DNS, HashSet())!!) currentDNS = deserializeStringSet2DNSInfoSet(
preferences.getStringSet(
CURRENT_DNS,
HashSet()
)!!
)
val adapterDns = DNSInfoListAdapter(this, currentDNS.sortedWith(compareBy { it.ping })) val adapterDns = DNSInfoListAdapter(this, currentDNS.sortedWith(compareBy { it.ping }))
listViewDNS.adapter = adapterDns listViewDNS.adapter = adapterDns
val editDnsButton = findViewById<Button>(R.id.editDNS) val editDnsButton = findViewById<Button>(R.id.editDNS)
@ -193,10 +201,12 @@ class MainActivity : AppCompatActivity() {
val cl = classLoader val cl = classLoader
val c: Class<*> = dexFile.loadClass("dummy/Dummy", cl) val c: Class<*> = dexFile.loadClass("dummy/Dummy", cl)
} }
val versionName = findViewById<Button>(R.id.about)
versionName.text = """version: ${BuildConfig.VERSION_NAME} build:(${BuildConfig.VERSION_CODE})"""
} }
private fun stopVpn(){ private fun stopVpn(){
Log.i(TAG,"Stop") Log.i(TAG, "Stop")
val intent = Intent(this, YggdrasilTunService::class.java) val intent = Intent(this, YggdrasilTunService::class.java)
val TASK_CODE = 100 val TASK_CODE = 100
val pi = createPendingResult(TASK_CODE, intent, 0) val pi = createPendingResult(TASK_CODE, intent, 0)
@ -206,7 +216,7 @@ class MainActivity : AppCompatActivity() {
} }
private fun startVpn(){ private fun startVpn(){
Log.i(TAG,"Start") Log.i(TAG, "Start")
val intent= VpnService.prepare(this) val intent= VpnService.prepare(this)
if (intent!=null){ if (intent!=null){
startActivityForResult(intent, VPN_REQUEST_CODE) startActivityForResult(intent, VPN_REQUEST_CODE)
@ -216,7 +226,7 @@ class MainActivity : AppCompatActivity() {
} }
private fun updateDNS(){ private fun updateDNS(){
Log.i(TAG,"Update DNS") Log.i(TAG, "Update DNS")
val intent = Intent(this, YggdrasilTunService::class.java) val intent = Intent(this, YggdrasilTunService::class.java)
val TASK_CODE = 100 val TASK_CODE = 100
val pi = createPendingResult(TASK_CODE, intent, 0) val pi = createPendingResult(TASK_CODE, intent, 0)
@ -227,7 +237,7 @@ class MainActivity : AppCompatActivity() {
} }
private fun updatePeers(){ private fun updatePeers(){
Log.d(TAG,"Update Peers") Log.d(TAG, "Update Peers")
val intent = Intent(this, YggdrasilTunService::class.java) val intent = Intent(this, YggdrasilTunService::class.java)
val TASK_CODE = 100 val TASK_CODE = 100
val pi = createPendingResult(TASK_CODE, intent, 0) val pi = createPendingResult(TASK_CODE, intent, 0)
@ -258,9 +268,13 @@ class MainActivity : AppCompatActivity() {
val pi = createPendingResult(TASK_CODE, intent, 0) val pi = createPendingResult(TASK_CODE, intent, 0)
intent.putExtra(PARAM_PINTENT, pi) intent.putExtra(PARAM_PINTENT, pi)
intent.putExtra(COMMAND, START) intent.putExtra(COMMAND, START)
intent.putStringArrayListExtra(CURRENT_PEERS, serializePeerInfoSet2StringList(currentPeers)) intent.putStringArrayListExtra(
CURRENT_PEERS, serializePeerInfoSet2StringList(
currentPeers
)
)
intent.putStringArrayListExtra(CURRENT_DNS, serializeDNSInfoSet2StringList(currentDNS)) intent.putStringArrayListExtra(CURRENT_DNS, serializeDNSInfoSet2StringList(currentDNS))
intent.putExtra(STATIC_IP, findViewById<Switch>(R.id.staticIP).isChecked) intent.putExtra(STATIC_IP, findViewById<SwitchCompat>(R.id.staticIP).isChecked)
startService(intent) startService(intent)
} }
@ -272,7 +286,10 @@ class MainActivity : AppCompatActivity() {
var currentPeers = data.extras!!.getStringArrayList(PEER_LIST) var currentPeers = data.extras!!.getStringArrayList(PEER_LIST)
/*WiFi Direct test. need peer empty list*/ /*WiFi Direct test. need peer empty list*/
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers) this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping })) val adapter = PeerInfoListAdapter(
this,
this.currentPeers.sortedWith(compareBy { it.ping })
)
val listView = findViewById<ListView>(R.id.peers) val listView = findViewById<ListView>(R.id.peers)
listView.adapter = adapter listView.adapter = adapter
@ -297,7 +314,10 @@ class MainActivity : AppCompatActivity() {
if(data!!.extras!=null){ if(data!!.extras!=null){
var currentDNS = data.extras!!.getStringArrayList(DNS_LIST) var currentDNS = data.extras!!.getStringArrayList(DNS_LIST)
this.currentDNS = deserializeStringList2DNSInfoSet(currentDNS) this.currentDNS = deserializeStringList2DNSInfoSet(currentDNS)
val adapter = DNSInfoListAdapter(this, this.currentDNS.sortedWith(compareBy { it.ping })) val adapter = DNSInfoListAdapter(
this,
this.currentDNS.sortedWith(compareBy { it.ping })
)
val listView = findViewById<ListView>(R.id.dns) val listView = findViewById<ListView>(R.id.dns)
listView.adapter = adapter listView.adapter = adapter
//save to shared preferences //save to shared preferences
@ -313,7 +333,7 @@ class MainActivity : AppCompatActivity() {
when (resultCode) { when (resultCode) {
STATUS_START -> { STATUS_START -> {
print("service started") print("service started")
if(this.currentPeers.isEmpty()){ if (this.currentPeers.isEmpty()) {
checkPeers() checkPeers()
} }
} }
@ -329,8 +349,8 @@ class MainActivity : AppCompatActivity() {
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout) val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
ipLayout.visibility = View.GONE ipLayout.visibility = View.GONE
} }
STATUS_PEERS_UPDATE ->{ STATUS_PEERS_UPDATE -> {
if(data!!.extras!=null) { if (data!!.extras != null) {
thread(start = true) { thread(start = true) {
val meshPeers = deserializePeerStringList2PeerInfoSet( val meshPeers = deserializePeerStringList2PeerInfoSet(
data.extras!!.getStringArrayList(MESH_PEERS) data.extras!!.getStringArrayList(MESH_PEERS)
@ -338,7 +358,8 @@ class MainActivity : AppCompatActivity() {
val listView = findViewById<ListView>(R.id.peers) val listView = findViewById<ListView>(R.id.peers)
val adapter = PeerInfoListAdapter( val adapter = PeerInfoListAdapter(
this@MainActivity, this@MainActivity,
meshPeers.filter { it.schema!="self" }.sortedWith(compareBy { it.ping }) meshPeers.filter { it.schema != "self" }
.sortedWith(compareBy { it.ping })
) )
runOnUiThread { runOnUiThread {
listView.adapter = adapter listView.adapter = adapter

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/grey">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/about"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
</LinearLayout>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -30,7 +30,7 @@
app:popupTheme="@style/AppTheme.PopupOverlay" app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_marginRight="240dp" /> android:layout_marginRight="240dp" />
<Switch <androidx.appcompat.widget.SwitchCompat
android:id="@+id/staticIP" android:id="@+id/staticIP"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -42,7 +42,7 @@
android:text="Static IP" android:text="Static IP"
android:textColor="@color/white"/> android:textColor="@color/white"/>
<Switch <androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchOn" android:id="@+id/switchOn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -152,5 +152,12 @@
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>
</LinearLayout> </LinearLayout>
<Button
android:id="@+id/about"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
android:text=""
android:textSize="12sp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,6 +2,6 @@
<resources> <resources>
<style name="SwitchTheme" parent="Theme.AppCompat.Light"> <style name="SwitchTheme" parent="Theme.AppCompat.Light">
<item name="android:colorControlActivated">@color/green</item> <item name="colorControlActivated">@color/green</item>
</style> </style>
</resources> </resources>