mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +00:00
3. added IP field constraints
This commit is contained in:
parent
17dc3b8650
commit
f8875455be
@ -28,8 +28,10 @@ import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.lang.reflect.Type
|
||||
import java.net.InetAddress
|
||||
import java.net.SocketTimeoutException
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
import java.nio.charset.Charset
|
||||
@ -141,10 +143,36 @@ class PeerListActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
getPopupWindow(R.layout.spinner_item, resources.getStringArray(R.array.schemas), schemaInput, getString(R.string.schema));
|
||||
view.findViewById<com.hbb20.CountryCodePicker>(R.id.ccp).setCountryForNameCode(countryCode)
|
||||
var ccp = view.findViewById<com.hbb20.CountryCodePicker>(R.id.ccp)
|
||||
ccp.setCountryForNameCode(countryCode)
|
||||
val ab: AlertDialog.Builder = AlertDialog.Builder(this)
|
||||
ab.setCancelable(true).setView(view)
|
||||
ab.show()
|
||||
var ad = ab.show()
|
||||
var addButton = view.findViewById<Button>(R.id.add)
|
||||
addButton.setOnClickListener{
|
||||
var ipInput = view.findViewById<TextView>(R.id.ipInput)
|
||||
var portInput = view.findViewById<TextView>(R.id.portInput)
|
||||
var ccpInput = view.findViewById<com.hbb20.CountryCodePicker>(R.id.ccp)
|
||||
var schema = schemaInput.text.toString().toLowerCase()
|
||||
var ip = ipInput.text.toString().toLowerCase()
|
||||
var port = portInput.text.toString().toInt()
|
||||
var ccp = ccpInput.selectedCountryNameCode
|
||||
GlobalScope.launch {
|
||||
var pi = PeerInfo(schema, InetAddress.getByName(ip), port, ccp)
|
||||
try {
|
||||
var ping = ping(pi.address, pi.port)
|
||||
pi.ping = ping
|
||||
} catch(e: Throwable){
|
||||
pi.ping = Int.MAX_VALUE
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
var selectAdapter = (findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter)
|
||||
selectAdapter.addItem(0, pi)
|
||||
selectAdapter.notifyDataSetChanged()
|
||||
ad.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onClickSchemaList(v: View) {
|
||||
|
@ -81,6 +81,10 @@ class SelectPeerInfoListAdapter(
|
||||
allPeers.add(peerInfo)
|
||||
}
|
||||
|
||||
fun addItem(index: Int, peerInfo: PeerInfo){
|
||||
allPeers.add(index, peerInfo)
|
||||
}
|
||||
|
||||
fun addAll(index: Int, peerInfo: ArrayList<PeerInfo>){
|
||||
currentPeers.addAll(peerInfo)
|
||||
allPeers.removeAll(peerInfo)
|
||||
|
@ -44,11 +44,12 @@
|
||||
android:id="@+id/ipInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:digits="0123456789."
|
||||
android:digits="0,1,2,3,4,5,6,7,8,9,.,qwertzuiopasdfghjklyxcvbnm,_,-"
|
||||
android:hint="IP/domain"
|
||||
android:inputType="textNoSuggestions"
|
||||
android:textColor="@color/white"
|
||||
android:textCursorDrawable="@null"/>
|
||||
android:textCursorDrawable="@null"
|
||||
/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
@ -84,6 +85,8 @@
|
||||
app:ccp_showFullName="true"
|
||||
app:ccp_showPhoneCode="false"
|
||||
app:ccp_showNameCode="false"
|
||||
app:ccpDialog_backgroundColor="@color/grey"
|
||||
app:ccpDialog_textColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="@+id/schema"
|
||||
app:layout_constraintTop_toBottomOf="@+id/port"
|
||||
android:background="@drawable/edit_text_rounded_corner"/>
|
||||
|
Loading…
Reference in New Issue
Block a user