3. added IP field constraints

This commit is contained in:
vadym 2020-07-02 07:29:02 -07:00
parent 17dc3b8650
commit f8875455be
3 changed files with 39 additions and 4 deletions

View File

@ -28,8 +28,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.IOException
import java.lang.reflect.Type import java.lang.reflect.Type
import java.net.InetAddress import java.net.InetAddress
import java.net.SocketTimeoutException
import java.net.URI import java.net.URI
import java.net.URL import java.net.URL
import java.nio.charset.Charset 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)); 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) val ab: AlertDialog.Builder = AlertDialog.Builder(this)
ab.setCancelable(true).setView(view) 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) { fun onClickSchemaList(v: View) {

View File

@ -81,6 +81,10 @@ class SelectPeerInfoListAdapter(
allPeers.add(peerInfo) allPeers.add(peerInfo)
} }
fun addItem(index: Int, peerInfo: PeerInfo){
allPeers.add(index, peerInfo)
}
fun addAll(index: Int, peerInfo: ArrayList<PeerInfo>){ fun addAll(index: Int, peerInfo: ArrayList<PeerInfo>){
currentPeers.addAll(peerInfo) currentPeers.addAll(peerInfo)
allPeers.removeAll(peerInfo) allPeers.removeAll(peerInfo)

View File

@ -44,11 +44,12 @@
android:id="@+id/ipInput" android:id="@+id/ipInput"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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:hint="IP/domain"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:textColor="@color/white" android:textColor="@color/white"
android:textCursorDrawable="@null"/> android:textCursorDrawable="@null"
/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
@ -84,6 +85,8 @@
app:ccp_showFullName="true" app:ccp_showFullName="true"
app:ccp_showPhoneCode="false" app:ccp_showPhoneCode="false"
app:ccp_showNameCode="false" app:ccp_showNameCode="false"
app:ccpDialog_backgroundColor="@color/grey"
app:ccpDialog_textColor="@color/white"
app:layout_constraintEnd_toEndOf="@+id/schema" app:layout_constraintEnd_toEndOf="@+id/schema"
app:layout_constraintTop_toBottomOf="@+id/port" app:layout_constraintTop_toBottomOf="@+id/port"
android:background="@drawable/edit_text_rounded_corner"/> android:background="@drawable/edit_text_rounded_corner"/>