add website to the View screen

This commit is contained in:
tibbi
2018-04-13 12:14:26 +02:00
parent 5b55467691
commit 54df14442d
5 changed files with 78 additions and 6 deletions

View File

@ -19,6 +19,7 @@ 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_group.view.*
import kotlinx.android.synthetic.main.item_view_phone_number.view.*
import kotlinx.android.synthetic.main.item_website.view.*
class ViewContactActivity : ContactActivity() {
private var isViewIntent = false
@ -124,6 +125,7 @@ class ViewContactActivity : ContactActivity() {
contact_source_image.applyColorFilter(textColor)
contact_notes_image.applyColorFilter(textColor)
contact_organization_image.applyColorFilter(textColor)
contact_websites_image.applyColorFilter(textColor)
contact_groups_image.applyColorFilter(textColor)
contact_send_sms.setOnClickListener { trySendSMS() }
@ -180,6 +182,7 @@ class ViewContactActivity : ContactActivity() {
setupEvents()
setupNotes()
setupOrganization()
setupWebsites()
setupGroups()
}
@ -303,6 +306,29 @@ class ViewContactActivity : ContactActivity() {
}
}
private fun setupWebsites() {
contact_websites_holder.removeAllViews()
val websites = contact!!.websites
if (websites.isNotEmpty() && showFields and SHOW_WEBSITES_FIELD != 0) {
websites.forEach {
val url = it
layoutInflater.inflate(R.layout.item_website, contact_websites_holder, false).apply {
contact_websites_holder.addView(this)
contact_website.text = url
setOnClickListener {
openWebsiteIntent(url)
}
}
}
contact_websites_image.beVisible()
contact_websites_holder.beVisible()
} else {
contact_websites_image.beGone()
contact_websites_holder.beGone()
}
}
private fun setupGroups() {
contact_groups_holder.removeAllViews()
val groups = contact!!.groups

View File

@ -68,11 +68,23 @@ 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)
Intent(Intent.ACTION_VIEW, uri).apply {
if (resolveActivity(packageManager) != null) {
startActivity(this)
} else {
toast(R.string.no_app_found)
}
}
}
fun Context.openWebsiteIntent(url: String) {
Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(url)
if (resolveActivity(packageManager) != null) {
startActivity(this)
} else {
toast(R.string.no_app_found)
}
}
}

View File

@ -82,3 +82,4 @@ const val SHOW_NOTES_FIELD = 512
const val SHOW_ORGANIZATION_FIELD = 1024
const val SHOW_GROUPS_FIELD = 2048
const val SHOW_CONTACT_SOURCE_FIELD = 4096
const val SHOW_WEBSITES_FIELD = 8192