package de.thedevstack.conversationsplus.services.filetransfer.http.delete; import android.widget.Toast; import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.enums.FileStatus; import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.utils.ui.ConversationsPlusToast; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; import de.thedevstack.conversationsplus.xmpp.exceptions.ServiceUnavailableException; import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete.DeletedPacketParser; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; /** * */ public class DeletedIqPacketReceived implements OnIqPacketReceived { private final DeleteRemoteFile remoteFile; public DeletedIqPacketReceived(DeleteRemoteFile remoteFile) { this.remoteFile = remoteFile; } @Override public void onIqPacketReceived(Account account, IqPacket packet) { try { boolean fileIsDeleted = DeletedPacketParser.parseDeleteToken(packet); if (fileIsDeleted) { MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), FileStatus.DELETED); Logging.i("filetransfer.http.delete", "Remote file successfully deleted '" + remoteFile.getPath() + "'"); } else { Logging.e("filetransfer.http.delete", "Unexpectedly failed to delete remote file."); } } catch (XmppException e) { Logging.e("filetransfer.http.delete", "Error while trying to delete remote file: " + e.getMessage()); int messageResId = R.string.cplus_remote_file_delete_failed; if (e instanceof ServiceUnavailableException) { messageResId = R.string.cplus_remote_file_delete_service_unavailable; } ConversationsPlusToast.makeErrorToast(messageResId, Toast.LENGTH_LONG); MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), FileStatus.DELETE_FAILED); } } }