Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
This commit is contained in:
commit
424477dfbc
4 changed files with 62 additions and 65 deletions
|
@ -44,7 +44,7 @@ public class IqGenerator extends AbstractGenerator {
|
|||
return packet;
|
||||
}
|
||||
|
||||
protected IqPacket publish(final String node, final Element item) {
|
||||
protected static IqPacket publish(final String node, final Element item) {
|
||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||
final Element pubsub = packet.addChild("pubsub",
|
||||
"http://jabber.org/protocol/pubsub");
|
||||
|
@ -66,7 +66,7 @@ public class IqGenerator extends AbstractGenerator {
|
|||
return packet;
|
||||
}
|
||||
|
||||
public IqPacket publishAvatar(Avatar avatar) {
|
||||
public static IqPacket publishAvatar(Avatar avatar) {
|
||||
final Element item = new Element("item");
|
||||
item.setAttribute("id", avatar.sha1sum);
|
||||
final Element data = item.addChild("data", "urn:xmpp:avatar:data");
|
||||
|
@ -74,7 +74,7 @@ public class IqGenerator extends AbstractGenerator {
|
|||
return publish("urn:xmpp:avatar:data", item);
|
||||
}
|
||||
|
||||
public IqPacket publishAvatarMetadata(final Avatar avatar) {
|
||||
public static IqPacket publishAvatarMetadata(final Avatar avatar) {
|
||||
final Element item = new Element("item");
|
||||
item.setAttribute("id", avatar.sha1sum);
|
||||
final Element metadata = item
|
||||
|
|
|
@ -19,6 +19,7 @@ import de.thedevstack.conversationsplus.utils.ImageUtil;
|
|||
import de.thedevstack.conversationsplus.utils.UiUpdateHelper;
|
||||
import de.thedevstack.conversationsplus.utils.XmppSendUtil;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Bookmark;
|
||||
|
@ -303,6 +304,63 @@ public class AvatarService {
|
|||
canvas.drawBitmap(bm, null, dst, null);
|
||||
}
|
||||
|
||||
public void publishAvatar(final Account account,
|
||||
final Uri image,
|
||||
final UiCallback<Avatar> callback) {
|
||||
final Bitmap.CompressFormat format = Config.AVATAR_FORMAT;
|
||||
final int size = Config.AVATAR_SIZE;
|
||||
final Avatar avatar = AvatarUtil.getPepAvatar(image, size, format);
|
||||
if (avatar != null) {
|
||||
avatar.height = size;
|
||||
avatar.width = size;
|
||||
if (format.equals(Bitmap.CompressFormat.WEBP)) {
|
||||
avatar.type = "image/webp";
|
||||
} else if (format.equals(Bitmap.CompressFormat.JPEG)) {
|
||||
avatar.type = "image/jpeg";
|
||||
} else if (format.equals(Bitmap.CompressFormat.PNG)) {
|
||||
avatar.type = "image/png";
|
||||
}
|
||||
if (!AvatarUtil.save(avatar)) {
|
||||
callback.error(R.string.error_saving_avatar, avatar);
|
||||
return;
|
||||
}
|
||||
final IqPacket packet = IqGenerator.publishAvatar(avatar);
|
||||
XmppSendUtil.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||
|
||||
@Override
|
||||
public void onIqPacketReceived(Account account, IqPacket result) {
|
||||
if (result.getType() == IqPacket.TYPE.RESULT) {
|
||||
final IqPacket packet = IqGenerator.publishAvatarMetadata(avatar);
|
||||
XmppSendUtil.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||
|
||||
@Override
|
||||
public void onIqPacketReceived(Account account,
|
||||
IqPacket result) {
|
||||
if (result.getType() == IqPacket.TYPE.RESULT) {
|
||||
if (account.setAvatar(avatar.getFilename())) {
|
||||
AvatarService.getInstance().clear(account);
|
||||
DatabaseBackend.getInstance(ConversationsPlusApplication.getAppContext()).updateAccount(account);
|
||||
}
|
||||
callback.success(avatar);
|
||||
} else {
|
||||
callback.error(
|
||||
R.string.error_publish_avatar_server_reject,
|
||||
avatar);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback.error(
|
||||
R.string.error_publish_avatar_server_reject,
|
||||
avatar);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback.error(R.string.error_publish_avatar_converting, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateFetchKey(Account account, final Avatar avatar) {
|
||||
return account.getJid().toBareJid()+"_"+avatar.owner+"_"+avatar.sha1sum;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.app.Service;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.ContentObserver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
|
@ -49,7 +48,6 @@ import de.thedevstack.android.logcat.Logging;
|
|||
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
|
||||
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
|
||||
import de.thedevstack.conversationsplus.exceptions.FileCopyException;
|
||||
import de.thedevstack.conversationsplus.utils.AvatarUtil;
|
||||
import de.thedevstack.conversationsplus.utils.FileHelper;
|
||||
import de.thedevstack.conversationsplus.utils.ImageUtil;
|
||||
import de.thedevstack.conversationsplus.utils.MessageUtil;
|
||||
|
@ -104,7 +102,6 @@ import eu.siacs.conversations.xmpp.jid.Jid;
|
|||
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
|
||||
import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived;
|
||||
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
|
||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
||||
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||
|
@ -1845,64 +1842,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||
}
|
||||
}
|
||||
|
||||
public void publishAvatar(final Account account,
|
||||
final Uri image,
|
||||
final UiCallback<Avatar> callback) {
|
||||
final Bitmap.CompressFormat format = Config.AVATAR_FORMAT;
|
||||
final int size = Config.AVATAR_SIZE;
|
||||
final Avatar avatar = AvatarUtil.getPepAvatar(image, size, format);
|
||||
if (avatar != null) {
|
||||
avatar.height = size;
|
||||
avatar.width = size;
|
||||
if (format.equals(Bitmap.CompressFormat.WEBP)) {
|
||||
avatar.type = "image/webp";
|
||||
} else if (format.equals(Bitmap.CompressFormat.JPEG)) {
|
||||
avatar.type = "image/jpeg";
|
||||
} else if (format.equals(Bitmap.CompressFormat.PNG)) {
|
||||
avatar.type = "image/png";
|
||||
}
|
||||
if (!AvatarUtil.save(avatar)) {
|
||||
callback.error(R.string.error_saving_avatar, avatar);
|
||||
return;
|
||||
}
|
||||
final IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
|
||||
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||
|
||||
@Override
|
||||
public void onIqPacketReceived(Account account, IqPacket result) {
|
||||
if (result.getType() == IqPacket.TYPE.RESULT) {
|
||||
final IqPacket packet = XmppConnectionService.this.mIqGenerator
|
||||
.publishAvatarMetadata(avatar);
|
||||
sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||
|
||||
@Override
|
||||
public void onIqPacketReceived(Account account,
|
||||
IqPacket result) {
|
||||
if (result.getType() == IqPacket.TYPE.RESULT) {
|
||||
if (account.setAvatar(avatar.getFilename())) {
|
||||
AvatarService.getInstance().clear(account);
|
||||
databaseBackend.updateAccount(account);
|
||||
}
|
||||
callback.success(avatar);
|
||||
} else {
|
||||
callback.error(
|
||||
R.string.error_publish_avatar_server_reject,
|
||||
avatar);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback.error(
|
||||
R.string.error_publish_avatar_server_reject,
|
||||
avatar);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback.error(R.string.error_publish_avatar_converting, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteContactOnServer(Contact contact) {
|
||||
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
||||
|
|
|
@ -107,7 +107,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
|
|||
if (avatarUri != null) {
|
||||
publishButton.setText(R.string.publishing);
|
||||
disablePublishButton();
|
||||
xmppConnectionService.publishAvatar(account, avatarUri,
|
||||
AvatarService.getInstance().publishAvatar(account, avatarUri,
|
||||
avatarPublication);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue