1. DNS refresh fix

This commit is contained in:
vadym 2020-06-27 14:58:44 -07:00
parent a8eaa5fc9d
commit 50a107cea4
5 changed files with 40 additions and 11 deletions

View File

@ -35,7 +35,6 @@
</service>
<activity android:name=".MainActivity"
android:launchMode= "singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -42,6 +42,8 @@ class DNSListActivity : AppCompatActivity() {
)
}
var isLoading = true;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dns_list)
@ -74,6 +76,7 @@ class DNSListActivity : AppCompatActivity() {
Runnable
{
adapter.sort()
isLoading = false
}
)
}
@ -91,6 +94,9 @@ class DNSListActivity : AppCompatActivity() {
val saveButton = item
.actionView.findViewById<Button>(R.id.saveButton)
saveButton.setOnClickListener {
if(isLoading){
return@setOnClickListener
}
val result = Intent(this, MainActivity::class.java)
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
val selectedDNS = adapter.getSelectedDNS()

View File

@ -45,8 +45,8 @@ class MainActivity : AppCompatActivity() {
const val DNS_LIST_CODE = 2000
const val PEER_LIST = "PEERS_LIST"
const val DNS_LIST = "DNS_LIST"
const val CURRENT_PEERS = "CURRENT_PEERS_v1.1"
const val CURRENT_DNS = "CURRENT_DNS_v1.1"
const val CURRENT_PEERS = "CURRENT_PEERS_v1.2"
const val CURRENT_DNS = "CURRENT_DNS_v1.2"
const val START_VPN = "START_VPN"
private const val TAG="Yggdrasil"
private const val VPN_REQUEST_CODE = 0x0F
@ -57,11 +57,17 @@ class MainActivity : AppCompatActivity() {
private var currentPeers = setOf<PeerInfo>()
private var currentDNS = setOf<DNSInfo>()
private var startVpnFlag = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if(intent.extras!==null) {
startVpnFlag = intent.extras!!.getBoolean(START_VPN, false)
isStarted = true
} else {
isStarted = isYggServiceRunning(this)
}
val listView = findViewById<ListView>(R.id.peers)
//save to shared preferences
val preferences =
@ -193,6 +199,7 @@ class MainActivity : AppCompatActivity() {
if(isStarted){
//TODO implement UpdateConfig method in native interface and apply peer changes
stopVpn()
finish()
val i = baseContext.packageManager
.getLaunchIntentForPackage(baseContext.packageName)
i!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
@ -233,6 +240,9 @@ class MainActivity : AppCompatActivity() {
.actionView.findViewById<Switch>(R.id.switchOn)
if(isStarted){
switchOn.isChecked = true
if(startVpnFlag) {
startVpn()
}
}
switchOn.setOnCheckedChangeListener { _, isChecked ->
if(currentPeers.isEmpty()){

View File

@ -47,6 +47,8 @@ class PeerListActivity : AppCompatActivity() {
}
}
var isLoading = true;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_peer_list)
@ -108,6 +110,8 @@ class PeerListActivity : AppCompatActivity() {
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
withContext(Dispatchers.Main) {
adapter.addAll(0, currentPeers)
isLoading = false
adapter.setLoading(isLoading)
}
} catch (e: Throwable){
e.printStackTrace()
@ -123,6 +127,9 @@ class PeerListActivity : AppCompatActivity() {
val saveButton = item
.actionView.findViewById<Button>(R.id.saveButton)
saveButton.setOnClickListener {
if(isLoading){
return@setOnClickListener
}
val result = Intent(this, MainActivity::class.java)
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
val selectedPeers = adapter.getSelectedPeers()

View File

@ -18,6 +18,7 @@ class SelectPeerInfoListAdapter(
currentPeers: MutableSet<PeerInfo>
) : ArrayAdapter<PeerInfo?> (context, 0, allPeers) {
private var isLoading = true
private val mContext: Context = context
private var allPeers: MutableList<PeerInfo> = allPeers as MutableList<PeerInfo>
private var currentPeers: MutableSet<PeerInfo> = currentPeers
@ -56,6 +57,7 @@ class SelectPeerInfoListAdapter(
peerInfoHolder.peerInfoText.setTextColor(Color.WHITE)
}
peerInfoHolder.checkbox.setOnCheckedChangeListener { _, isChecked ->
if(!isLoading) {
if (isChecked) {
if (!currentPeers.contains(currentPeer)) {
currentPeers.add(currentPeer)
@ -66,6 +68,7 @@ class SelectPeerInfoListAdapter(
}
}
}
}
peerInfoHolder.checkbox.isChecked = this.currentPeers.contains(currentPeer)
return listItem!!
}
@ -90,6 +93,10 @@ class SelectPeerInfoListAdapter(
this.notifyDataSetChanged()
}
fun setLoading(loading: Boolean){
this.isLoading = loading
}
class PeerInfoHolder {
lateinit var checkbox: CheckBox
lateinit var countryFlag: ImageView