mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 07:56:30 +00:00
Refactor Node Info activity to RecyclerView, make visual consistency of style of Node Info activity
This commit is contained in:
parent
4a9eabd565
commit
7ed17e75b7
@ -1,12 +1,12 @@
|
||||
package io.github.chronosx88.yggdrasil
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.ListView
|
||||
import android.view.MenuItem
|
||||
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
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.github.chronosx88.yggdrasil.models.config.NodeInfoListAdapter
|
||||
|
||||
class CopyLocalNodeInfoActivity: AppCompatActivity() {
|
||||
|
||||
@ -17,12 +17,24 @@ class CopyLocalNodeInfoActivity: AppCompatActivity() {
|
||||
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)
|
||||
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, "***")
|
||||
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, "***")
|
||||
var nodeInfoListView = findViewById<RecyclerView>(R.id.node_info_list)
|
||||
val nodeInfoList = listOf<Pair<String, String>>(Pair("IP address", ipv6Address!!), Pair("Encryption Public Key", encryptionPublicKey!!), Pair("Signing Public Key", signingPublicKey!!));
|
||||
val adapter =
|
||||
NodeInfoListAdapter(
|
||||
this,
|
||||
nodeInfoList.toTypedArray()
|
||||
)
|
||||
nodeInfoListView.adapter = adapter
|
||||
nodeInfoListView.layoutManager = LinearLayoutManager(this)
|
||||
|
||||
getSupportActionBar()?.setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar()?.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package io.github.chronosx88.yggdrasil.models.config
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.github.chronosx88.yggdrasil.R
|
||||
|
||||
class NodeInfoListAdapter(private val context: Context, private val infoSet: Array<Pair<String, String>>) :
|
||||
RecyclerView.Adapter<NodeInfoListAdapter.ViewHolder>() {
|
||||
|
||||
class ViewHolder(private val context: Context, view: View) : RecyclerView.ViewHolder(view) {
|
||||
val key: TextView
|
||||
val value: TextView
|
||||
|
||||
init {
|
||||
key = view.findViewById(R.id.node_info_key)
|
||||
value = view.findViewById(R.id.node_info_value)
|
||||
|
||||
value.setOnClickListener {
|
||||
val clipboard: ClipboardManager =
|
||||
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip =
|
||||
ClipData.newPlainText(key.text, value.text)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
Toast.makeText(context, key.text.toString() + " " + context.getString(R.string.node_info_copied), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create new views (invoked by the layout manager)
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
|
||||
// Create a new view, which defines the UI of the list item
|
||||
val view = LayoutInflater.from(viewGroup.context)
|
||||
.inflate(R.layout.node_info_row, viewGroup, false)
|
||||
|
||||
return ViewHolder(
|
||||
context,
|
||||
view
|
||||
)
|
||||
}
|
||||
|
||||
// Replace the contents of a view (invoked by the layout manager)
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
|
||||
// Get element from your dataset at this position and replace the
|
||||
// contents of the view with that element
|
||||
viewHolder.key.text = infoSet[position].first
|
||||
viewHolder.value.text = infoSet[position].second
|
||||
}
|
||||
|
||||
// Return the size of your dataset (invoked by the layout manager)
|
||||
override fun getItemCount() = infoSet.size
|
||||
|
||||
}
|
@ -16,7 +16,8 @@
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:visibility="gone">
|
||||
android:visibility="gone"
|
||||
android:elevation="8dp">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -54,8 +55,11 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/nodeInfo"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:text=""
|
||||
android:textColor="@color/white"/>
|
||||
android:textColor="@color/white"
|
||||
android:layout_marginRight="5dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@ -67,7 +71,8 @@
|
||||
android:gravity="left"
|
||||
android:paddingLeft="20dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toBottomOf="@id/ipLayout">
|
||||
app:layout_constraintTop_toBottomOf="@id/ipLayout"
|
||||
android:elevation="8dp">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -114,7 +119,8 @@
|
||||
android:gravity="left"
|
||||
android:paddingLeft="20dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toBottomOf="@id/peerLayout">
|
||||
app:layout_constraintTop_toBottomOf="@id/peerLayout"
|
||||
android:elevation="8dp">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -1,13 +1,27 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
<ListView
|
||||
android:id="@+id/nodeInfoList"
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@color/dark_20"
|
||||
android:dividerHeight="2px"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dp"
|
||||
android:background="@drawable/info_panel_rounded_corner"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:elevation="8dp">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/node_info_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,52 +0,0 @@
|
||||
<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>
|
35
app/src/main/res/layout/node_info_row.xml
Normal file
35
app/src/main/res/layout/node_info_row.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/node_info_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Key"
|
||||
android:layout_margin="10dp"
|
||||
android:textColor="@color/dark_30"
|
||||
android:background="@android:color/transparent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/node_info_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Value"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:textSize="7pt"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/node_info_key"
|
||||
android:paddingBottom="10dp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user