forked from hush/SilentDragonAndroid-old
N1CK145
5 years ago
9 changed files with 231 additions and 24 deletions
@ -0,0 +1,54 @@ |
|||
package org.myhush.silentdragon.chat |
|||
|
|||
import android.app.AlertDialog |
|||
import android.support.v7.app.AppCompatActivity |
|||
import android.os.Bundle |
|||
import kotlinx.android.synthetic.main.activity_add_contact.* |
|||
import org.myhush.silentdragon.R |
|||
|
|||
class AddContactActivity : AppCompatActivity() { |
|||
|
|||
override fun onCreate(savedInstanceState: Bundle?) { |
|||
super.onCreate(savedInstanceState) |
|||
setContentView(R.layout.activity_add_contact) |
|||
|
|||
buttonAddContact.setOnClickListener { |
|||
if (checkValueValidation()) { |
|||
var nickName = editText_NickName.text.toString() |
|||
var fullname = editText_FullName.text.toString() |
|||
var zAddr = editTextZAddress.text.toString() |
|||
|
|||
Addressbook.contactList.add(Addressbook.Contact(fullname, nickName, zAddr)) |
|||
this.finish() |
|||
} |
|||
} |
|||
} |
|||
|
|||
private fun sendErrorDialog(msg: String) { |
|||
val alertDialog = AlertDialog.Builder(this@AddContactActivity).create() |
|||
alertDialog.setTitle("Error by add a new Contact!") |
|||
alertDialog.setMessage(msg) |
|||
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK") { |
|||
dialog, _ -> dialog.dismiss() } |
|||
alertDialog.show() |
|||
} |
|||
|
|||
private fun checkValueValidation(): Boolean{ |
|||
if (editText_FullName.text.length <= 1) { |
|||
sendErrorDialog("Pleas insert a name!") |
|||
return false |
|||
} |
|||
if (editText_NickName.text.length <= 1) { |
|||
sendErrorDialog("Pleas insert a nickname!") |
|||
return false |
|||
} |
|||
if (editTextZAddress.text.length <= 1) { |
|||
if(!editTextZAddress.text.startsWith('z', true)) { |
|||
sendErrorDialog("Pleas insert a z-address!") |
|||
return false |
|||
} |
|||
} |
|||
|
|||
return true |
|||
} |
|||
} |
@ -0,0 +1,117 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<android.support.constraint.ConstraintLayout 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=".chat.AddContactActivity"> |
|||
|
|||
<EditText |
|||
android:id="@+id/editTextZAddress" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="16dp" |
|||
android:layout_marginTop="16dp" |
|||
android:layout_marginEnd="16dp" |
|||
android:ems="10" |
|||
android:gravity="start|top" |
|||
android:hint="Addresses" |
|||
android:inputType="textMultiLine" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/divider7" /> |
|||
|
|||
<View |
|||
android:id="@+id/divider5" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="1dp" |
|||
android:layout_marginTop="16dp" |
|||
android:background="?android:attr/listDivider" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.0" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/textView15" /> |
|||
|
|||
<View |
|||
android:id="@+id/divider8" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="1dp" |
|||
android:layout_marginTop="16dp" |
|||
android:background="?android:attr/listDivider" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.0" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/editTextZAddress" /> |
|||
|
|||
<View |
|||
android:id="@+id/divider7" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="1dp" |
|||
android:layout_marginTop="16dp" |
|||
android:background="?android:attr/listDivider" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.0" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/editText_NickName" /> |
|||
|
|||
<EditText |
|||
android:id="@+id/editText_FullName" |
|||
android:layout_width="0sp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="16dp" |
|||
android:layout_marginTop="16dp" |
|||
android:layout_marginEnd="8dp" |
|||
android:ems="10" |
|||
android:hint="Fullname" |
|||
android:inputType="textPersonName" |
|||
app:layout_constraintEnd_toStartOf="@+id/divider9" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/divider5" /> |
|||
|
|||
<EditText |
|||
android:id="@+id/editText_NickName" |
|||
android:layout_width="0sp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="8dp" |
|||
android:layout_marginTop="16dp" |
|||
android:layout_marginEnd="16dp" |
|||
android:ems="10" |
|||
android:hint="Nickname" |
|||
android:inputType="textPersonName" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toEndOf="@+id/divider9" |
|||
app:layout_constraintTop_toBottomOf="@+id/divider5" /> |
|||
|
|||
<Button |
|||
android:id="@+id/buttonAddContact" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginTop="16dp" |
|||
android:text="Create Contact" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/divider8" /> |
|||
|
|||
<TextView |
|||
android:id="@+id/textView15" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginTop="16dp" |
|||
android:text="Add a new Contact" |
|||
android:textSize="24sp" |
|||
android:textStyle="bold" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" /> |
|||
|
|||
<View |
|||
android:id="@+id/divider9" |
|||
android:layout_width="1dp" |
|||
android:layout_height="0dp" |
|||
android:background="?android:attr/listDivider" |
|||
android:visibility="invisible" |
|||
app:layout_constraintBottom_toTopOf="@+id/divider7" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/divider5" /> |
|||
</android.support.constraint.ConstraintLayout> |
Loading…
Reference in new issue