Skip to content

Instantly share code, notes, and snippets.

@dened
Last active February 13, 2017 07:34
Show Gist options
  • Save dened/386e48960d94f3d2599ec61068f21bad to your computer and use it in GitHub Desktop.
Save dened/386e48960d94f3d2599ec61068f21bad to your computer and use it in GitHub Desktop.
Навигатор по фрагментам и активити
public abstract class BaseNavigator extends SupportFragmentNavigator {
private static final String TAG = "BaseNavigator";
private AppCompatActivity activity;
public BaseNavigator(AppCompatActivity activity, int containerId) {
super(activity.getSupportFragmentManager(), containerId);
this.activity = activity;
}
@Override
public void applyCommand(Command command) {
Intent intent = createIntent(command);
if(intent == null) {
super.applyCommand(command);
} else if (command instanceof Forward) {
activity.startActivity(intent);
} else if(command instanceof Replace) {
activity.startActivity(intent);
activity.finish();
} else {
Log.e(TAG, "Command " + command.getClass().getSimpleName() + " was not executed!");
}
}
private @Nullable Intent createIntent(Command command) {
if(command instanceof Replace) {
return createIntent(activity, ((Replace) command).getScreenKey(), ((Replace) command).getTransitionData());
} else if(command instanceof Forward) {
return createIntent(activity, ((Forward) command).getScreenKey(), ((Forward) command).getTransitionData());
}
return null;
}
@Override
protected void showSystemMessage(String message) {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
}
@Override
protected void exit() {
activity.finish();
}
protected abstract @Nullable Intent createIntent(Context context, String screenName, Object transferData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment