Skip to content

Instantly share code, notes, and snippets.

@romandev
Created June 10, 2020 05:00
Show Gist options
  • Save romandev/350d28abf333a74ca6ee8996377fb2e5 to your computer and use it in GitHub Desktop.
Save romandev/350d28abf333a74ca6ee8996377fb2e5 to your computer and use it in GitHub Desktop.
Namyam
public class LifeCycleDelegateDialog extends Dialog {
interface LifeCycleDelegate {
default void onDismiss() {}
default void onResume() {}
default void onPause() {}
...
}
private LifeCycleDelegate mDelegate;
public void setDelegate(LifeCycleDelegate delegate) {
mDelegate = delegate;
}
@Override
public void onDismiss() {
mDelegate.onDismiss();
}
@Override
public void onResume() {
mDelegate.onResume();
}
@Override
public void onPause() {
mDelegate.onPause();
}
...
}
interface AuthenticationView {
void show();
void hide();
void updateStatus();
void showErrorMessage();
...
}
class AuthenticationDialog extends LifeCycleDelegateDialog implements AuthenticationView {
public AuthenticationDialog(LifeCycleDelegate delegate) {
super(delegate);
inflateLayout(AuthenticationViewFactory.create(type));
}
@Override
public void show() {
...
}
@Override
public void hide() {
...
}
@Override
public void updateStatus() {
...
}
@Override
public void showErrorMessage() {
...
}
}
public class AuthenticationController implements LifeCycleDelegate {
private AuthenticationView mView;
private Driver mDriver;
@Override
public AuthenticationController(AuthenticationView view, Driver driver) {
mView = view;
mView.setDelegate(th
mDriver = driver;
}
@Override
public void onResume() {
mDriver.authenticate(...);
}
@Override
public void onPause() {
mDriver.cancelAuthenticate(...);
}
@Override
public void onAuthenticateEvent(Event e) {
switch (e) {
case FINGERPRINT_ERROR:
mView.updateStatus(...);
break;
case IRIS_ERROR:
mView.showErrorMessage(...);
break;
case LOCKOUT:
mView.showLockoutMessage(...);
break;
case TIMEOUT:
mView.showTimeoutMessage(...);
break;
case SUCCESS:
handleCallback(...);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment