mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 07:56:30 +00:00
1. added dynamic peer list loading
This commit is contained in:
parent
f9335316a7
commit
0ca330e66f
@ -38,15 +38,6 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task ndkBuild(type: Exec) {
|
|
||||||
def rootDir = project.rootDir
|
|
||||||
workingDir = new File(rootDir,"yggdrasil")
|
|
||||||
commandLine 'make'
|
|
||||||
}
|
|
||||||
|
|
||||||
gradle.projectsEvaluated {
|
|
||||||
tasks.compileDebugKotlin.dependsOn(ndkBuild)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -32,57 +32,6 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json"
|
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json"
|
||||||
|
|
||||||
var allPeers = arrayListOf(
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("194.177.21.156"),
|
|
||||||
5066,
|
|
||||||
"RU"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("46.151.26.194"),
|
|
||||||
60575,
|
|
||||||
"RU"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("188.226.125.64"),
|
|
||||||
54321,
|
|
||||||
"RU"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("88.201.129.205"),
|
|
||||||
8777,
|
|
||||||
"RU"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("45.11.19.26"),
|
|
||||||
5001,
|
|
||||||
"DE"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("82.165.69.111"),
|
|
||||||
61216,
|
|
||||||
"DE"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("104.248.15.125"),
|
|
||||||
31337,
|
|
||||||
"US"
|
|
||||||
),
|
|
||||||
PeerInfo(
|
|
||||||
"tcp",
|
|
||||||
Inet4Address.getByName("108.175.10.127"),
|
|
||||||
61216,
|
|
||||||
"US"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun downloadJson(link: String): String {
|
fun downloadJson(link: String): String {
|
||||||
@ -118,7 +67,10 @@ 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 instance = this
|
var allPeers = arrayListOf<PeerInfo>()
|
||||||
|
var adapter = SelectPeerInfoListAdapter(this, allPeers, mutableSetOf())
|
||||||
|
peerList.adapter = adapter
|
||||||
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
try {
|
try {
|
||||||
var json = downloadJson(PEER_LIST_URL)
|
var json = downloadJson(PEER_LIST_URL)
|
||||||
@ -126,7 +78,6 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
val mapType: Type = object :
|
val mapType: Type = object :
|
||||||
TypeToken<Map<String?, Map<String, Status>>>() {}.type
|
TypeToken<Map<String?, Map<String, Status>>>() {}.type
|
||||||
val peersMap: Map<String, Map<String, Status>> = Gson().fromJson(json, mapType)
|
val peersMap: Map<String, Map<String, Status>> = Gson().fromJson(json, mapType)
|
||||||
val allOnlinePeers = arrayListOf<PeerInfo>()
|
|
||||||
for ((country, peers) in peersMap.entries) {
|
for ((country, peers) in peersMap.entries) {
|
||||||
println("$country:")
|
println("$country:")
|
||||||
for ((peer, status) in peers) {
|
for ((peer, status) in peers) {
|
||||||
@ -142,7 +93,12 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
var peerInfo =
|
var peerInfo =
|
||||||
PeerInfo(url.scheme, address, url.port, ccp.nameCode)
|
PeerInfo(url.scheme, address, url.port, ccp.nameCode)
|
||||||
peerInfo.ping = ping
|
peerInfo.ping = ping
|
||||||
allOnlinePeers.add(peerInfo)
|
adapter.addItem(peerInfo)
|
||||||
|
if(peerList.adapter.count % 5 == 0) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
adapter.sort()
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Throwable){
|
} catch (e: Throwable){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
@ -151,31 +107,20 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (allOnlinePeers.size > 0) {
|
|
||||||
allPeers = ArrayList(allOnlinePeers.sortedWith(compareBy { it.ping }))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
var cp = MainActivity.deserializeStringList2PeerInfoSet(
|
var cp = MainActivity.deserializeStringList2PeerInfoSet(
|
||||||
extras.getStringArrayList(MainActivity.PEER_LIST)!!
|
extras.getStringArrayList(MainActivity.PEER_LIST)!!
|
||||||
)
|
)
|
||||||
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
||||||
allPeers.removeAll(currentPeers)
|
|
||||||
allPeers.addAll(0, currentPeers)
|
|
||||||
var adapter = SelectPeerInfoListAdapter(instance, allPeers, cp)
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
peerList.adapter = adapter
|
adapter.addAll(0, currentPeers)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var adapter = SelectPeerInfoListAdapter(instance, allPeers, mutableSetOf())
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
peerList.adapter = adapter
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Throwable){
|
} catch (e: Throwable){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(peerList.adapter as SelectPeerInfoListAdapter).sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -19,9 +19,17 @@ class SelectPeerInfoListAdapter(
|
|||||||
) : ArrayAdapter<PeerInfo?> (context, 0, allPeers) {
|
) : ArrayAdapter<PeerInfo?> (context, 0, allPeers) {
|
||||||
|
|
||||||
private val mContext: Context = context
|
private val mContext: Context = context
|
||||||
private var allPeers: List<PeerInfo> = allPeers
|
private var allPeers: MutableList<PeerInfo> = allPeers as MutableList<PeerInfo>
|
||||||
private var currentPeers: MutableSet<PeerInfo> = currentPeers
|
private var currentPeers: MutableSet<PeerInfo> = currentPeers
|
||||||
|
|
||||||
|
override fun getItem(position: Int): PeerInfo? {
|
||||||
|
return allPeers.get(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCount(): Int {
|
||||||
|
return allPeers.size
|
||||||
|
}
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
var peerInfoHolder = PeerInfoHolder()
|
var peerInfoHolder = PeerInfoHolder()
|
||||||
var listItem: View? = convertView
|
var listItem: View? = convertView
|
||||||
@ -66,6 +74,22 @@ class SelectPeerInfoListAdapter(
|
|||||||
return currentPeers
|
return currentPeers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addItem(peerInfo: PeerInfo){
|
||||||
|
allPeers.add(peerInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addAll(index: Int, peerInfo: ArrayList<PeerInfo>){
|
||||||
|
currentPeers.addAll(peerInfo)
|
||||||
|
allPeers.removeAll(peerInfo)
|
||||||
|
allPeers.addAll(index, peerInfo)
|
||||||
|
this.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sort(){
|
||||||
|
allPeers = ArrayList(allPeers.sortedWith(compareBy { it.ping }))
|
||||||
|
this.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
class PeerInfoHolder {
|
class PeerInfoHolder {
|
||||||
lateinit var checkbox: CheckBox
|
lateinit var checkbox: CheckBox
|
||||||
lateinit var countryFlag: ImageView
|
lateinit var countryFlag: ImageView
|
||||||
|
Loading…
x
Reference in New Issue
Block a user