aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-03 21:50:16 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-03 21:50:16 +0200
commite52b3d8942ec9843533c0a08040e8b8436aa4454 (patch)
tree1cde5ef2a0243359b14e068dce3c1ac40baa1490 /src/main/java/de/pixart/messenger/ui
parentcac0d886bdaee1fbbd57b03192c4f57d5889e40b (diff)
organize listeners in lists
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java37
1 files changed, 13 insertions, 24 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index c77545be6..c7dba686d 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -59,6 +59,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import de.pixart.messenger.Config;
@@ -94,7 +95,7 @@ public abstract class XmppActivity extends ActionBarActivity {
public XmppConnectionService xmppConnectionService;
public boolean xmppConnectionServiceBound = false;
- protected boolean registeredListeners = false;
+ protected final AtomicBoolean registeredListeners = new AtomicBoolean(false);
protected int mColorRed;
protected int mColorWarningButton;
@@ -119,9 +120,8 @@ public abstract class XmppActivity extends ActionBarActivity {
XmppConnectionBinder binder = (XmppConnectionBinder) service;
xmppConnectionService = binder.getService();
xmppConnectionServiceBound = true;
- if (!registeredListeners && shouldRegisterListeners()) {
+ if (registeredListeners.compareAndSet(false, true)) {
registerListeners();
- registeredListeners = true;
}
invalidateOptionsMenu();
onBackendConnected();
@@ -226,23 +226,13 @@ public abstract class XmppActivity extends ActionBarActivity {
connectToBackend();
}
} else {
- if (!registeredListeners) {
+ if (registeredListeners.compareAndSet(false, true)) {
this.registerListeners();
- this.registeredListeners = true;
}
this.onBackendConnected();
}
}
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
- protected boolean shouldRegisterListeners() {
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- return !isDestroyed() && !isFinishing();
- } else {
- return !isFinishing();
- }
- }
-
public void connectToBackend() {
Intent intent = new Intent(this, XmppConnectionService.class);
intent.setAction("ui");
@@ -254,9 +244,8 @@ public abstract class XmppActivity extends ActionBarActivity {
protected void onStop() {
super.onStop();
if (xmppConnectionServiceBound) {
- if (registeredListeners) {
+ if (registeredListeners.compareAndSet(true, false)) {
this.unregisterListeners();
- this.registeredListeners = false;
}
unbindService(mConnection);
xmppConnectionServiceBound = false;
@@ -337,28 +326,28 @@ public abstract class XmppActivity extends ActionBarActivity {
protected void unregisterListeners() {
if (this instanceof XmppConnectionService.OnConversationUpdate) {
- this.xmppConnectionService.removeOnConversationListChangedListener();
+ this.xmppConnectionService.removeOnConversationListChangedListener((XmppConnectionService.OnConversationUpdate) this);
}
if (this instanceof XmppConnectionService.OnAccountUpdate) {
- this.xmppConnectionService.removeOnAccountListChangedListener();
+ this.xmppConnectionService.removeOnAccountListChangedListener((XmppConnectionService.OnAccountUpdate) this);
}
if (this instanceof XmppConnectionService.OnCaptchaRequested) {
- this.xmppConnectionService.removeOnCaptchaRequestedListener();
+ this.xmppConnectionService.removeOnCaptchaRequestedListener((XmppConnectionService.OnCaptchaRequested) this);
}
if (this instanceof XmppConnectionService.OnRosterUpdate) {
- this.xmppConnectionService.removeOnRosterUpdateListener();
+ this.xmppConnectionService.removeOnRosterUpdateListener((XmppConnectionService.OnRosterUpdate) this);
}
if (this instanceof XmppConnectionService.OnMucRosterUpdate) {
- this.xmppConnectionService.removeOnMucRosterUpdateListener();
+ this.xmppConnectionService.removeOnMucRosterUpdateListener((XmppConnectionService.OnMucRosterUpdate) this);
}
if (this instanceof OnUpdateBlocklist) {
- this.xmppConnectionService.removeOnUpdateBlocklistListener();
+ this.xmppConnectionService.removeOnUpdateBlocklistListener((OnUpdateBlocklist) this);
}
if (this instanceof XmppConnectionService.OnShowErrorToast) {
- this.xmppConnectionService.removeOnShowErrorToastListener();
+ this.xmppConnectionService.removeOnShowErrorToastListener((XmppConnectionService.OnShowErrorToast) this);
}
if (this instanceof OnKeyStatusUpdated) {
- this.xmppConnectionService.removeOnNewKeysAvailableListener();
+ this.xmppConnectionService.removeOnNewKeysAvailableListener((OnKeyStatusUpdated) this);
}
}