mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +00:00
Make already selected peers have toggled checkbox in peer list
This commit is contained in:
parent
992e8058d9
commit
9a2d534620
@ -37,6 +37,8 @@ import java.net.URI
|
|||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
|
||||||
class PeerListActivity : AppCompatActivity() {
|
class PeerListActivity : AppCompatActivity() {
|
||||||
@ -83,7 +85,9 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
var extras = intent.extras
|
var extras = intent.extras
|
||||||
var peerList = findViewById<ListView>(R.id.peerList)
|
var peerList = findViewById<ListView>(R.id.peerList)
|
||||||
var adapter = SelectPeerInfoListAdapter(this, arrayListOf(), mutableSetOf())
|
|
||||||
|
val alreadySelectedPeers = deserializeStringList2PeerInfoSet(extras!!.getStringArrayList(MainActivity.PEER_LIST)!!)
|
||||||
|
var adapter = SelectPeerInfoListAdapter(this, arrayListOf(), alreadySelectedPeers)
|
||||||
peerList.adapter = adapter
|
peerList.adapter = adapter
|
||||||
var peerInfoListCache = Builder<List<PeerInfo>>(CACHE_NAME, TEST_APP_VERSION)
|
var peerInfoListCache = Builder<List<PeerInfo>>(CACHE_NAME, TEST_APP_VERSION)
|
||||||
.enableLog()
|
.enableLog()
|
||||||
@ -95,10 +99,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
GlobalScope.launch() {
|
GlobalScope.launch() {
|
||||||
try {
|
try {
|
||||||
var cp = deserializeStringList2PeerInfoSet(
|
for (pi in alreadySelectedPeers) {
|
||||||
extras!!.getStringArrayList(MainActivity.PEER_LIST)!!
|
|
||||||
)
|
|
||||||
for (pi in cp) {
|
|
||||||
var ping = ping(pi.hostName, pi.port)
|
var ping = ping(pi.hostName, pi.port)
|
||||||
pi.ping = ping
|
pi.ping = ping
|
||||||
}
|
}
|
||||||
@ -108,7 +109,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
for (peerInfo in peerInfoCache) {
|
for (peerInfo in peerInfoCache) {
|
||||||
var ping = ping(peerInfo.hostName, peerInfo.port)
|
var ping = ping(peerInfo.hostName, peerInfo.port)
|
||||||
peerInfo.ping = ping
|
peerInfo.ping = ping
|
||||||
if (cp.contains(peerInfo)) {
|
if (alreadySelectedPeers.contains(peerInfo)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
@ -129,7 +130,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
for ((peer, status) in peers) {
|
for ((peer, status) in peers) {
|
||||||
if (status.up) {
|
if (status.up) {
|
||||||
for (ccp in countries) {
|
for (ccp in countries) {
|
||||||
if (ccp.name.toLowerCase()
|
if (ccp.name.lowercase(Locale.getDefault())
|
||||||
.contains(country.replace(".md", "").replace("-", " "))
|
.contains(country.replace(".md", "").replace("-", " "))
|
||||||
) {
|
) {
|
||||||
if(!peerListPing){
|
if(!peerListPing){
|
||||||
@ -147,7 +148,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
var ping = ping(url.host, url.port)
|
var ping = ping(url.host, url.port)
|
||||||
peerInfo.ping = ping
|
peerInfo.ping = ping
|
||||||
if (cp.contains(peerInfo)) {
|
if (alreadySelectedPeers.contains(peerInfo)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (peerInfo.ping < Int.MAX_VALUE) {
|
if (peerInfo.ping < Int.MAX_VALUE) {
|
||||||
@ -181,7 +182,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
for (peerInfo in onlinePeerInfoList) {
|
for (peerInfo in onlinePeerInfoList) {
|
||||||
var ping = ping(peerInfo.hostName, peerInfo.port)
|
var ping = ping(peerInfo.hostName, peerInfo.port)
|
||||||
peerInfo.ping = ping
|
peerInfo.ping = ping
|
||||||
if (cp.contains(peerInfo)) {
|
if (alreadySelectedPeers.contains(peerInfo)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
@ -197,7 +198,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
else -> e.printStackTrace()
|
else -> e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
var currentPeers = ArrayList(alreadySelectedPeers.sortedWith(compareBy { it.ping }))
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.addAll(0, currentPeers)
|
adapter.addAll(0, currentPeers)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user