1. added copy peer info/dns info to clipboard

This commit is contained in:
vadym 2020-12-09 13:47:24 +02:00
parent 0857d15340
commit 664c39d315
3 changed files with 39 additions and 11 deletions

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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()
}
}