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) {
|
synchronized (LISTENER_LOCK) {
|
||||||
for (OnShowErrorToast listener : this.mOnShowErrorToasts) {
|
return set.size() == 0 ? Collections.emptyList() : new ArrayList<>(set);
|
||||||
listener.onShowErrorToast(resId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showErrorToastInUi(int resId) {
|
||||||
|
for (OnShowErrorToast listener : threadSafeList(this.mOnShowErrorToasts)) {
|
||||||
|
listener.onShowErrorToast(resId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateConversationUi() {
|
public void updateConversationUi() {
|
||||||
synchronized (LISTENER_LOCK) {
|
for (OnConversationUpdate listener : threadSafeList(this.mOnConversationUpdates)) {
|
||||||
for (OnConversationUpdate listener : this.mOnConversationUpdates) {
|
|
||||||
listener.onConversationUpdate();
|
listener.onConversationUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAccountUi() {
|
public void updateAccountUi() {
|
||||||
synchronized (LISTENER_LOCK) {
|
for (OnAccountUpdate listener : threadSafeList(this.mOnAccountUpdates)) {
|
||||||
for (OnAccountUpdate listener : this.mOnAccountUpdates) {
|
|
||||||
listener.onAccountUpdate();
|
listener.onAccountUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRosterUi() {
|
public void updateRosterUi() {
|
||||||
synchronized (LISTENER_LOCK) {
|
for (OnRosterUpdate listener : threadSafeList(this.mOnRosterUpdates)) {
|
||||||
for (OnRosterUpdate listener : this.mOnRosterUpdates) {
|
|
||||||
listener.onRosterUpdate();
|
listener.onRosterUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean displayCaptchaRequest(Account account, String id, Data data, Bitmap captcha) {
|
public boolean displayCaptchaRequest(Account account, String id, Data data, Bitmap captcha) {
|
||||||
synchronized (LISTENER_LOCK) {
|
|
||||||
if (mOnCaptchaRequested.size() > 0) {
|
if (mOnCaptchaRequested.size() > 0) {
|
||||||
DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
|
DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
|
||||||
Bitmap scaled = Bitmap.createScaledBitmap(captcha, (int) (captcha.getWidth() * metrics.scaledDensity),
|
Bitmap scaled = Bitmap.createScaledBitmap(captcha, (int) (captcha.getWidth() * metrics.scaledDensity),
|
||||||
(int) (captcha.getHeight() * metrics.scaledDensity), false);
|
(int) (captcha.getHeight() * metrics.scaledDensity), false);
|
||||||
for (OnCaptchaRequested listener : this.mOnCaptchaRequested) {
|
for (OnCaptchaRequested listener : threadSafeList(this.mOnCaptchaRequested)) {
|
||||||
listener.onCaptchaRequested(account, id, data, scaled);
|
listener.onCaptchaRequested(account, id, data, scaled);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateBlocklistUi(final OnUpdateBlocklist.Status status) {
|
public void updateBlocklistUi(final OnUpdateBlocklist.Status status) {
|
||||||
synchronized (LISTENER_LOCK) {
|
for (OnUpdateBlocklist listener : threadSafeList(this.mOnUpdateBlocklist)) {
|
||||||
for (OnUpdateBlocklist listener : this.mOnUpdateBlocklist) {
|
|
||||||
listener.OnUpdateBlocklist(status);
|
listener.OnUpdateBlocklist(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateMucRosterUi() {
|
public void updateMucRosterUi() {
|
||||||
synchronized (LISTENER_LOCK) {
|
for (OnMucRosterUpdate listener : threadSafeList(this.mOnMucRosterUpdate)) {
|
||||||
for (OnMucRosterUpdate listener : this.mOnMucRosterUpdate) {
|
|
||||||
listener.onMucRosterUpdate();
|
listener.onMucRosterUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void keyStatusUpdated(AxolotlService.FetchStatus report) {
|
public void keyStatusUpdated(AxolotlService.FetchStatus report) {
|
||||||
synchronized (LISTENER_LOCK) {
|
for (OnKeyStatusUpdated listener : threadSafeList(this.mOnKeyStatusUpdated)) {
|
||||||
for (OnKeyStatusUpdated listener : this.mOnKeyStatusUpdated) {
|
|
||||||
listener.onKeyStatusUpdated(report);
|
listener.onKeyStatusUpdated(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Account findAccountByJid(final Jid accountJid) {
|
public Account findAccountByJid(final Jid accountJid) {
|
||||||
for (Account account : this.accounts) {
|
for (Account account : this.accounts) {
|
||||||
|
|
Loading…
Reference in New Issue