mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +00:00
1. #30. added node info copy to Clipboard
This commit is contained in:
parent
22db3c2343
commit
c5344d5794
@ -8,7 +8,7 @@ android {
|
||||
applicationId "io.github.chronosx88.yggdrasil"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 30
|
||||
versionCode 10
|
||||
versionCode 11
|
||||
versionName "1.6"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
setProperty("archivesBaseName", project.getParent().name+"-"+versionName)
|
||||
|
@ -32,6 +32,12 @@
|
||||
android:label="@string/title_activity_dns_list"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name=".CopyLocalNodeInfoActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:label="@string/title_activity_copy_local_node_info"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:screenOrientation="portrait"/>
|
||||
<service
|
||||
android:name=".YggdrasilTunService"
|
||||
android:enabled="true"
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.github.chronosx88.yggdrasil
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.ListView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
import io.github.chronosx88.yggdrasil.models.NodeInfo
|
||||
import io.github.chronosx88.yggdrasil.models.config.CopyInfoAdapter
|
||||
import io.github.chronosx88.yggdrasil.models.config.SelectDNSInfoListAdapter
|
||||
|
||||
class CopyLocalNodeInfoActivity: AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_copy_local_node_info)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "")
|
||||
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, "")
|
||||
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, "")
|
||||
var nodeInfoListView = findViewById<ListView>(R.id.nodeInfoList)
|
||||
val nodeInfoList = listOf<NodeInfo>(NodeInfo("IP address", ipv6Address!!), NodeInfo("Encryption Public Key", encryptionPublicKey!!), NodeInfo("Signing Public Key", signingPublicKey!!));
|
||||
var adapter = CopyInfoAdapter(this, nodeInfoList)
|
||||
nodeInfoListView.adapter = adapter
|
||||
}
|
||||
|
||||
}
|
@ -110,16 +110,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if(isStarted && this.currentPeers.isEmpty()) {
|
||||
updatePeers()
|
||||
}
|
||||
val copyAddressButton = findViewById<Button>(R.id.copyIp)
|
||||
copyAddressButton.setOnClickListener {
|
||||
val ip = findViewById<TextView>(R.id.ip)
|
||||
val clipboard: ClipboardManager =
|
||||
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip =
|
||||
ClipData.newPlainText("IP address", ip.text.toString())
|
||||
clipboard.setPrimaryClip(clip)
|
||||
showToast(getString(R.string.address_copied))
|
||||
}
|
||||
|
||||
val editPeersButton = findViewById<Button>(R.id.edit)
|
||||
editPeersButton.setOnClickListener {
|
||||
if(isStarted){
|
||||
@ -150,6 +141,14 @@ class MainActivity : AppCompatActivity() {
|
||||
intent.putStringArrayListExtra(DNS_LIST, serializeDNSInfoSet2StringList(currentDNS))
|
||||
startActivityForResult(intent, DNS_LIST_CODE)
|
||||
}
|
||||
val nodeInfoButton = findViewById<Button>(R.id.nodeInfo)
|
||||
nodeInfoButton.setOnClickListener {
|
||||
if(isStarted) {
|
||||
val intent = Intent(this@MainActivity, CopyLocalNodeInfoActivity::class.java)
|
||||
intent.putExtra(IPv6, findViewById<TextView>(R.id.ip).text.toString())
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
if(isStarted){
|
||||
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
||||
ipLayout.visibility = View.VISIBLE
|
||||
|
@ -177,7 +177,7 @@ class YggdrasilTunService : VpnService() {
|
||||
.putString(MainActivity.signingPublicKey, signingPublicKey)
|
||||
.putString(MainActivity.encryptionPrivateKey, encryptionPrivateKey)
|
||||
.putString(MainActivity.encryptionPublicKey, encryptionPublicKey)
|
||||
.putString(MainActivity.STATIC_IP,MainActivity.STATIC_IP).apply()
|
||||
.putString(MainActivity.STATIC_IP, MainActivity.STATIC_IP).apply()
|
||||
} else {
|
||||
val signingPrivateKey = preferences.getString(MainActivity.signingPrivateKey, null)
|
||||
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, null)
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.chronosx88.yggdrasil.models
|
||||
|
||||
class NodeInfo {
|
||||
|
||||
constructor(key: String, value: String){
|
||||
this.key = key
|
||||
this.value = value
|
||||
}
|
||||
|
||||
var key: String
|
||||
var value: String
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package io.github.chronosx88.yggdrasil.models.config
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.*
|
||||
import io.github.chronosx88.yggdrasil.R
|
||||
import io.github.chronosx88.yggdrasil.models.NodeInfo
|
||||
|
||||
class CopyInfoAdapter(
|
||||
context: Context,
|
||||
nodeInfoList: List<NodeInfo>,
|
||||
) : ArrayAdapter<NodeInfo?> (context, 0, nodeInfoList) {
|
||||
|
||||
private val mContext: Context = context
|
||||
private var nodeInfoList: MutableList<NodeInfo> = nodeInfoList as MutableList<NodeInfo>
|
||||
|
||||
override fun getItem(position: Int): NodeInfo? {
|
||||
return nodeInfoList[position]
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return nodeInfoList.size
|
||||
}
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
var copyNodeInfoHolder = CopyInfoHolder()
|
||||
var listItem: View? = convertView
|
||||
if (listItem == null) {
|
||||
listItem = LayoutInflater.from(mContext).inflate(R.layout.copy_node_info_list_item, parent, false)
|
||||
copyNodeInfoHolder.copyButton = listItem.findViewById(R.id.nodeInfoButton) as Button
|
||||
copyNodeInfoHolder.nodeInfoText = listItem.findViewById(R.id.nodeInfoText) as TextView
|
||||
copyNodeInfoHolder.nodeInfoKey = listItem.findViewById(R.id.nodeInfoKey) as TextView
|
||||
listItem.tag = copyNodeInfoHolder
|
||||
} else {
|
||||
copyNodeInfoHolder = listItem.tag as CopyInfoHolder
|
||||
}
|
||||
copyNodeInfoHolder.nodeInfoKey.text = nodeInfoList[position].key
|
||||
copyNodeInfoHolder.nodeInfoText.text = nodeInfoList[position].value
|
||||
copyNodeInfoHolder.copyButton.setOnClickListener{ _ ->
|
||||
val clipboard: ClipboardManager =
|
||||
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip =
|
||||
ClipData.newPlainText(nodeInfoList[position].key, nodeInfoList[position].value)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
showToast(nodeInfoList[position].key + " " + context.getString(R.string.node_info_copied))
|
||||
}
|
||||
return listItem!!
|
||||
}
|
||||
|
||||
private fun showToast(text: String){
|
||||
val duration = Toast.LENGTH_SHORT
|
||||
val toast = Toast.makeText(context, text, duration)
|
||||
toast.setGravity(Gravity.CENTER, 0, 0)
|
||||
toast.show()
|
||||
}
|
||||
|
||||
class CopyInfoHolder {
|
||||
lateinit var nodeInfoKey: TextView
|
||||
lateinit var nodeInfoText: TextView
|
||||
lateinit var copyButton: Button
|
||||
}
|
||||
}
|
26
app/src/main/res/layout/activity_copy_local_node_info.xml
Normal file
26
app/src/main/res/layout/activity_copy_local_node_info.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".CopyLocalNodeInfoActivity"
|
||||
android:background="@color/grey">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_node_info" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -35,10 +35,10 @@
|
||||
android:textColor="@color/dark_30"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/copyIp"
|
||||
android:id="@+id/nodeInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="COPY"
|
||||
android:text="INFO"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:background="@android:color/transparent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -53,7 +53,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/copyIp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/nodeInfo"
|
||||
android:text=""
|
||||
android:textColor="@color/white"/>
|
||||
</LinearLayout>
|
||||
|
13
app/src/main/res/layout/content_node_info.xml
Normal file
13
app/src/main/res/layout/content_node_info.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
<ListView
|
||||
android:id="@+id/nodeInfoList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@color/dark_20"
|
||||
android:dividerHeight="2px"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
52
app/src/main/res/layout/copy_node_info_list_item.xml
Normal file
52
app/src/main/res/layout/copy_node_info_list_item.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<RelativeLayout
|
||||
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">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_toLeftOf="@+id/nodeInfoButton"
|
||||
android:id="@+id/data">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nodeInfoKey"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="10sp"
|
||||
android:text = "nodeInfoKey"
|
||||
android:textColor="@color/white"
|
||||
android:layout_marginStart="10dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/nodeInfoText"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:paddingBottom="5dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nodeInfoText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="35dp"
|
||||
android:text="nodeInfoText"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/nodeInfoKey"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/nodeInfoButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="COPY"
|
||||
android:textColor="@color/white"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
</RelativeLayout>
|
@ -5,7 +5,8 @@
|
||||
<string name="switch_button_title">SwitchOn</string>
|
||||
<string name="title_activity_peer_list">Edit peers</string>
|
||||
<string name="title_activity_dns_list">Edit DNS</string>
|
||||
<string name="address_copied">Address copied</string>
|
||||
<string name="node_info_copied">copied</string>
|
||||
<string name="schema">Schema</string>
|
||||
<string name="title_activity_about">Yggdrasil</string>
|
||||
<string name="title_activity_copy_local_node_info">Node info</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user