|
|
@ -26,13 +26,13 @@ import org.floens.chan.ui.toolbar.Toolbar; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public abstract class NavigationController extends Controller implements ControllerTransition.Callback, Toolbar.ToolbarCallback { |
|
|
|
public abstract class NavigationController extends Controller implements Toolbar.ToolbarCallback, ControllerTransition.Callback { |
|
|
|
public Toolbar toolbar; |
|
|
|
protected Toolbar toolbar; |
|
|
|
public FrameLayout container; |
|
|
|
protected FrameLayout container; |
|
|
|
|
|
|
|
|
|
|
|
private List<Controller> controllerList = new ArrayList<>(); |
|
|
|
protected List<Controller> controllerList = new ArrayList<>(); |
|
|
|
private ControllerTransition controllerTransition; |
|
|
|
protected ControllerTransition controllerTransition; |
|
|
|
private boolean blockingInput = false; |
|
|
|
protected boolean blockingInput = false; |
|
|
|
|
|
|
|
|
|
|
|
public NavigationController(Context context) { |
|
|
|
public NavigationController(Context context) { |
|
|
|
super(context); |
|
|
|
super(context); |
|
|
@ -58,31 +58,13 @@ public abstract class NavigationController extends Controller implements Control |
|
|
|
public boolean pushController(final Controller to, ControllerTransition controllerTransition) { |
|
|
|
public boolean pushController(final Controller to, ControllerTransition controllerTransition) { |
|
|
|
if (blockingInput) return false; |
|
|
|
if (blockingInput) return false; |
|
|
|
|
|
|
|
|
|
|
|
if (this.controllerTransition != null) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Cannot push controller while a transition is in progress."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Controller from = controllerList.size() > 0 ? controllerList.get(controllerList.size() - 1) : null; |
|
|
|
final Controller from = controllerList.size() > 0 ? controllerList.get(controllerList.size() - 1) : null; |
|
|
|
to.navigationController = this; |
|
|
|
to.navigationController = this; |
|
|
|
to.previousSiblingController = from; |
|
|
|
to.previousSiblingController = from; |
|
|
|
|
|
|
|
|
|
|
|
controllerList.add(to); |
|
|
|
controllerList.add(to); |
|
|
|
|
|
|
|
|
|
|
|
if (controllerTransition != null) { |
|
|
|
transition(from, to, true, controllerTransition); |
|
|
|
blockingInput = true; |
|
|
|
|
|
|
|
this.controllerTransition = controllerTransition; |
|
|
|
|
|
|
|
controllerTransition.setCallback(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControllerLogic.startTransition(from, to, false, true, container, controllerTransition); |
|
|
|
|
|
|
|
toolbar.setNavigationItem(true, true, to.navigationItem); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ControllerLogic.transition(from, to, false, true, container); |
|
|
|
|
|
|
|
toolbar.setNavigationItem(false, true, to.navigationItem); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateToolbarCollapse(to, controllerTransition != null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllerPushed(to); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -101,44 +83,65 @@ public abstract class NavigationController extends Controller implements Control |
|
|
|
public boolean popController(ControllerTransition controllerTransition) { |
|
|
|
public boolean popController(ControllerTransition controllerTransition) { |
|
|
|
if (blockingInput) return false; |
|
|
|
if (blockingInput) return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Controller from = controllerList.get(controllerList.size() - 1); |
|
|
|
|
|
|
|
final Controller to = controllerList.size() > 1 ? controllerList.get(controllerList.size() - 2) : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transition(from, to, false, controllerTransition); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void controllerPopped(Controller controller) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void transition(Controller from, Controller to, boolean pushing, ControllerTransition controllerTransition) { |
|
|
|
if (this.controllerTransition != null) { |
|
|
|
if (this.controllerTransition != null) { |
|
|
|
throw new IllegalArgumentException("Cannot pop controller while a transition is in progress."); |
|
|
|
throw new IllegalArgumentException("Cannot transition while another transition is in progress."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (controllerList.size() == 0) { |
|
|
|
if (!pushing && controllerList.size() == 0) { |
|
|
|
throw new IllegalArgumentException("Cannot pop with no controllers left"); |
|
|
|
throw new IllegalArgumentException("Cannot pop with no controllers left"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Controller from = controllerList.get(controllerList.size() - 1); |
|
|
|
|
|
|
|
final Controller to = controllerList.size() > 1 ? controllerList.get(controllerList.size() - 2) : null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (controllerTransition != null) { |
|
|
|
if (controllerTransition != null) { |
|
|
|
blockingInput = true; |
|
|
|
blockingInput = true; |
|
|
|
this.controllerTransition = controllerTransition; |
|
|
|
this.controllerTransition = controllerTransition; |
|
|
|
controllerTransition.setCallback(this); |
|
|
|
controllerTransition.setCallback(this); |
|
|
|
|
|
|
|
ControllerLogic.startTransition(from, to, pushing, container, controllerTransition); |
|
|
|
ControllerLogic.startTransition(from, to, true, false, container, controllerTransition); |
|
|
|
|
|
|
|
if (to != null) { |
|
|
|
if (to != null) { |
|
|
|
toolbar.setNavigationItem(true, false, to.navigationItem); |
|
|
|
toolbar.setNavigationItem(true, false, to.navigationItem); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ControllerLogic.transition(from, to, true, false, container); |
|
|
|
ControllerLogic.transition(from, to, pushing, container); |
|
|
|
if (to != null) { |
|
|
|
if (to != null) { |
|
|
|
toolbar.setNavigationItem(false, false, to.navigationItem); |
|
|
|
toolbar.setNavigationItem(false, false, to.navigationItem); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!pushing) { |
|
|
|
controllerList.remove(from); |
|
|
|
controllerList.remove(from); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (to != null) { |
|
|
|
if (to != null) { |
|
|
|
updateToolbarCollapse(to, controllerTransition != null); |
|
|
|
updateToolbarCollapse(to, controllerTransition != null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pushing) { |
|
|
|
|
|
|
|
controllerPushed(to); |
|
|
|
|
|
|
|
} else { |
|
|
|
controllerPopped(to); |
|
|
|
controllerPopped(to); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onControllerTransitionCompleted(ControllerTransition transition) { |
|
|
|
|
|
|
|
ControllerLogic.finishTransition(transition); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (transition.destroyFrom) { |
|
|
|
|
|
|
|
controllerList.remove(transition.from); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void controllerPopped(Controller controller) { |
|
|
|
controllerTransition = null; |
|
|
|
|
|
|
|
blockingInput = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Controller getTop() { |
|
|
|
public Controller getTop() { |
|
|
@ -156,16 +159,8 @@ public abstract class NavigationController extends Controller implements Control |
|
|
|
return controllerList; |
|
|
|
return controllerList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Toolbar getToolbar() { |
|
|
|
public void onControllerTransitionCompleted(ControllerTransition transition) { |
|
|
|
return toolbar; |
|
|
|
ControllerLogic.finishTransition(transition); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (transition.destroyFrom) { |
|
|
|
|
|
|
|
controllerList.remove(transition.from); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.controllerTransition = null; |
|
|
|
|
|
|
|
blockingInput = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean onBack() { |
|
|
|
public boolean onBack() { |
|
|
|