mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-13 22:11:03 +00:00
1. add peer dialog. iteration 1
This commit is contained in:
parent
010051da50
commit
599c79eca9
@ -1,24 +1,25 @@
|
|||||||
package io.github.chronosx88.yggdrasil
|
package io.github.chronosx88.yggdrasil
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Gravity
|
import android.text.Html
|
||||||
import android.view.Menu
|
import android.view.*
|
||||||
import android.view.MenuItem
|
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import io.github.chronosx88.yggdrasil.models.DNSInfo
|
import io.github.chronosx88.yggdrasil.models.DNSInfo
|
||||||
import io.github.chronosx88.yggdrasil.models.config.SelectDNSInfoListAdapter
|
import io.github.chronosx88.yggdrasil.models.config.SelectDNSInfoListAdapter
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.ping
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.ping
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.serializeDNSInfoSet2StringList
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.serializeDNSInfoSet2StringList
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Runnable
|
||||||
import java.net.*
|
import java.net.InetAddress
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
|
|
||||||
@ -49,8 +50,7 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
setContentView(R.layout.activity_dns_list)
|
setContentView(R.layout.activity_dns_list)
|
||||||
setSupportActionBar(findViewById(R.id.toolbar))
|
setSupportActionBar(findViewById(R.id.toolbar))
|
||||||
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
|
findViewById<FloatingActionButton>(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 extras = intent.extras
|
||||||
var dnsList = findViewById<ListView>(R.id.dnsList)
|
var dnsList = findViewById<ListView>(R.id.dnsList)
|
||||||
|
@ -191,11 +191,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.isEmpty()){
|
|
||||||
showToast("No peers selected!")
|
|
||||||
return
|
|
||||||
}*/
|
|
||||||
val intent = Intent(this, YggdrasilTunService::class.java)
|
val intent = Intent(this, YggdrasilTunService::class.java)
|
||||||
val TASK_CODE = 100
|
val TASK_CODE = 100
|
||||||
val pi = createPendingResult(TASK_CODE, intent, 0)
|
val pi = createPendingResult(TASK_CODE, intent, 0)
|
||||||
@ -214,29 +210,25 @@ 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)
|
||||||
/*WiFi Direct test. need peer empty list*/
|
/*WiFi Direct test. need peer empty list*/
|
||||||
//if(currentPeers==null || currentPeers.size==0){
|
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
||||||
// showToast("No peers selected!")
|
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
|
||||||
//} else {
|
val listView = findViewById<ListView>(R.id.peers)
|
||||||
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
listView.adapter = adapter
|
||||||
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
|
|
||||||
val listView = findViewById<ListView>(R.id.peers)
|
|
||||||
listView.adapter = adapter
|
|
||||||
|
|
||||||
//save to shared preferences
|
//save to shared preferences
|
||||||
val preferences =
|
val preferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
||||||
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()
|
||||||
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)
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
i.putExtra(START_VPN, true)
|
i.putExtra(START_VPN, true)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@ package io.github.chronosx88.yggdrasil
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.*
|
||||||
import android.view.MenuItem
|
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@ -52,8 +52,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
setContentView(R.layout.activity_peer_list)
|
setContentView(R.layout.activity_peer_list)
|
||||||
setSupportActionBar(findViewById(R.id.toolbar))
|
setSupportActionBar(findViewById(R.id.toolbar))
|
||||||
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
|
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
|
||||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
addNewPeer()
|
||||||
.setAction("Action", null).show()
|
|
||||||
}
|
}
|
||||||
var extras = intent.extras
|
var extras = intent.extras
|
||||||
var peerList = findViewById<ListView>(R.id.peerList)
|
var peerList = findViewById<ListView>(R.id.peerList)
|
||||||
@ -117,6 +116,13 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addNewPeer() {
|
||||||
|
val view: View = LayoutInflater.from(this).inflate(R.layout.new_peer_dialog, null)
|
||||||
|
val ab: AlertDialog.Builder = AlertDialog.Builder(this)
|
||||||
|
ab.setCancelable(true).setView(view)
|
||||||
|
ab.show()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
menuInflater.inflate(R.menu.save, menu)
|
menuInflater.inflate(R.menu.save, menu)
|
||||||
|
16
app/src/main/res/drawable/edit_text_rounded_corner.xml
Normal file
16
app/src/main/res/drawable/edit_text_rounded_corner.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="@color/grey" />
|
||||||
|
|
||||||
|
<solid android:color="@color/dark_10" />
|
||||||
|
|
||||||
|
<padding
|
||||||
|
android:left="1dp"
|
||||||
|
android:right="1dp"
|
||||||
|
android:bottom="1dp"
|
||||||
|
android:top="1dp" />
|
||||||
|
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
</shape>
|
@ -34,7 +34,6 @@
|
|||||||
app:borderWidth="0dp"
|
app:borderWidth="0dp"
|
||||||
app:elevation="6dp"
|
app:elevation="6dp"
|
||||||
app:fabSize="normal"
|
app:fabSize="normal"
|
||||||
app:srcCompat="@android:drawable/ic_input_add"
|
app:srcCompat="@android:drawable/ic_input_add"/>
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
69
app/src/main/res/layout/new_peer_dialog.xml
Normal file
69
app/src/main/res/layout/new_peer_dialog.xml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
xmlns:mask="http://schemas.android.com/tools"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:background="@color/grey">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/schema"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
app:boxBackgroundMode="none"
|
||||||
|
android:background="@drawable/edit_text_rounded_corner"
|
||||||
|
android:textColorHint="@color/white"
|
||||||
|
style="@style/EditText.OutlinedBox">
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Schema"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:inputType="text"
|
||||||
|
/>
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/ip"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/schema"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/schema"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
app:boxBackgroundMode="none"
|
||||||
|
android:background="@drawable/edit_text_rounded_corner"
|
||||||
|
android:textColorHint="@color/white"
|
||||||
|
style="@style/EditText.OutlinedBox">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:digits="0123456789."
|
||||||
|
android:hint="IP address"
|
||||||
|
android:inputType="number"
|
||||||
|
mask:mask="###.###.###.###" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/port"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/schema"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/ip"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
app:boxBackgroundMode="none"
|
||||||
|
android:background="@drawable/edit_text_rounded_corner"
|
||||||
|
android:textColorHint="@color/white"
|
||||||
|
style="@style/EditText.OutlinedBox">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:digits="0123456789"
|
||||||
|
android:hint="Port"
|
||||||
|
android:inputType="number" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -6,13 +6,27 @@
|
|||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
<item name="colorControlActivated">@color/white</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
|
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
|
||||||
<item name="android:colorControlActivated">@color/green</item>
|
<item name="android:colorControlActivated">@color/green</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="EditText.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||||
|
<item name="android:textColorHint"> @color/white </item>
|
||||||
|
<item name="hintTextColor"> @color/white </item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="EditTextTheme" parent="@android:style/TextAppearance">
|
||||||
|
<item name="android:textColor">@color/white</item>
|
||||||
|
<item name="android:textColorHint">@color/white</item>
|
||||||
|
<item name="colorAccent">@color/white</item>
|
||||||
|
<item name="android:textSize">13sp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme.NoActionBar">
|
<style name="AppTheme.NoActionBar">
|
||||||
|
|
||||||
<item name="windowActionBar">false</item>
|
<item name="windowActionBar">false</item>
|
||||||
<item name="windowNoTitle">true</item>
|
<item name="windowNoTitle">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user