forked from yggdrasil-network/crispa-android
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. yggdrasil-network#30. added node info copy to Clipboard
- Loading branch information
Showing
12 changed files
with
221 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/io/github/chronosx88/yggdrasil/CopyLocalNodeInfoActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/main/java/io/github/chronosx88/yggdrasil/models/NodeInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
app/src/main/java/io/github/chronosx88/yggdrasil/models/config/CopyInfoAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters