fix #82, allow pressing phone number, email, address on the View screen

This commit is contained in:
tibbi 2018-03-16 13:33:03 +01:00
parent 1165550ef4
commit 4bd4513ad9
5 changed files with 36 additions and 6 deletions

View File

@ -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)
}
}
}

View File

@ -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)

View File

@ -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">

View File

@ -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">

View File

@ -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">