add a new email/number field at pressing Plus
This commit is contained in:
parent
4e93d5098a
commit
6b201213a4
|
@ -3,6 +3,7 @@ package com.simplemobiletools.contacts.activities
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.provider.ContactsContract
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.ViewGroup
|
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.*
|
import kotlinx.android.synthetic.main.item_phone_number.view.*
|
||||||
|
|
||||||
class ContactActivity : SimpleActivity() {
|
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 wasActivityInitialized = false
|
||||||
private var contact: Contact? = null
|
private var contact: Contact? = null
|
||||||
|
|
||||||
|
@ -158,7 +162,7 @@ class ContactActivity : SimpleActivity() {
|
||||||
|
|
||||||
(numberHolder as? ViewGroup)?.apply {
|
(numberHolder as? ViewGroup)?.apply {
|
||||||
contact_number.setText(number.value)
|
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 {
|
(emailHolder as? ViewGroup)?.apply {
|
||||||
contact_email.setText(email.value)
|
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
|
firstName = contact_first_name.value
|
||||||
middleName = contact_middle_name.value
|
middleName = contact_middle_name.value
|
||||||
surname = contact_surname.value
|
surname = contact_surname.value
|
||||||
//number = contact_number.value
|
|
||||||
//email = contact_email.value
|
|
||||||
|
|
||||||
if (ContactsHelper(this@ContactActivity).updateContact(this)) {
|
if (ContactsHelper(this@ContactActivity).updateContact(this)) {
|
||||||
finish()
|
finish()
|
||||||
|
@ -204,11 +206,17 @@ class ContactActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewPhoneNumberField() {
|
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() {
|
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() {
|
private fun deleteContact() {
|
||||||
|
@ -221,4 +229,22 @@ class ContactActivity : SimpleActivity() {
|
||||||
private fun showAccountSourcePicker() {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
package com.simplemobiletools.contacts.models
|
package com.simplemobiletools.contacts.models
|
||||||
|
|
||||||
import android.provider.ContactsContract
|
data class Email(var value: String, var type: Int)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +1,3 @@
|
||||||
package com.simplemobiletools.contacts.models
|
package com.simplemobiletools.contacts.models
|
||||||
|
|
||||||
import android.provider.ContactsContract
|
data class PhoneNumber(var value: String, var type: Int)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/contact_email_holder"
|
android:id="@+id/contact_email_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingLeft="@dimen/medium_margin"
|
android:paddingLeft="@dimen/medium_margin"
|
||||||
android:paddingRight="@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>
|
</RelativeLayout>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/contact_number_holder"
|
android:id="@+id/contact_number_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingLeft="@dimen/medium_margin"
|
android:paddingLeft="@dimen/medium_margin"
|
||||||
android:paddingRight="@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>
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in New Issue