Trigger with event

This commit is contained in:
topjohnwu 2016-12-25 15:29:24 +08:00
parent 2fa5e4679f
commit a5a2df4956
2 changed files with 9 additions and 6 deletions

View File

@ -68,7 +68,7 @@ public class Async {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
CallbackHandler.triggerCallback(StatusFragment.updateCheckDone); StatusFragment.updateCheckDone.trigger();
} }
} }
@ -77,7 +77,7 @@ public class Async {
@Override @Override
public void handleResults(int i) { public void handleResults(int i) {
StatusFragment.SNCheckResult = i; StatusFragment.SNCheckResult = i;
CallbackHandler.triggerCallback(StatusFragment.safetyNetDone); StatusFragment.safetyNetDone.trigger();
} }
}.requestTest(); }.requestTest();
} }
@ -92,7 +92,7 @@ public class Async {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
CallbackHandler.triggerCallback(ModulesFragment.moduleLoadDone); ModulesFragment.moduleLoadDone.trigger();
} }
} }
@ -112,7 +112,7 @@ public class Async {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
CallbackHandler.triggerCallback(ReposFragment.repoLoadDone); ReposFragment.repoLoadDone.trigger();
} }
} }

View File

@ -23,8 +23,7 @@ public class CallbackHandler {
} }
} }
public static void triggerCallback(Event event) { private static void triggerCallback(Event event) {
event.isTriggered = true;
HashSet<EventListener> list = listeners.get(event); HashSet<EventListener> list = listeners.get(event);
if (list != null) { if (list != null) {
for (EventListener listener : list) { for (EventListener listener : list) {
@ -35,6 +34,10 @@ public class CallbackHandler {
public static class Event { public static class Event {
public boolean isTriggered = false; public boolean isTriggered = false;
public void trigger() {
isTriggered = true;
triggerCallback(this);
}
} }
public interface EventListener { public interface EventListener {