show own avatar after publication. no persistancy yet

This commit is contained in:
iNPUTmice 2014-08-05 13:00:06 +02:00
parent 9aba9a4059
commit 08755e56a5
4 changed files with 41 additions and 6 deletions

View File

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

View File

@ -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 {
@ -272,6 +271,10 @@ public class FileBackend {
}
}
public static String getAvatarPath(Context context, String avatar) {
return context.getFilesDir().getAbsolutePath() + "/avatars/"+avatar;
}
public Bitmap cropCenterSquare(Uri image, int size) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();

View File

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

View File

@ -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
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);
}
this.accountTextView.setText(this.account.getJid());
}
}