mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. DNS refresh fix
This commit is contained in:
parent
a8eaa5fc9d
commit
50a107cea4
@ -35,7 +35,6 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity"
|
||||||
android:launchMode= "singleInstance"
|
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -42,6 +42,8 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isLoading = true;
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_dns_list)
|
setContentView(R.layout.activity_dns_list)
|
||||||
@ -74,6 +76,7 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
Runnable
|
Runnable
|
||||||
{
|
{
|
||||||
adapter.sort()
|
adapter.sort()
|
||||||
|
isLoading = false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -91,6 +94,9 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
val saveButton = item
|
val saveButton = item
|
||||||
.actionView.findViewById<Button>(R.id.saveButton)
|
.actionView.findViewById<Button>(R.id.saveButton)
|
||||||
saveButton.setOnClickListener {
|
saveButton.setOnClickListener {
|
||||||
|
if(isLoading){
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
val result = Intent(this, MainActivity::class.java)
|
val result = Intent(this, MainActivity::class.java)
|
||||||
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
|
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
|
||||||
val selectedDNS = adapter.getSelectedDNS()
|
val selectedDNS = adapter.getSelectedDNS()
|
||||||
|
@ -45,8 +45,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
const val DNS_LIST_CODE = 2000
|
const val DNS_LIST_CODE = 2000
|
||||||
const val PEER_LIST = "PEERS_LIST"
|
const val PEER_LIST = "PEERS_LIST"
|
||||||
const val DNS_LIST = "DNS_LIST"
|
const val DNS_LIST = "DNS_LIST"
|
||||||
const val CURRENT_PEERS = "CURRENT_PEERS_v1.1"
|
const val CURRENT_PEERS = "CURRENT_PEERS_v1.2"
|
||||||
const val CURRENT_DNS = "CURRENT_DNS_v1.1"
|
const val CURRENT_DNS = "CURRENT_DNS_v1.2"
|
||||||
const val START_VPN = "START_VPN"
|
const val START_VPN = "START_VPN"
|
||||||
private const val TAG="Yggdrasil"
|
private const val TAG="Yggdrasil"
|
||||||
private const val VPN_REQUEST_CODE = 0x0F
|
private const val VPN_REQUEST_CODE = 0x0F
|
||||||
@ -57,11 +57,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private var currentPeers = setOf<PeerInfo>()
|
private var currentPeers = setOf<PeerInfo>()
|
||||||
private var currentDNS = setOf<DNSInfo>()
|
private var currentDNS = setOf<DNSInfo>()
|
||||||
|
private var startVpnFlag = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
if(intent.extras!==null) {
|
||||||
|
startVpnFlag = intent.extras!!.getBoolean(START_VPN, false)
|
||||||
|
isStarted = true
|
||||||
|
} else {
|
||||||
isStarted = isYggServiceRunning(this)
|
isStarted = isYggServiceRunning(this)
|
||||||
|
}
|
||||||
val listView = findViewById<ListView>(R.id.peers)
|
val listView = findViewById<ListView>(R.id.peers)
|
||||||
//save to shared preferences
|
//save to shared preferences
|
||||||
val preferences =
|
val preferences =
|
||||||
@ -193,6 +199,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if(isStarted){
|
if(isStarted){
|
||||||
//TODO implement UpdateConfig method in native interface and apply peer changes
|
//TODO implement UpdateConfig method in native interface and apply peer changes
|
||||||
stopVpn()
|
stopVpn()
|
||||||
|
finish()
|
||||||
val i = baseContext.packageManager
|
val i = baseContext.packageManager
|
||||||
.getLaunchIntentForPackage(baseContext.packageName)
|
.getLaunchIntentForPackage(baseContext.packageName)
|
||||||
i!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
i!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
@ -233,6 +240,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.actionView.findViewById<Switch>(R.id.switchOn)
|
.actionView.findViewById<Switch>(R.id.switchOn)
|
||||||
if(isStarted){
|
if(isStarted){
|
||||||
switchOn.isChecked = true
|
switchOn.isChecked = true
|
||||||
|
if(startVpnFlag) {
|
||||||
|
startVpn()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switchOn.setOnCheckedChangeListener { _, isChecked ->
|
switchOn.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if(currentPeers.isEmpty()){
|
if(currentPeers.isEmpty()){
|
||||||
|
@ -47,6 +47,8 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isLoading = true;
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_peer_list)
|
setContentView(R.layout.activity_peer_list)
|
||||||
@ -108,6 +110,8 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
var currentPeers = ArrayList(cp.sortedWith(compareBy { it.ping }))
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.addAll(0, currentPeers)
|
adapter.addAll(0, currentPeers)
|
||||||
|
isLoading = false
|
||||||
|
adapter.setLoading(isLoading)
|
||||||
}
|
}
|
||||||
} catch (e: Throwable){
|
} catch (e: Throwable){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@ -123,6 +127,9 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
val saveButton = item
|
val saveButton = item
|
||||||
.actionView.findViewById<Button>(R.id.saveButton)
|
.actionView.findViewById<Button>(R.id.saveButton)
|
||||||
saveButton.setOnClickListener {
|
saveButton.setOnClickListener {
|
||||||
|
if(isLoading){
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
val result = Intent(this, MainActivity::class.java)
|
val result = Intent(this, MainActivity::class.java)
|
||||||
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
|
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
|
||||||
val selectedPeers = adapter.getSelectedPeers()
|
val selectedPeers = adapter.getSelectedPeers()
|
||||||
|
@ -18,6 +18,7 @@ class SelectPeerInfoListAdapter(
|
|||||||
currentPeers: MutableSet<PeerInfo>
|
currentPeers: MutableSet<PeerInfo>
|
||||||
) : ArrayAdapter<PeerInfo?> (context, 0, allPeers) {
|
) : ArrayAdapter<PeerInfo?> (context, 0, allPeers) {
|
||||||
|
|
||||||
|
private var isLoading = true
|
||||||
private val mContext: Context = context
|
private val mContext: Context = context
|
||||||
private var allPeers: MutableList<PeerInfo> = allPeers as MutableList<PeerInfo>
|
private var allPeers: MutableList<PeerInfo> = allPeers as MutableList<PeerInfo>
|
||||||
private var currentPeers: MutableSet<PeerInfo> = currentPeers
|
private var currentPeers: MutableSet<PeerInfo> = currentPeers
|
||||||
@ -56,6 +57,7 @@ class SelectPeerInfoListAdapter(
|
|||||||
peerInfoHolder.peerInfoText.setTextColor(Color.WHITE)
|
peerInfoHolder.peerInfoText.setTextColor(Color.WHITE)
|
||||||
}
|
}
|
||||||
peerInfoHolder.checkbox.setOnCheckedChangeListener { _, isChecked ->
|
peerInfoHolder.checkbox.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
if(!isLoading) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
if (!currentPeers.contains(currentPeer)) {
|
if (!currentPeers.contains(currentPeer)) {
|
||||||
currentPeers.add(currentPeer)
|
currentPeers.add(currentPeer)
|
||||||
@ -66,6 +68,7 @@ class SelectPeerInfoListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
peerInfoHolder.checkbox.isChecked = this.currentPeers.contains(currentPeer)
|
peerInfoHolder.checkbox.isChecked = this.currentPeers.contains(currentPeer)
|
||||||
return listItem!!
|
return listItem!!
|
||||||
}
|
}
|
||||||
@ -90,6 +93,10 @@ class SelectPeerInfoListAdapter(
|
|||||||
this.notifyDataSetChanged()
|
this.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setLoading(loading: Boolean){
|
||||||
|
this.isLoading = loading
|
||||||
|
}
|
||||||
|
|
||||||
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