1. allow empty peer list fo WiFi Direct

This commit is contained in:
vadym 2020-06-28 10:27:13 -07:00
parent c0a779ce3c
commit b09f180020
2 changed files with 13 additions and 8 deletions

View File

@ -87,8 +87,9 @@ class MainActivity : AppCompatActivity() {
isStarted = isYggServiceRunning(this) isStarted = isYggServiceRunning(this)
val switchOn = findViewById<Switch>(R.id.switchOn) val switchOn = findViewById<Switch>(R.id.switchOn)
switchOn.isChecked = isStarted switchOn.isChecked = isStarted
val wifiDirect = findViewById<Switch>(R.id.wifiDirect)
switchOn.setOnCheckedChangeListener { _, isChecked -> switchOn.setOnCheckedChangeListener { _, isChecked ->
if(currentPeers.isEmpty()){ if(currentPeers.isEmpty() && !wifiDirect.isChecked){
switchOn.isChecked = false switchOn.isChecked = false
return@setOnCheckedChangeListener return@setOnCheckedChangeListener
} }
@ -104,7 +105,7 @@ class MainActivity : AppCompatActivity() {
} }
} }
val wifiDirect = findViewById<Switch>(R.id.wifiDirect)
wifiDirect.setOnCheckedChangeListener { _, isChecked -> wifiDirect.setOnCheckedChangeListener { _, isChecked ->
if (ActivityCompat.checkSelfPermission( if (ActivityCompat.checkSelfPermission(
this, this,
@ -242,9 +243,10 @@ class MainActivity : AppCompatActivity() {
if (requestCode == PEER_LIST_CODE && resultCode== Activity.RESULT_OK){ if (requestCode == PEER_LIST_CODE && resultCode== Activity.RESULT_OK){
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){ /*WiFi Direct test. need peer empty list*/
showToast("No peers selected!") //if(currentPeers==null || currentPeers.size==0){
} else { // showToast("No peers selected!")
//} else {
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers) this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping })) val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
val listView = findViewById<ListView>(R.id.peers) val listView = findViewById<ListView>(R.id.peers)
@ -264,7 +266,7 @@ class MainActivity : AppCompatActivity() {
i.putExtra(START_VPN, true) i.putExtra(START_VPN, true)
startActivity(i) startActivity(i)
} }
} //}
} }
} }

View File

@ -133,6 +133,7 @@ class PeerListActivity : AppCompatActivity() {
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()
/* WiFi Direct test - no peers is needed
if(selectedPeers.size>0) { if(selectedPeers.size>0) {
result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers)) result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers))
setResult(Activity.RESULT_OK, result) setResult(Activity.RESULT_OK, result)
@ -143,8 +144,10 @@ class PeerListActivity : AppCompatActivity() {
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)
toast.show() toast.show()
} }*/
result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers))
setResult(Activity.RESULT_OK, result)
finish()
} }
return true return true
} }