mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. prevent peer edit if service is started
This commit is contained in:
parent
9969d9baa8
commit
2ea5ecf165
@ -15,7 +15,6 @@ import androidx.preference.PreferenceManager
|
|||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
||||||
import io.github.chronosx88.yggdrasil.models.config.PeerInfoListAdapter
|
import io.github.chronosx88.yggdrasil.models.config.PeerInfoListAdapter
|
||||||
import java.util.*
|
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashSet
|
import kotlin.collections.HashSet
|
||||||
|
|
||||||
@ -87,6 +86,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
listView.adapter = adapter
|
listView.adapter = adapter
|
||||||
val editPeersButton = findViewById<Button>(R.id.edit)
|
val editPeersButton = findViewById<Button>(R.id.edit)
|
||||||
editPeersButton.setOnClickListener {
|
editPeersButton.setOnClickListener {
|
||||||
|
if(isStarted){
|
||||||
|
showToast("Service is running. Please stop service before edit Peers list")
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
val intent = Intent(this, PeerListActivity::class.java)
|
val intent = Intent(this, PeerListActivity::class.java)
|
||||||
intent.putStringArrayListExtra(PEER_LIST, serializePeerInfoSet2StringList(currentPeers))
|
intent.putStringArrayListExtra(PEER_LIST, serializePeerInfoSet2StringList(currentPeers))
|
||||||
startActivityForResult(intent, PEER_LIST_CODE)
|
startActivityForResult(intent, PEER_LIST_CODE)
|
||||||
@ -122,7 +125,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if (requestCode == VPN_REQUEST_CODE && resultCode== Activity.RESULT_OK){
|
if (requestCode == VPN_REQUEST_CODE && resultCode== Activity.RESULT_OK){
|
||||||
if(currentPeers.size==0){
|
if(currentPeers.size==0){
|
||||||
showNoPeersSelected()
|
showToast("No peers selected!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val intent = Intent(this, YggdrasilTunService::class.java)
|
val intent = Intent(this, YggdrasilTunService::class.java)
|
||||||
@ -137,7 +140,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if(data!!.extras!=null){
|
if(data!!.extras!=null){
|
||||||
var currentPeers = data.extras!!.getStringArrayList(PEER_LIST)
|
var currentPeers = data.extras!!.getStringArrayList(PEER_LIST)
|
||||||
if(currentPeers==null || currentPeers.size==0){
|
if(currentPeers==null || currentPeers.size==0){
|
||||||
showNoPeersSelected()
|
showToast("No peers selected!")
|
||||||
} else {
|
} else {
|
||||||
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
||||||
val adapter = PeerInfoListAdapter(this, ArrayList(this.currentPeers))
|
val adapter = PeerInfoListAdapter(this, ArrayList(this.currentPeers))
|
||||||
@ -204,8 +207,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showNoPeersSelected(){
|
fun showToast(text: String){
|
||||||
val text = "No peers selected!"
|
|
||||||
val duration = Toast.LENGTH_SHORT
|
val duration = Toast.LENGTH_SHORT
|
||||||
val toast = Toast.makeText(applicationContext, text, duration)
|
val toast = Toast.makeText(applicationContext, text, duration)
|
||||||
toast.setGravity(Gravity.CENTER, 0, 0)
|
toast.setGravity(Gravity.CENTER, 0, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user