mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
show the contact addresses on the View screen
This commit is contained in:
@ -154,15 +154,15 @@ abstract class ContactActivity : SimpleActivity() {
|
||||
else -> R.string.other
|
||||
}
|
||||
|
||||
fun getEventTextId(type: Int) = when (type) {
|
||||
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY -> R.string.birthday
|
||||
ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY -> R.string.anniversary
|
||||
else -> R.string.other
|
||||
}
|
||||
|
||||
fun getAddressTextId(type: Int) = when (type) {
|
||||
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME -> R.string.home
|
||||
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work
|
||||
else -> R.string.other
|
||||
}
|
||||
|
||||
fun getEventTextId(type: Int) = when (type) {
|
||||
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY -> R.string.birthday
|
||||
ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY -> R.string.anniversary
|
||||
else -> R.string.other
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,11 @@ import org.joda.time.format.DateTimeFormat
|
||||
import java.util.*
|
||||
|
||||
class EditContactActivity : ContactActivity() {
|
||||
val DEFAULT_EMAIL_TYPE = CommonDataKinds.Email.TYPE_HOME
|
||||
val DEFAULT_PHONE_NUMBER_TYPE = CommonDataKinds.Phone.TYPE_MOBILE
|
||||
val DEFAULT_ADDRESS_TYPE = CommonDataKinds.StructuredPostal.TYPE_HOME
|
||||
val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
||||
|
||||
private val INTENT_TAKE_PHOTO = 1
|
||||
private val INTENT_CHOOSE_PHOTO = 2
|
||||
private val INTENT_CROP_PHOTO = 3
|
||||
|
@ -6,17 +6,18 @@ import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.extensions.*
|
||||
import com.simplemobiletools.contacts.helpers.*
|
||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.IS_PRIVATE
|
||||
import kotlinx.android.synthetic.main.activity_view_contact.*
|
||||
import kotlinx.android.synthetic.main.item_event.view.*
|
||||
import kotlinx.android.synthetic.main.item_view_address.view.*
|
||||
import kotlinx.android.synthetic.main.item_view_email.view.*
|
||||
import kotlinx.android.synthetic.main.item_view_phone_number.view.*
|
||||
|
||||
@ -89,9 +90,8 @@ class ViewContactActivity : ContactActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
setupEditContact()
|
||||
setupViewContact()
|
||||
|
||||
setupTypePickers()
|
||||
contact_send_sms.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
|
||||
contact_start_call.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
|
||||
contact_send_email.beVisibleIf(contact!!.emails.isNotEmpty())
|
||||
@ -122,7 +122,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
private fun setupEditContact() {
|
||||
private fun setupViewContact() {
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
||||
contact!!.apply {
|
||||
contact_first_name.text = firstName
|
||||
@ -150,6 +150,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
|
||||
setupPhoneNumbers()
|
||||
setupEmails()
|
||||
setupAddresses()
|
||||
setupEvents()
|
||||
}
|
||||
|
||||
@ -160,7 +161,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
|
||||
contact_numbers_holder.addView(this)
|
||||
contact_number.text = it.value
|
||||
setupPhoneNumberTypePicker(contact_number_type, it.type)
|
||||
contact_number_type.setText(getPhoneNumberTextId(it.type))
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +176,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply {
|
||||
contact_emails_holder.addView(this)
|
||||
contact_email.text = it.value
|
||||
setupEmailTypePicker(contact_email_type, it.type)
|
||||
contact_email_type.setText(getEmailTextId(it.type))
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,6 +184,21 @@ class ViewContactActivity : ContactActivity() {
|
||||
contact_emails_holder.beVisibleIf(emails.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupAddresses() {
|
||||
contact_addresses_holder.removeAllViews()
|
||||
val addresses = contact!!.addresses
|
||||
addresses.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
|
||||
contact_addresses_holder.addView(this)
|
||||
contact_address.text = it.value
|
||||
contact_address_type.setText(getAddressTextId(it.type))
|
||||
}
|
||||
}
|
||||
|
||||
contact_address_image.beVisibleIf(addresses.isNotEmpty())
|
||||
contact_addresses_holder.beVisibleIf(addresses.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupEvents() {
|
||||
contact_events_holder.removeAllViews()
|
||||
val events = contact!!.events
|
||||
@ -191,7 +207,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
contact_events_holder.addView(this)
|
||||
contact_event.alpha = 1f
|
||||
getDateTime(it.value, contact_event)
|
||||
setupEventTypePicker(this as ViewGroup, it.type)
|
||||
contact_event_type.setText(getEventTextId(it.type))
|
||||
contact_event_remove.beGone()
|
||||
}
|
||||
}
|
||||
@ -200,40 +216,5 @@ class ViewContactActivity : ContactActivity() {
|
||||
contact_events_holder.beVisibleIf(events.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupTypePickers() {
|
||||
if (contact!!.phoneNumbers.isEmpty()) {
|
||||
val numberHolder = contact_numbers_holder.getChildAt(0)
|
||||
(numberHolder as? ViewGroup)?.contact_number_type?.apply {
|
||||
setupPhoneNumberTypePicker(this)
|
||||
}
|
||||
}
|
||||
|
||||
if (contact!!.emails.isEmpty()) {
|
||||
val emailHolder = contact_emails_holder.getChildAt(0)
|
||||
(emailHolder as? ViewGroup)?.contact_email_type?.apply {
|
||||
setupEmailTypePicker(this)
|
||||
}
|
||||
}
|
||||
|
||||
if (contact!!.events.isEmpty()) {
|
||||
val eventHolder = contact_events_holder.getChildAt(0)
|
||||
(eventHolder as? ViewGroup)?.apply {
|
||||
setupEventTypePicker(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupPhoneNumberTypePicker(numberTypeField: TextView, type: Int = DEFAULT_PHONE_NUMBER_TYPE) {
|
||||
numberTypeField.setText(getPhoneNumberTextId(type))
|
||||
}
|
||||
|
||||
private fun setupEmailTypePicker(emailTypeField: TextView, type: Int = DEFAULT_EMAIL_TYPE) {
|
||||
emailTypeField.setText(getEmailTextId(type))
|
||||
}
|
||||
|
||||
private fun setupEventTypePicker(eventHolder: ViewGroup, type: Int = DEFAULT_EVENT_TYPE) {
|
||||
eventHolder.contact_event_type.setText(getEventTextId(type))
|
||||
}
|
||||
|
||||
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_big else R.drawable.ic_star_off_big)
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.simplemobiletools.contacts.helpers
|
||||
|
||||
import android.provider.ContactsContract.CommonDataKinds
|
||||
|
||||
// shared prefs
|
||||
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
|
||||
const val SHOW_PHONE_NUMBERS = "show_phone_numbers"
|
||||
@ -23,11 +21,6 @@ const val PHOTO_REMOVED = 2
|
||||
const val PHOTO_CHANGED = 3
|
||||
const val PHOTO_UNCHANGED = 4
|
||||
|
||||
// default contact values
|
||||
const val DEFAULT_EMAIL_TYPE = CommonDataKinds.Email.TYPE_HOME
|
||||
const val DEFAULT_PHONE_NUMBER_TYPE = CommonDataKinds.Phone.TYPE_MOBILE
|
||||
const val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
||||
|
||||
// export/import
|
||||
const val BEGIN_VCARD = "BEGIN:VCARD"
|
||||
const val END_VCARD = "END:VCARD"
|
||||
|
Reference in New Issue
Block a user