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 org.json.JSONObject;
import eu.siacs.conversations.crypto.OtrEngine; import eu.siacs.conversations.crypto.OtrEngine;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.XmppConnection;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
public class Account extends AbstractEntity{ public class Account extends AbstractEntity{
@ -58,6 +61,7 @@ public class Account extends AbstractEntity{
protected String resource = "mobile"; protected String resource = "mobile";
protected int status = -1; protected int status = -1;
protected JSONObject keys = new JSONObject(); protected JSONObject keys = new JSONObject();
protected String avatar;
protected boolean online = false; protected boolean online = false;
@ -322,6 +326,23 @@ public class Account extends AbstractEntity{
} }
public Bitmap getImage(Context context, int size) { 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); 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) { public void save(Avatar avatar) {
String path = context.getFilesDir().getAbsolutePath() + "/avatars/"; File file = new File(getAvatarPath(context, avatar.getFilename()));
File file = new File(path+"/"+avatar.getFilename());
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
Log.d("xmppService",file.getAbsolutePath()); Log.d("xmppService",file.getAbsolutePath());
try { 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) { public Bitmap cropCenterSquare(Uri image, int size) {
try { try {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();

View file

@ -1214,6 +1214,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket result) { public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE_RESULT) { if (result.getType() == IqPacket.TYPE_RESULT) {
account.setAvatar(avatar.getFilename());
callback.success(avatar); callback.success(avatar);
} else { } else {
callback.error(R.string.error_publish_avatar_server_reject, avatar); 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.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -134,10 +135,19 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (jid != null) { if (jid != null) {
this.account = xmppConnectionService.findAccountByJid(jid); this.account = xmppConnectionService.findAccountByJid(jid);
if (this.avatarUri == null) { 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()); .getSefliUri(getApplicationContext());
if (this.avatarUri != null) {
loadImageIntoPreview(this.avatarUri);
} }
}
} else {
loadImageIntoPreview(avatarUri); loadImageIntoPreview(avatarUri);
}
this.accountTextView.setText(this.account.getJid()); this.accountTextView.setText(this.account.getJid());
} }
} }