From 3db311c4d2bad300edfa227bc159219afbeb4a8a Mon Sep 17 00:00:00 2001 From: vadym Date: Thu, 25 Jun 2020 13:09:24 -0700 Subject: [PATCH] 1. added DNS form. iteration 1. --- app/src/main/AndroidManifest.xml | 5 +- .../chronosx88/yggdrasil/DNSListActivity.kt | 109 ++++++++++++++++++ .../chronosx88/yggdrasil/MainActivity.kt | 91 ++++++++++++++- .../chronosx88/yggdrasil/PeerListActivity.kt | 21 +--- .../yggdrasil/YggdrasilTunService.kt | 22 ++-- .../chronosx88/yggdrasil/models/DNSInfo.kt | 34 ++++++ .../models/config/DNSInfoListAdapter.kt | 44 +++++++ .../models/config/PeerInfoListAdapter.kt | 9 +- .../models/config/SelectDNSInfoAdapter.kt | 99 ++++++++++++++++ .../config/SelectPeerInfoListAdapter.kt | 4 +- .../yggdrasil/models/config/Utils.kt | 27 +++++ app/src/main/res/layout/activity_dns_list.xml | 40 +++++++ app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/content_dns_list.xml | 13 +++ ...peers_list_item.xml => host_list_item.xml} | 2 +- ..._item_edit.xml => host_list_item_edit.xml} | 2 +- .../res/menu/{save_peers.xml => save.xml} | 0 app/src/main/res/values/strings.xml | 1 + 18 files changed, 486 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/io/github/chronosx88/yggdrasil/DNSListActivity.kt create mode 100644 app/src/main/java/io/github/chronosx88/yggdrasil/models/DNSInfo.kt create mode 100644 app/src/main/java/io/github/chronosx88/yggdrasil/models/config/DNSInfoListAdapter.kt create mode 100644 app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectDNSInfoAdapter.kt create mode 100644 app/src/main/java/io/github/chronosx88/yggdrasil/models/config/Utils.kt create mode 100644 app/src/main/res/layout/activity_dns_list.xml create mode 100644 app/src/main/res/layout/content_dns_list.xml rename app/src/main/res/layout/{peers_list_item.xml => host_list_item.xml} (95%) rename app/src/main/res/layout/{peers_list_item_edit.xml => host_list_item_edit.xml} (98%) rename app/src/main/res/menu/{save_peers.xml => save.xml} (100%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 74b6990..32c387d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,7 +18,10 @@ android:name=".PeerListActivity" android:label="@string/title_activity_peer_list" android:theme="@style/AppTheme.NoActionBar" /> - + (R.id.fab).setOnClickListener { view -> + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show() + } + var extras = intent.extras + var dnsList = findViewById(R.id.dnsList) + var adapter = SelectDNSInfoListAdapter(this, arrayListOf(), mutableSetOf()) + dnsList.adapter = adapter + thread(start = true) { + try { + var cd = MainActivity.deserializeStringList2DNSInfoSet( + extras!!.getStringArrayList(MainActivity.DNS_LIST)!! + ) + for (d in cd) { + var ping = ping(d.address, 53) + d.ping = ping + } + for (dns in allDNS) { + if (cd.contains(dns)) { + continue + } + var ping = ping(dns.address, 53) + dns.ping = ping + adapter.addItem(dns) + runOnUiThread( + Runnable + { + adapter.sort() + } + ) + } + } catch (e: Throwable) { + e.printStackTrace() + } + } + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.save, menu) + val item = menu.findItem(R.id.saveItem) as MenuItem + item.setActionView(R.layout.menu_save) + val saveButton = item + .actionView.findViewById