From 664c39d315193e99d3e6c685f712f3dec32a6ff4 Mon Sep 17 00:00:00 2001 From: vadym Date: Wed, 9 Dec 2020 13:47:24 +0200 Subject: [PATCH] 1. added copy peer info/dns info to clipboard --- app/build.gradle | 2 +- .../models/config/SelectDNSInfoAdapter.kt | 23 ++++++++++++++--- .../config/SelectPeerInfoListAdapter.kt | 25 ++++++++++++++----- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3d404ab..5b8ee3c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { applicationId "io.github.chronosx88.yggdrasil" minSdkVersion 15 targetSdkVersion 30 - versionCode 14 + versionCode 15 versionName "1.6" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" setProperty("archivesBaseName", project.getParent().name+"-"+versionName) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectDNSInfoAdapter.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectDNSInfoAdapter.kt index 1b706cb..0b3cf93 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectDNSInfoAdapter.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectDNSInfoAdapter.kt @@ -1,14 +1,14 @@ package io.github.chronosx88.yggdrasil.models.config +import android.content.ClipData +import android.content.ClipboardManager import android.content.Context import android.graphics.Color +import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.ArrayAdapter -import android.widget.CheckBox -import android.widget.ImageView -import android.widget.TextView +import android.widget.* import io.github.chronosx88.yggdrasil.R import io.github.chronosx88.yggdrasil.models.DNSInfo @@ -66,6 +66,14 @@ class SelectDNSInfoListAdapter( } } } + dnsInfoHolder.dnsInfoText.setOnClickListener { + val clipboard: ClipboardManager = + context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = + ClipData.newPlainText("DNS info", dnsId) + clipboard.setPrimaryClip(clip) + showToast(dnsId + " " + context.getString(R.string.node_info_copied)) + } dnsInfoHolder.checkbox.isChecked = this.currentDNS.contains(currentDNS) return listItem!! } @@ -100,4 +108,11 @@ class SelectDNSInfoListAdapter( lateinit var dnsInfoText: TextView lateinit var ping: TextView } + + 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() + } } \ No newline at end of file diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt index 51908d8..147112c 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt @@ -1,14 +1,14 @@ package io.github.chronosx88.yggdrasil.models.config +import android.content.ClipData +import android.content.ClipboardManager import android.content.Context import android.graphics.Color +import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.ArrayAdapter -import android.widget.CheckBox -import android.widget.ImageView -import android.widget.TextView +import android.widget.* import io.github.chronosx88.yggdrasil.R import io.github.chronosx88.yggdrasil.models.PeerInfo @@ -46,12 +46,11 @@ class SelectPeerInfoListAdapter( val currentPeer = allPeers[position] peerInfoHolder.countryFlag.setImageResource(currentPeer.getCountry(mContext)!!.flagID) val peerId = currentPeer.toString() + peerInfoHolder.peerInfoText.text = peerId if(currentPeer.ping == Int.MAX_VALUE){ - peerInfoHolder.peerInfoText.text = peerId peerInfoHolder.ping.text="" peerInfoHolder.peerInfoText.setTextColor(Color.GRAY) } else { - peerInfoHolder.peerInfoText.text = peerId peerInfoHolder.ping.text = currentPeer.ping.toString() + " ms" peerInfoHolder.peerInfoText.setTextColor(Color.WHITE) } @@ -66,6 +65,14 @@ class SelectPeerInfoListAdapter( } } } + peerInfoHolder.peerInfoText.setOnClickListener { + val clipboard: ClipboardManager = + context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = + ClipData.newPlainText("Peer info", peerId) + clipboard.setPrimaryClip(clip) + showToast(peerId + " " + context.getString(R.string.node_info_copied)) + } peerInfoHolder.checkbox.isChecked = this.currentPeers.contains(currentPeer) return listItem!! } @@ -107,4 +114,10 @@ class SelectPeerInfoListAdapter( lateinit var ping: TextView } + 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() + } } \ No newline at end of file