From 08755e56a5bf861c97eefd545f629ac67a804275 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 5 Aug 2014 13:00:06 +0200 Subject: show own avatar after publication. no persistancy yet --- src/eu/siacs/conversations/entities/Account.java | 23 +++++++++++++++++++++- .../conversations/persistance/FileBackend.java | 7 +++++-- .../services/XmppConnectionService.java | 1 + .../ui/PublishProfilePictureActivity.java | 16 ++++++++++++--- 4 files changed, 41 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java index 2be03ab1..61b104c4 100644 --- a/src/eu/siacs/conversations/entities/Account.java +++ b/src/eu/siacs/conversations/entities/Account.java @@ -12,12 +12,15 @@ import org.json.JSONException; import org.json.JSONObject; import eu.siacs.conversations.crypto.OtrEngine; +import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.XmppConnection; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; public class Account extends AbstractEntity{ @@ -58,6 +61,7 @@ public class Account extends AbstractEntity{ protected String resource = "mobile"; protected int status = -1; protected JSONObject keys = new JSONObject(); + protected String avatar; protected boolean online = false; @@ -322,6 +326,23 @@ public class Account extends AbstractEntity{ } public Bitmap getImage(Context context, int size) { - return UIHelper.getContactPicture(getJid(), size, context, false); + if (this.avatar!=null) { + Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar)); + if (bm==null) { + return UIHelper.getContactPicture(getJid(), size, context, false); + } else { + return bm; + } + } else { + return UIHelper.getContactPicture(getJid(), size, context, false); + } + } + + public void setAvatar(String filename) { + this.avatar = filename; + } + + public String getAvatar() { + return this.avatar; } } diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 9a94329a..4014cf60 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -249,8 +249,7 @@ public class FileBackend { } public void save(Avatar avatar) { - String path = context.getFilesDir().getAbsolutePath() + "/avatars/"; - File file = new File(path+"/"+avatar.getFilename()); + File file = new File(getAvatarPath(context, avatar.getFilename())); file.getParentFile().mkdirs(); Log.d("xmppService",file.getAbsolutePath()); try { @@ -271,6 +270,10 @@ public class FileBackend { e.printStackTrace(); } } + + public static String getAvatarPath(Context context, String avatar) { + return context.getFilesDir().getAbsolutePath() + "/avatars/"+avatar; + } public Bitmap cropCenterSquare(Uri image, int size) { try { diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 370d8304..8c964517 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1214,6 +1214,7 @@ public class XmppConnectionService extends Service { @Override public void onIqPacketReceived(Account account, IqPacket result) { if (result.getType() == IqPacket.TYPE_RESULT) { + account.setAvatar(avatar.getFilename()); callback.success(avatar); } else { callback.error(R.string.error_publish_avatar_server_reject, avatar); diff --git a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index 353600ef..fcb94efa 100644 --- a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; @@ -134,10 +135,19 @@ public class PublishProfilePictureActivity extends XmppActivity { if (jid != null) { this.account = xmppConnectionService.findAccountByJid(jid); if (this.avatarUri == null) { - avatarUri = PhoneHelper - .getSefliUri(getApplicationContext()); + if (this.account.getAvatar() != null) { + this.avatar.setImageBitmap(this.account.getImage( + getApplicationContext(), 384)); + } else { + this.avatarUri = PhoneHelper + .getSefliUri(getApplicationContext()); + if (this.avatarUri != null) { + loadImageIntoPreview(this.avatarUri); + } + } + } else { + loadImageIntoPreview(avatarUri); } - loadImageIntoPreview(avatarUri); this.accountTextView.setText(this.account.getJid()); } } -- cgit v1.2.3