mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 11:42:15 -05:00
show own avatar after publication. no persistancy yet
This commit is contained in:
parent
9aba9a4059
commit
08755e56a5
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user