change listener lock strategie
This commit is contained in:
parent
0f233022a6
commit
3014b7f857
|
@ -3224,76 +3224,66 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
|
||||
|
||||
public void showErrorToastInUi(int resId) {
|
||||
private <T> List<T> threadSafeList(Set<T> set) {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnShowErrorToast listener : this.mOnShowErrorToasts) {
|
||||
listener.onShowErrorToast(resId);
|
||||
return set.size() == 0 ? Collections.emptyList() : new ArrayList<>(set);
|
||||
}
|
||||
}
|
||||
|
||||
public void showErrorToastInUi(int resId) {
|
||||
for (OnShowErrorToast listener : threadSafeList(this.mOnShowErrorToasts)) {
|
||||
listener.onShowErrorToast(resId);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConversationUi() {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnConversationUpdate listener : this.mOnConversationUpdates) {
|
||||
for (OnConversationUpdate listener : threadSafeList(this.mOnConversationUpdates)) {
|
||||
listener.onConversationUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAccountUi() {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnAccountUpdate listener : this.mOnAccountUpdates) {
|
||||
for (OnAccountUpdate listener : threadSafeList(this.mOnAccountUpdates)) {
|
||||
listener.onAccountUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRosterUi() {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnRosterUpdate listener : this.mOnRosterUpdates) {
|
||||
for (OnRosterUpdate listener : threadSafeList(this.mOnRosterUpdates)) {
|
||||
listener.onRosterUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean displayCaptchaRequest(Account account, String id, Data data, Bitmap captcha) {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
if (mOnCaptchaRequested.size() > 0) {
|
||||
DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
|
||||
Bitmap scaled = Bitmap.createScaledBitmap(captcha, (int) (captcha.getWidth() * metrics.scaledDensity),
|
||||
(int) (captcha.getHeight() * metrics.scaledDensity), false);
|
||||
for (OnCaptchaRequested listener : this.mOnCaptchaRequested) {
|
||||
for (OnCaptchaRequested listener : threadSafeList(this.mOnCaptchaRequested)) {
|
||||
listener.onCaptchaRequested(account, id, data, scaled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBlocklistUi(final OnUpdateBlocklist.Status status) {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnUpdateBlocklist listener : this.mOnUpdateBlocklist) {
|
||||
for (OnUpdateBlocklist listener : threadSafeList(this.mOnUpdateBlocklist)) {
|
||||
listener.OnUpdateBlocklist(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMucRosterUi() {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnMucRosterUpdate listener : this.mOnMucRosterUpdate) {
|
||||
for (OnMucRosterUpdate listener : threadSafeList(this.mOnMucRosterUpdate)) {
|
||||
listener.onMucRosterUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyStatusUpdated(AxolotlService.FetchStatus report) {
|
||||
synchronized (LISTENER_LOCK) {
|
||||
for (OnKeyStatusUpdated listener : this.mOnKeyStatusUpdated) {
|
||||
for (OnKeyStatusUpdated listener : threadSafeList(this.mOnKeyStatusUpdated)) {
|
||||
listener.onKeyStatusUpdated(report);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Account findAccountByJid(final Jid accountJid) {
|
||||
for (Account account : this.accounts) {
|
||||
|
|
Loading…
Reference in New Issue