diff options
author | steckbrief <steckbrief@chefmail.de> | 2017-08-06 01:15:13 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2017-08-06 01:15:13 +0200 |
commit | 867afe4c5b888ce3f4f9a867906cc8edb86e7aba (patch) | |
tree | 82d17b5fcb4471ae884a548fa815a653cb00e000 /src/main/java/de/thedevstack/conversationsplus/services/avatar/listener/AvatarMetadataReceived.java | |
parent | 6f588444a953a54543661f7603d45a9093b7196a (diff) |
avatar handling refactored
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/services/avatar/listener/AvatarMetadataReceived.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/avatar/listener/AvatarMetadataReceived.java b/src/main/java/de/thedevstack/conversationsplus/services/avatar/listener/AvatarMetadataReceived.java new file mode 100644 index 00000000..b993ff18 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/avatar/listener/AvatarMetadataReceived.java @@ -0,0 +1,47 @@ +package de.thedevstack.conversationsplus.services.avatar.listener; + +import de.thedevstack.conversationsplus.ConversationsPlusApplication; +import de.thedevstack.conversationsplus.entities.Account; +import de.thedevstack.conversationsplus.persistance.DatabaseBackend; +import de.thedevstack.conversationsplus.services.avatar.AvatarCache; +import de.thedevstack.conversationsplus.services.avatar.AvatarService; +import de.thedevstack.conversationsplus.ui.UiCallback; +import de.thedevstack.conversationsplus.utils.AvatarUtil; +import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacketParser; +import de.thedevstack.conversationsplus.xmpp.pep.Avatar; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * + */ +public class AvatarMetadataReceived extends AbstractAvatarIqPacketReceived { + + public AvatarMetadataReceived(UiCallback uiCallback) { + super(null, uiCallback); + } + + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() == IqPacket.TYPE.RESULT) { + Avatar avatar = AvatarPacketParser.parseMetadata(packet); + if (avatar != null) { + avatar.owner = account.getJid().toBareJid(); + if (AvatarUtil.isAvatarCached(avatar)) { + if (account.setAvatar(avatar.getFilename())) { + DatabaseBackend.getInstance(ConversationsPlusApplication.getAppContext()).updateAccount(account); + } + AvatarCache.clear(account); + if (null != callback) { + callback.success(avatar); + } + } else { + AvatarService.getInstance().fetchAvatarPep(account, avatar, callback); + } + return; + } + } + if (null != callback) { + callback.error(0, null); + } + } +} |