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
|
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) {
|
fun getAddressTextId(type: Int) = when (type) {
|
||||||
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME -> R.string.home
|
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME -> R.string.home
|
||||||
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work
|
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work
|
||||||
else -> R.string.other
|
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.*
|
import java.util.*
|
||||||
|
|
||||||
class EditContactActivity : ContactActivity() {
|
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_TAKE_PHOTO = 1
|
||||||
private val INTENT_CHOOSE_PHOTO = 2
|
private val INTENT_CHOOSE_PHOTO = 2
|
||||||
private val INTENT_CROP_PHOTO = 3
|
private val INTENT_CROP_PHOTO = 3
|
||||||
|
@ -6,17 +6,18 @@ import android.os.Bundle
|
|||||||
import android.provider.ContactsContract
|
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.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.extensions.*
|
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.activity_view_contact.*
|
||||||
import kotlinx.android.synthetic.main.item_event.view.*
|
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_email.view.*
|
||||||
import kotlinx.android.synthetic.main.item_view_phone_number.view.*
|
import kotlinx.android.synthetic.main.item_view_phone_number.view.*
|
||||||
|
|
||||||
@ -89,9 +90,8 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setupEditContact()
|
setupViewContact()
|
||||||
|
|
||||||
setupTypePickers()
|
|
||||||
contact_send_sms.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
|
contact_send_sms.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
|
||||||
contact_start_call.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
|
contact_start_call.beVisibleIf(contact!!.phoneNumbers.isNotEmpty())
|
||||||
contact_send_email.beVisibleIf(contact!!.emails.isNotEmpty())
|
contact_send_email.beVisibleIf(contact!!.emails.isNotEmpty())
|
||||||
@ -122,7 +122,7 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEditContact() {
|
private fun setupViewContact() {
|
||||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
||||||
contact!!.apply {
|
contact!!.apply {
|
||||||
contact_first_name.text = firstName
|
contact_first_name.text = firstName
|
||||||
@ -150,6 +150,7 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
|
|
||||||
setupPhoneNumbers()
|
setupPhoneNumbers()
|
||||||
setupEmails()
|
setupEmails()
|
||||||
|
setupAddresses()
|
||||||
setupEvents()
|
setupEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
|
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
|
||||||
contact_numbers_holder.addView(this)
|
contact_numbers_holder.addView(this)
|
||||||
contact_number.text = it.value
|
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 {
|
layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply {
|
||||||
contact_emails_holder.addView(this)
|
contact_emails_holder.addView(this)
|
||||||
contact_email.text = it.value
|
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())
|
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() {
|
private fun setupEvents() {
|
||||||
contact_events_holder.removeAllViews()
|
contact_events_holder.removeAllViews()
|
||||||
val events = contact!!.events
|
val events = contact!!.events
|
||||||
@ -191,7 +207,7 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
contact_events_holder.addView(this)
|
contact_events_holder.addView(this)
|
||||||
contact_event.alpha = 1f
|
contact_event.alpha = 1f
|
||||||
getDateTime(it.value, contact_event)
|
getDateTime(it.value, contact_event)
|
||||||
setupEventTypePicker(this as ViewGroup, it.type)
|
contact_event_type.setText(getEventTextId(it.type))
|
||||||
contact_event_remove.beGone()
|
contact_event_remove.beGone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,40 +216,5 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
contact_events_holder.beVisibleIf(events.isNotEmpty())
|
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)
|
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
|
package com.simplemobiletools.contacts.helpers
|
||||||
|
|
||||||
import android.provider.ContactsContract.CommonDataKinds
|
|
||||||
|
|
||||||
// shared prefs
|
// shared prefs
|
||||||
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
|
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
|
||||||
const val SHOW_PHONE_NUMBERS = "show_phone_numbers"
|
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_CHANGED = 3
|
||||||
const val PHOTO_UNCHANGED = 4
|
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
|
// export/import
|
||||||
const val BEGIN_VCARD = "BEGIN:VCARD"
|
const val BEGIN_VCARD = "BEGIN:VCARD"
|
||||||
const val END_VCARD = "END:VCARD"
|
const val END_VCARD = "END:VCARD"
|
||||||
|
@ -176,6 +176,26 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="@dimen/small_margin"/>
|
android:paddingLeft="@dimen/small_margin"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/contact_address_image"
|
||||||
|
android:layout_width="@dimen/contact_icons_size"
|
||||||
|
android:layout_height="@dimen/contact_icons_size"
|
||||||
|
android:layout_alignTop="@+id/contact_addresses_holder"
|
||||||
|
android:paddingBottom="@dimen/small_margin"
|
||||||
|
android:paddingEnd="@dimen/small_margin"
|
||||||
|
android:paddingRight="@dimen/small_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:src="@drawable/ic_place"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/contact_addresses_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/contact_emails_holder"
|
||||||
|
android:layout_toRightOf="@+id/contact_name_image"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="@dimen/small_margin"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/contact_event_image"
|
android:id="@+id/contact_event_image"
|
||||||
android:layout_width="@dimen/contact_icons_size"
|
android:layout_width="@dimen/contact_icons_size"
|
||||||
@ -191,7 +211,7 @@
|
|||||||
android:id="@+id/contact_events_holder"
|
android:id="@+id/contact_events_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/contact_emails_holder"
|
android:layout_below="@+id/contact_addresses_holder"
|
||||||
android:layout_toRightOf="@+id/contact_name_image"
|
android:layout_toRightOf="@+id/contact_name_image"
|
||||||
android:orientation="vertical"/>
|
android:orientation="vertical"/>
|
||||||
|
|
||||||
|
37
app/src/main/res/layout/item_view_address.xml
Normal file
37
app/src/main/res/layout/item_view_address.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/contact_address_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/normal_margin"
|
||||||
|
android:paddingTop="@dimen/normal_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/contact_address"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_toLeftOf="@+id/contact_address_type"
|
||||||
|
android:layout_toStartOf="@+id/contact_address_type"
|
||||||
|
android:lines="1"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textSize="@dimen/bigger_text_size"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/contact_address_type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@+id/contact_address"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignTop="@+id/contact_address"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingLeft="@dimen/medium_margin"
|
||||||
|
android:paddingRight="@dimen/medium_margin"
|
||||||
|
android:text="@string/home"
|
||||||
|
android:textSize="@dimen/bigger_text_size"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -28,7 +28,6 @@
|
|||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignTop="@+id/contact_email"
|
android:layout_alignTop="@+id/contact_email"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
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"
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignTop="@+id/contact_number"
|
android:layout_alignTop="@+id/contact_number"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
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"
|
||||||
|
Reference in New Issue
Block a user