mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Introduce Exception handler for when no result needs to be returned
Also add NotNull annotation to classes that were touched
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
public interface ExceptionHandler<E extends Exception> {
|
||||
|
||||
void onException(E exception);
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
public interface ResultExceptionHandler<R, E extends Exception> {
|
||||
public interface ResultExceptionHandler<R, E extends Exception>
|
||||
extends ExceptionHandler<E> {
|
||||
|
||||
void onResult(R result);
|
||||
|
||||
void onException(E exception);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.DestroyableContext;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class UiExceptionHandler<E extends Exception>
|
||||
implements ExceptionHandler<E> {
|
||||
|
||||
protected final DestroyableContext listener;
|
||||
|
||||
protected UiExceptionHandler(DestroyableContext listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onExceptionUi(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public abstract void onExceptionUi(E exception);
|
||||
|
||||
}
|
||||
@@ -3,14 +3,17 @@ package org.briarproject.android.controller.handler;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.DestroyableContext;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
implements ResultExceptionHandler<R, E> {
|
||||
|
||||
private final DestroyableContext listener;
|
||||
extends UiExceptionHandler<E> implements ResultExceptionHandler<R, E> {
|
||||
|
||||
protected UiResultExceptionHandler(DestroyableContext listener) {
|
||||
this.listener = listener;
|
||||
super(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,19 +26,7 @@ public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onExceptionUi(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public abstract void onResultUi(R result);
|
||||
|
||||
@UiThread
|
||||
public abstract void onExceptionUi(E exception);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user