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.ActivityManager
import android.content.*
import android.net.ConnectivityManager
import android.net.Network
import android.net.VpnService
import android.os.Build
import android.os.Bundle
@ -13,12 +11,12 @@ import android.view.Gravity
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import androidx.preference.PreferenceManager
import dalvik.system.DexFile
import io.github.chronosx88.yggdrasil.models.DNSInfo
import io.github.chronosx88.yggdrasil.models.PeerInfo
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.Utils.Companion.deserializePeerStringList2PeerInfoSet
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
@ -74,7 +72,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar))
isStarted = isYggServiceRunning(this)
val switchOn = findViewById<Switch>(R.id.switchOn)
val switchOn = findViewById<SwitchCompat>(R.id.switchOn)
switchOn.isChecked = isStarted
switchOn.setOnCheckedChangeListener { _, isChecked ->
@ -92,12 +90,17 @@ class MainActivity : AppCompatActivity() {
//save to shared preferences
val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val staticIP = findViewById<Switch>(R.id.staticIP)
val staticIP = findViewById<SwitchCompat>(R.id.staticIP)
staticIP.isChecked =
preferences.getString(STATIC_IP, null) != null
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 }))
peersListView.adapter = adapter
if(isStarted && this.currentPeers.isEmpty()) {
@ -125,7 +128,12 @@ class MainActivity : AppCompatActivity() {
}
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 }))
listViewDNS.adapter = adapterDns
val editDnsButton = findViewById<Button>(R.id.editDNS)
@ -193,6 +201,8 @@ class MainActivity : AppCompatActivity() {
val cl = classLoader
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(){
@ -258,9 +268,13 @@ class MainActivity : AppCompatActivity() {
val pi = createPendingResult(TASK_CODE, intent, 0)
intent.putExtra(PARAM_PINTENT, pi)
intent.putExtra(COMMAND, START)
intent.putStringArrayListExtra(CURRENT_PEERS, serializePeerInfoSet2StringList(currentPeers))
intent.putStringArrayListExtra(
CURRENT_PEERS, serializePeerInfoSet2StringList(
currentPeers
)
)
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)
}
@ -272,7 +286,10 @@ class MainActivity : AppCompatActivity() {
var currentPeers = data.extras!!.getStringArrayList(PEER_LIST)
/*WiFi Direct test. need peer empty list*/
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)
listView.adapter = adapter
@ -297,7 +314,10 @@ class MainActivity : AppCompatActivity() {
if(data!!.extras!=null){
var currentDNS = data.extras!!.getStringArrayList(DNS_LIST)
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)
listView.adapter = adapter
//save to shared preferences
@ -338,7 +358,8 @@ class MainActivity : AppCompatActivity() {
val listView = findViewById<ListView>(R.id.peers)
val adapter = PeerInfoListAdapter(
this@MainActivity,
meshPeers.filter { it.schema!="self" }.sortedWith(compareBy { it.ping })
meshPeers.filter { it.schema != "self" }
.sortedWith(compareBy { it.ping })
)
runOnUiThread {
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"
android:layout_marginRight="240dp" />
<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/staticIP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -42,7 +42,7 @@
android:text="Static IP"
android:textColor="@color/white"/>
<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchOn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -152,5 +152,12 @@
app:layout_constraintTop_toTopOf="parent"/>
</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>

View File

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