show the user photo at Details, if available

This commit is contained in:
tibbi 2017-12-11 20:29:25 +01:00
parent ebb11be2c3
commit 829897b5e1
2 changed files with 38 additions and 4 deletions

View File

@ -1,10 +1,19 @@
package com.simplemobiletools.contacts.activities
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.contacts.R
@ -53,9 +62,29 @@ class ContactActivity : SimpleActivity() {
contact_send_email.beVisibleIf(contact!!.email.isNotEmpty())
contact_photo.applyColorFilter(config.primaryColor.getContrastColor())
contact_photo.background = ColorDrawable(config.primaryColor)
if (contact!!.photoUri.isEmpty()) {
applyPhotoPlaceholder()
} else {
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
Glide.with(this)
.load(contact!!.photoUri)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean) = false
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
applyPhotoPlaceholder()
return true
}
}).into(contact_photo)
}
val textColor = config.textColor
contact_send_sms.applyColorFilter(textColor)
contact_start_call.applyColorFilter(textColor)
@ -106,6 +135,13 @@ class ContactActivity : SimpleActivity() {
supportActionBar?.title = resources.getString(R.string.new_contact)
}
private fun applyPhotoPlaceholder() {
val placeholder = resources.getColoredBitmap(R.drawable.ic_person, config.primaryColor.getContrastColor())
val padding = resources.getDimension(R.dimen.activity_margin).toInt()
contact_photo.setPadding(padding, padding, padding, padding)
contact_photo.setImageBitmap(placeholder)
}
private fun saveContact() {
}

View File

@ -14,9 +14,7 @@
<ImageView
android:id="@+id/contact_photo"
android:layout_width="@dimen/contact_photo_size"
android:layout_height="@dimen/contact_photo_size"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_person"/>
android:layout_height="@dimen/contact_photo_size"/>
<ImageView
android:id="@+id/contact_send_sms"