mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +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
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.text.Html
|
||||
import android.view.*
|
||||
import android.widget.Button
|
||||
import android.widget.ListView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
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.config.SelectDNSInfoListAdapter
|
||||
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.serializeDNSInfoSet2StringList
|
||||
import kotlinx.coroutines.*
|
||||
import java.net.*
|
||||
import kotlinx.coroutines.Runnable
|
||||
import java.net.InetAddress
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
|
||||
@ -49,8 +50,7 @@ class DNSListActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_dns_list)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
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 dnsList = findViewById<ListView>(R.id.dnsList)
|
||||
|
@ -191,11 +191,7 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
||||
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 TASK_CODE = 100
|
||||
val pi = createPendingResult(TASK_CODE, intent, 0)
|
||||
@ -214,29 +210,25 @@ class MainActivity : AppCompatActivity() {
|
||||
if(data!!.extras!=null){
|
||||
var currentPeers = data.extras!!.getStringArrayList(PEER_LIST)
|
||||
/*WiFi Direct test. need peer empty list*/
|
||||
//if(currentPeers==null || currentPeers.size==0){
|
||||
// showToast("No peers selected!")
|
||||
//} else {
|
||||
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
||||
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
|
||||
val listView = findViewById<ListView>(R.id.peers)
|
||||
listView.adapter = adapter
|
||||
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
|
||||
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
|
||||
val listView = findViewById<ListView>(R.id.peers)
|
||||
listView.adapter = adapter
|
||||
|
||||
//save to shared preferences
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
||||
if(isStarted){
|
||||
//TODO implement UpdateConfig method in native interface and apply peer changes
|
||||
stopVpn()
|
||||
val i = baseContext.packageManager
|
||||
.getLaunchIntentForPackage(baseContext.packageName)
|
||||
i!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
i.putExtra(START_VPN, true)
|
||||
startActivity(i)
|
||||
}
|
||||
//}
|
||||
//save to shared preferences
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
preferences.edit().putStringSet(CURRENT_PEERS, HashSet(currentPeers)).apply()
|
||||
if(isStarted){
|
||||
//TODO implement UpdateConfig method in native interface and apply peer changes
|
||||
stopVpn()
|
||||
val i = baseContext.packageManager
|
||||
.getLaunchIntentForPackage(baseContext.packageName)
|
||||
i!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
i.putExtra(START_VPN, true)
|
||||
startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ package io.github.chronosx88.yggdrasil
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.*
|
||||
import android.widget.Button
|
||||
import android.widget.ListView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
@ -52,8 +52,7 @@ class PeerListActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_peer_list)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
addNewPeer()
|
||||
}
|
||||
var extras = intent.extras
|
||||
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 {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
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:elevation="6dp"
|
||||
app:fabSize="normal"
|
||||
app:srcCompat="@android:drawable/ic_input_add"
|
||||
android:visibility="gone"/>
|
||||
app:srcCompat="@android:drawable/ic_input_add"/>
|
||||
|
||||
</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="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="colorControlActivated">@color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
|
||||
<item name="android:colorControlActivated">@color/green</item>
|
||||
</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">
|
||||
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user