Skip to content

Commit

Permalink
Avoid crash in app status reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Jun 7, 2021
1 parent 6bef76b commit b7412a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="space.celestia.mobilecelestia"
android:versionCode="198"
android:versionCode="199"
android:versionName="1.3.5">

<uses-feature android:glEsVersion="0x00020000" android:required="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,48 @@ public interface Listener {
}

public void register(Listener listener) {
if (!listeners.contains(listener))
listeners.add(listener);
synchronized (lock) {
if (!listeners.contains(listener))
listeners.add(listener);
}
}

public void unregister(Listener listener) {
listeners.remove(listener);
synchronized (lock) {
listeners.remove(listener);
}
}

@Override
public void onCelestiaProgress(@NonNull String progress) {
synchronized (lock) {
String result = String.format(CelestiaAppCore.getLocalizedString("Loading: %s"), progress);
updateStatus(result);
}
updateStatus(String.format(CelestiaAppCore.getLocalizedString("Loading: %s"), progress));
}

public void updateState(@NonNull State state) {
ArrayList<Listener> currentListeners;
synchronized (lock) {
this.state = state;
currentListeners = new ArrayList<>(listeners.size());
for (Listener listener : listeners) {
listener.celestiaLoadingStateChanged(state);
currentListeners.add(listener);
}
}
for (Listener listener : currentListeners) {
listener.celestiaLoadingStateChanged(state);
}
}

public void updateStatus(@NonNull String status) {
ArrayList<Listener> currentListeners;
synchronized (lock) {
this.status = status;
currentListeners = new ArrayList<>(listeners.size());
for (Listener listener : listeners) {
listener.celestiaLoadingProgress(status);
currentListeners.add(listener);
}
}
for (Listener listener : currentListeners) {
listener.celestiaLoadingProgress(status);
}
}
}

0 comments on commit b7412a9

Please sign in to comment.