- Gravatars are loaded in Contact List and Contact Selection List

This commit is contained in:
Javier Varona 2018-02-25 20:12:01 -04:00
parent a131037fd1
commit 6c81d74deb
8 changed files with 113 additions and 5 deletions

View file

@ -63,4 +63,6 @@ dependencies {
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}

View file

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "3ec53bc71906b5abcabeaefcd7505bc1",
"identityHash": "22cb2a56b28a9f7088ec98d6a72f9f67",
"entities": [
{
"tableName": "account_seed",
@ -284,6 +284,14 @@
"name"
],
"createSql": "CREATE UNIQUE INDEX `index_contact_name` ON `${TABLE_NAME}` (`name`)"
},
{
"name": "index_contact_email",
"unique": false,
"columnNames": [
"email"
],
"createSql": "CREATE INDEX `index_contact_email` ON `${TABLE_NAME}` (`email`)"
}
],
"foreignKeys": []
@ -684,7 +692,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"3ec53bc71906b5abcabeaefcd7505bc1\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"22cb2a56b28a9f7088ec98d6a72f9f67\")"
]
}
}

View file

@ -27,7 +27,7 @@ public interface ContactDao {
@Query("SELECT * FROM contact ORDER BY name ASC")
LivePagedListProvider<Integer, Contact> contactsByName();
@Query("SELECT c.* FROM contact c WHERE c.id IN (SELECT DISTINCT(ca.contact_id) FROM contact_address ca WHERE ca.crypto_net == :cryptoNet) ORDER BY name ASC")
@Query("SELECT c.* FROM contact c WHERE c.id IN (SELECT DISTINCT(ca.contact_id) FROM contact_address ca WHERE ca.crypto_net == :cryptoNet) ORDER BY name ASC, email ASC")
LivePagedListProvider<Integer, Contact> contactsByNameAndCryptoNet(String cryptoNet);
@Query("SELECT * FROM contact WHERE id = :id")

View file

@ -22,7 +22,7 @@ import cy.agorise.crystalwallet.enums.CryptoNet;
*/
@Entity(tableName="contact",
indices = {@Index("id"),@Index(value = {"name"}, unique=true)})
indices = {@Index("id"),@Index(value = {"name"}, unique=true),@Index("email")})
public class Contact {
/**
@ -69,7 +69,7 @@ public class Contact {
}
public String getEmail() {
return mEmail;
return this.mEmail;
}
public void setEmail(String email) {

View file

@ -0,0 +1,47 @@
package cy.agorise.crystalwallet.util;
/**
* Created by Henry Varona on 25/2/2018.
*/
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.squareup.picasso.Transformation;
public class CircleTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
@Override
public String key() {
return "CircleTransformation";
}
}

View file

@ -0,0 +1,22 @@
package cy.agorise.crystalwallet.util;
/**
* Created by Henry Varona on 24/2/2018.
*/
public class MD5Hash {
static public String hash(String md5) {
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
}
return null;
}
}

View file

@ -9,10 +9,14 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.activities.CreateContactActivity;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.Contact;
import cy.agorise.crystalwallet.util.CircleTransformation;
import cy.agorise.crystalwallet.util.MD5Hash;
/**
* Created by Henry Varona on 2/16/2018.
@ -62,6 +66,16 @@ public class ContactSelectionViewHolder extends RecyclerView.ViewHolder {
tvName.setText(contact.getName());
tvLastPaid.setText("Paid: 1 Jan, 2001 01:01");
if (contact.getEmail() != null){
String emailHash = MD5Hash.hash(contact.getEmail());
String gravatarUrl = "http://www.gravatar.com/avatar/" + emailHash + "?s=204&d=404";
Picasso.with(this.context)
.load(gravatarUrl)
.transform(new CircleTransformation())
.into(ivThumbnail);
}
this.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View file

@ -6,14 +6,19 @@ import android.content.Intent;
import android.provider.ContactsContract;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.ThemedSpinnerAdapter;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.activities.CreateContactActivity;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.Contact;
import cy.agorise.crystalwallet.util.CircleTransformation;
import cy.agorise.crystalwallet.util.MD5Hash;
/**
* Created by Henry Varona on 1/17/2017.
@ -67,6 +72,16 @@ public class ContactViewHolder extends RecyclerView.ViewHolder {
}
});
if (contact.getEmail() != null){
String emailHash = MD5Hash.hash(contact.getEmail());
String gravatarUrl = "http://www.gravatar.com/avatar/" + emailHash + "?s=204&d=404";
Picasso.with(this.context)
.load(gravatarUrl)
.transform(new CircleTransformation())
.into(ivThumbnail);
}
this.ivDeleteContact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {