aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java59
1 files changed, 49 insertions, 10 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 2fead2380..ee212aed0 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -57,12 +57,11 @@ import eu.siacs.conversations.entities.Blockable;
import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
-import eu.siacs.conversations.entities.Downloadable;
-import eu.siacs.conversations.entities.DownloadablePlaceholder;
+import eu.siacs.conversations.entities.Transferable;
+import eu.siacs.conversations.entities.TransferablePlaceholder;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
-import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.generator.MessageGenerator;
import eu.siacs.conversations.generator.PresenceGenerator;
@@ -234,6 +233,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private MessageArchiveService mMessageArchiveService = new MessageArchiveService(this);
private OnConversationUpdate mOnConversationUpdate = null;
private int convChangedListenerCount = 0;
+ private OnShowErrorToast mOnShowErrorToast = null;
+ private int showErrorToastListenerCount = 0;
private int unreadCount = -1;
private OnAccountUpdate mOnAccountUpdate = null;
private OnStatusChanged statusListener = new OnStatusChanged() {
@@ -631,7 +632,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
Context context = getApplicationContext();
AlarmManager alarmManager = (AlarmManager) context
- .getSystemService(Context.ALARM_SERVICE);
+ .getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, EventReceiver.class);
alarmManager.cancel(PendingIntent.getBroadcast(context, 0, intent, 0));
Log.d(Config.LOGTAG, "good bye");
@@ -685,7 +686,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void sendMessage(final Message message) {
- sendMessage(message,false);
+ sendMessage(message, false);
}
private void sendMessage(final Message message, final boolean resend) {
@@ -818,7 +819,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void resendMessage(final Message message) {
- sendMessage(message,true);
+ sendMessage(message, true);
}
public void fetchRosterFromServer(final Account account) {
@@ -973,7 +974,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onMessageFound(Message message) {
if (!getFileBackend().isFileAvailable(message)) {
- message.setDownloadable(new DownloadablePlaceholder(Downloadable.STATUS_DELETED));
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
}
}
});
@@ -984,7 +985,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
Message message = conversation.findMessageWithFileAndUuid(uuid);
if (message != null) {
if (!getFileBackend().isFileAvailable(message)) {
- message.setDownloadable(new DownloadablePlaceholder(Downloadable.STATUS_DELETED));
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
updateConversationUi();
}
return;
@@ -1241,6 +1242,32 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
+ public void setOnShowErrorToastListener(OnShowErrorToast onShowErrorToast) {
+ synchronized (this) {
+ if (checkListeners()) {
+ switchToForeground();
+ }
+ this.mOnShowErrorToast = onShowErrorToast;
+ if (this.showErrorToastListenerCount < 2) {
+ this.showErrorToastListenerCount++;
+ }
+ }
+ this.mOnShowErrorToast = onShowErrorToast;
+ }
+
+ public void removeOnShowErrorToastListener() {
+ synchronized (this) {
+ this.showErrorToastListenerCount--;
+ if (this.showErrorToastListenerCount <= 0) {
+ this.showErrorToastListenerCount = 0;
+ this.mOnShowErrorToast = null;
+ if (checkListeners()) {
+ switchToBackground();
+ }
+ }
+ }
+ }
+
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
synchronized (this) {
if (checkListeners()) {
@@ -1345,7 +1372,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return (this.mOnAccountUpdate == null
&& this.mOnConversationUpdate == null
&& this.mOnRosterUpdate == null
- && this.mOnUpdateBlocklist == null);
+ && this.mOnUpdateBlocklist == null
+ && this.mOnShowErrorToast == null);
}
private void switchToForeground() {
@@ -1671,7 +1699,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) {
List<Jid> jids = new ArrayList<>();
for (MucOptions.User user : conference.getMucOptions().getUsers()) {
- if (user.getAffiliation() == before) {
+ if (user.getAffiliation() == before && user.getJid() != null) {
jids.add(user.getJid());
}
}
@@ -2196,6 +2224,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return count;
}
+
+ public void showErrorToastInUi(int resId) {
+ if (mOnShowErrorToast != null) {
+ mOnShowErrorToast.onShowErrorToast(resId);
+ }
+ }
+
public void updateConversationUi() {
if (mOnConversationUpdate != null) {
mOnConversationUpdate.onConversationUpdate();
@@ -2529,6 +2564,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void onPushFailed();
}
+ public interface OnShowErrorToast {
+ void onShowErrorToast(int resId);
+ }
+
public class XmppConnectionBinder extends Binder {
public XmppConnectionService getService() {
return XmppConnectionService.this;