From 4bd4513ad903bb5ca9b0b03efb91f69587e8ecde Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 16 Mar 2018 13:33:03 +0100 Subject: [PATCH] fix #82, allow pressing phone number, email, address on the View screen --- .../activities/ViewContactActivity.kt | 27 ++++++++++++++----- .../contacts/extensions/Context.kt | 12 +++++++++ app/src/main/res/layout/item_view_address.xml | 1 + app/src/main/res/layout/item_view_email.xml | 1 + .../res/layout/item_view_phone_number.xml | 1 + 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt index dbd35dd2..ff483eb8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt @@ -166,9 +166,14 @@ class ViewContactActivity : ContactActivity() { val phoneNumbers = contact!!.phoneNumbers phoneNumbers.forEach { layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply { + val phoneNumber = it contact_numbers_holder.addView(this) - contact_number.text = it.value - contact_number_type.setText(getPhoneNumberTextId(it.type)) + contact_number.text = phoneNumber.value + contact_number_type.setText(getPhoneNumberTextId(phoneNumber.type)) + + setOnClickListener { + startCallIntent(phoneNumber.value) + } } } @@ -181,9 +186,14 @@ class ViewContactActivity : ContactActivity() { val emails = contact!!.emails emails.forEach { layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply { + val email = it contact_emails_holder.addView(this) - contact_email.text = it.value - contact_email_type.setText(getEmailTextId(it.type)) + contact_email.text = email.value + contact_email_type.setText(getEmailTextId(email.type)) + + setOnClickListener { + sendEmailIntent(email.value) + } } } @@ -196,9 +206,14 @@ class ViewContactActivity : ContactActivity() { val addresses = contact!!.addresses addresses.forEach { layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply { + val address = it contact_addresses_holder.addView(this) - contact_address.text = it.value - contact_address_type.setText(getAddressTextId(it.type)) + contact_address.text = address.value + contact_address_type.setText(getAddressTextId(address.type)) + + setOnClickListener { + sendAddressIntent(address.value) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt index b242274b..8731909a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt @@ -61,6 +61,18 @@ fun Context.sendSMSIntent(recipient: String) { } } +fun Context.sendAddressIntent(address: String) { + val location = Uri.encode(address) + val uri = Uri.parse("geo:0,0?q=$location") + + val intent = Intent(Intent.ACTION_VIEW, uri) + if (intent.resolveActivity(packageManager) != null) { + startActivity(intent) + } else { + toast(R.string.no_app_found) + } +} + @TargetApi(Build.VERSION_CODES.LOLLIPOP) fun Context.getLookupUriRawId(dataUri: Uri): Int { val lookupKey = getLookupKeyFromUri(dataUri) diff --git a/app/src/main/res/layout/item_view_address.xml b/app/src/main/res/layout/item_view_address.xml index fce8cbf1..fa3497b8 100644 --- a/app/src/main/res/layout/item_view_address.xml +++ b/app/src/main/res/layout/item_view_address.xml @@ -4,6 +4,7 @@ android:id="@+id/contact_address_holder" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" android:paddingBottom="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin"> diff --git a/app/src/main/res/layout/item_view_email.xml b/app/src/main/res/layout/item_view_email.xml index 9de6e320..7169d289 100644 --- a/app/src/main/res/layout/item_view_email.xml +++ b/app/src/main/res/layout/item_view_email.xml @@ -4,6 +4,7 @@ android:id="@+id/contact_email_holder" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" android:paddingBottom="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin"> diff --git a/app/src/main/res/layout/item_view_phone_number.xml b/app/src/main/res/layout/item_view_phone_number.xml index d37bf04e..d4dea4a8 100644 --- a/app/src/main/res/layout/item_view_phone_number.xml +++ b/app/src/main/res/layout/item_view_phone_number.xml @@ -4,6 +4,7 @@ android:id="@+id/contact_number_holder" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" android:paddingBottom="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin">