add a new email/number field at pressing Plus

This commit is contained in:
tibbi 2017-12-18 21:23:47 +01:00
parent 4e93d5098a
commit 6b201213a4
5 changed files with 40 additions and 36 deletions

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.contacts.activities
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.provider.ContactsContract
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
@ -29,6 +30,9 @@ import kotlinx.android.synthetic.main.item_email.view.*
import kotlinx.android.synthetic.main.item_phone_number.view.*
class ContactActivity : SimpleActivity() {
private val DEFAULT_EMAIL_TYPE = ContactsContract.CommonDataKinds.Email.TYPE_HOME
private val DEFAULT_PHONE_NUMBER_TYPE = ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE
private var wasActivityInitialized = false
private var contact: Contact? = null
@ -158,7 +162,7 @@ class ContactActivity : SimpleActivity() {
(numberHolder as? ViewGroup)?.apply {
contact_number.setText(number.value)
contact_number_type.setText(number.getTextId())
contact_number_type.setText(getPhoneNumberTextId(number.type))
}
}
@ -171,7 +175,7 @@ class ContactActivity : SimpleActivity() {
(emailHolder as? ViewGroup)?.apply {
contact_email.setText(email.value)
contact_email_type.setText(email.getTextId())
contact_email_type.setText(getEmailTextId(email.type))
}
}
}
@ -194,8 +198,6 @@ class ContactActivity : SimpleActivity() {
firstName = contact_first_name.value
middleName = contact_middle_name.value
surname = contact_surname.value
//number = contact_number.value
//email = contact_email.value
if (ContactsHelper(this@ContactActivity).updateContact(this)) {
finish()
@ -204,11 +206,17 @@ class ContactActivity : SimpleActivity() {
}
private fun addNewPhoneNumberField() {
val view = layoutInflater.inflate(R.layout.item_phone_number, contact_numbers_holder, false)
updateTextColors(view as ViewGroup)
view.contact_number_type.setText(getPhoneNumberTextId(DEFAULT_PHONE_NUMBER_TYPE))
contact_numbers_holder.addView(view)
}
private fun addNewEmailField() {
val view = layoutInflater.inflate(R.layout.item_email, contact_emails_holder, false)
updateTextColors(view as ViewGroup)
view.contact_email_type.setText(getEmailTextId(DEFAULT_EMAIL_TYPE))
contact_emails_holder.addView(view)
}
private fun deleteContact() {
@ -221,4 +229,22 @@ class ContactActivity : SimpleActivity() {
private fun showAccountSourcePicker() {
}
private fun getEmailTextId(type: Int) = when (type) {
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Email.TYPE_MOBILE -> R.string.mobile
else -> R.string.other
}
private fun getPhoneNumberTextId(type: Int) = when (type) {
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE -> R.string.mobile
ContactsContract.CommonDataKinds.Phone.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Phone.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Phone.TYPE_MAIN -> R.string.main_number
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK -> R.string.work_fax
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME -> R.string.home_fax
ContactsContract.CommonDataKinds.Phone.TYPE_PAGER -> R.string.pager
else -> R.string.other
}
}

View File

@ -1,13 +1,3 @@
package com.simplemobiletools.contacts.models
import android.provider.ContactsContract
import com.simplemobiletools.contacts.R
data class Email(var value: String, var type: Int) {
fun getTextId() = when (type) {
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Email.TYPE_MOBILE -> R.string.mobile
else -> R.string.other
}
}
data class Email(var value: String, var type: Int)

View File

@ -1,17 +1,3 @@
package com.simplemobiletools.contacts.models
import android.provider.ContactsContract
import com.simplemobiletools.contacts.R
data class PhoneNumber(var value: String, var type: Int) {
fun getTextId() = when (type) {
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE -> R.string.mobile
ContactsContract.CommonDataKinds.Phone.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Phone.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Phone.TYPE_MAIN -> R.string.main_number
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK -> R.string.work_fax
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME -> R.string.home_fax
ContactsContract.CommonDataKinds.Phone.TYPE_PAGER -> R.string.pager
else -> R.string.other
}
}
data class PhoneNumber(var value: String, var type: Int)

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contact_email_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -31,7 +32,7 @@
android:gravity="center"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/home"
android:textSize="@dimen/bigger_text_size"/>
android:textSize="@dimen/bigger_text_size"
tools:text="@string/home"/>
</RelativeLayout>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contact_number_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -31,7 +32,7 @@
android:gravity="center"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/mobile"
android:textSize="@dimen/bigger_text_size"/>
android:textSize="@dimen/bigger_text_size"
tools:text="@string/mobile"/>
</RelativeLayout>