Compare commits

...

5 Commits

Author SHA1 Message Date
Eric Kuck 8a70c09fea Big lifecycle update + a few bug fixes 2016-04-04 17:03:43 -05:00
Eric Kuck 343e8c92e5 Merge pull request #9 from ravidsrk/patch-1
Added code syntax highlighting to Readme
2016-04-01 06:49:14 -05:00
Ravindra Kumar 332788ee01 Added code syntax highlighting to Readme 2016-04-01 00:51:53 -04:00
Eric Kuck acf77101a7 Merge pull request #4 from sockeqwe/patch-1
Conductor class final; added private Constructor
2016-03-31 18:29:21 -05:00
Hannes Dorfmann cba372966d Conductor class final; added private Constructor 2016-04-01 00:32:04 +02:00
29 changed files with 172 additions and 187 deletions
+6 -6
View File
@@ -1,4 +1,4 @@
[![Travis Build](https://travis-ci.org/bluelinelabs/Conductor.svg)](https://travis-ci.org/bluelinelabs/Conductor)
[![Travis Build](https://travis-ci.org/bluelinelabs/Conductor.svg)](https://travis-ci.org/bluelinelabs/Conductor) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Conductor-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3361)
# Conductor
@@ -20,14 +20,14 @@ Conductor is architecture-agnostic and does not try to force any design decision
## Installation
```gradle
compile 'com.bluelinelabs:conductor:1.0.5'
compile 'com.bluelinelabs:conductor:1.1.0'
// If you want the components that go along with
// Android's support libraries (currently just a PagerAdapter):
compile 'com.bluelinelabs:conductor-support:1.0.5'
compile 'com.bluelinelabs:conductor-support:1.1.0'
// If you want RxJava/RxAndroid lifecycle support:
compile 'com.bluelinelabs:conductor-rxlifecycle:1.0.5'
compile 'com.bluelinelabs:conductor-rxlifecycle:1.1.0'
```
## Components to Know
@@ -43,7 +43,7 @@ __ControllerTransaction__ | Transactions are used to define data about adding Co
### Minimal Activity implementation
```
```java
public class MainActivity extends Activity {
private Router mRouter;
@@ -74,7 +74,7 @@ public class MainActivity extends Activity {
### Minimal Controller implementation
```
```java
public class HomeController extends Controller {
@Override
@@ -3,10 +3,10 @@ package com.bluelinelabs.conductor.rxlifecycle;
public enum ControllerEvent {
CREATE,
CREATE_VIEW,
ATTACH,
BIND_VIEW,
DETACH,
UNBIND_VIEW,
DESTROY_VIEW,
DESTROY
}
@@ -21,8 +21,8 @@ public class ControllerLifecycleSubjectHelper {
controller.addLifecycleListener(new LifecycleListener() {
@Override
public void preBindView(@NonNull Controller controller, @NonNull View view) {
subject.onNext(ControllerEvent.BIND_VIEW);
public void preCreateView(@NonNull Controller controller) {
subject.onNext(ControllerEvent.CREATE_VIEW);
}
@Override
@@ -31,13 +31,13 @@ public class ControllerLifecycleSubjectHelper {
}
@Override
public void preUnbindView(@NonNull Controller controller, @NonNull View view) {
subject.onNext(ControllerEvent.UNBIND_VIEW);
public void preDetach(@NonNull Controller controller, @NonNull View view) {
subject.onNext(ControllerEvent.DETACH);
}
@Override
public void preDetach(@NonNull Controller controller, @NonNull View view) {
subject.onNext(ControllerEvent.DETACH);
public void preDestroyView(@NonNull Controller controller, @NonNull View view) {
subject.onNext(ControllerEvent.DESTROY_VIEW);
}
@Override
@@ -33,8 +33,8 @@ public class RxControllerLifecycle {
return ControllerEvent.DESTROY;
case ATTACH:
return ControllerEvent.DETACH;
case BIND_VIEW:
return ControllerEvent.UNBIND_VIEW;
case CREATE_VIEW:
return ControllerEvent.DESTROY_VIEW;
case DETACH:
return ControllerEvent.DESTROY;
default:
@@ -75,10 +75,10 @@ class Backstack implements Iterable<RouterTransaction> {
return list;
}
public void saveInstanceState(Bundle outState) {
public void detachAndSaveInstanceState(Bundle outState) {
ArrayList<Bundle> entryBundles = new ArrayList<>(mBackStack.size());
for (RouterTransaction entry : mBackStack) {
entryBundles.add(entry.toBundle());
entryBundles.add(entry.detachAndSaveInstanceState());
}
outState.putParcelableArrayList(KEY_ENTRIES, entryBundles);
@@ -31,8 +31,8 @@ public class ChildControllerTransaction extends ControllerTransaction {
}
@Override
public Bundle toBundle() {
Bundle bundle = super.toBundle();
public Bundle detachAndSaveInstanceState() {
Bundle bundle = super.detachAndSaveInstanceState();
bundle.putInt(KEY_CONTAINER_ID, containerId);
bundle.putBoolean(KEY_ADD_TO_LOCAL_BACKSTACK, addToLocalBackstack);
return bundle;
@@ -10,8 +10,10 @@ import com.bluelinelabs.conductor.internal.LifecycleHandler;
/**
* Point of initial interaction with Conductor. Used to attach a {@link Router} to your Activity.
*/
public class Conductor {
public final class Conductor {
private Conductor(){}
/**
* Conductor will create a {@link Router} that has been initialized for your Activity and containing ViewGroup.
* If an existing {@link Router} is already associated with this Activity/ViewGroup pair, either in memory
@@ -108,7 +108,8 @@ public abstract class Controller {
/**
* Called when the controller is ready to display its view. A valid view must be returned. The standard body
* for this method will be {@code return inflater.inflate(R.layout.my_layout, container, false);}
* for this method will be {@code return inflater.inflate(R.layout.my_layout, container, false);}, plus
* any binding code.
*
* @param inflater The LayoutInflater that should be used to inflate views
* @param container The parent view that this Controller's view will eventually be attached to.
@@ -116,7 +117,7 @@ public abstract class Controller {
* so that valid LayoutParams can be used during inflation.
*/
@NonNull
protected abstract View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container);
protected abstract View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container);
/**
* Returns the {@link Router} object that can be used for pushing or popping other Controllers
@@ -271,22 +272,14 @@ public abstract class Controller {
/**
* Optional target for this Controller. One reason this could be used is to send results back to the Controller
* that started this one. Target Controllers are retained across instances.
*
* @param target The Controller that is the target of this one.
*/
public final void setTargetController(Controller target) {
mTargetInstanceId = target != null ? target.getInstanceId() : null;
onTargetControllerSet(target);
}
/**
* This method will be called when {@link #setTargetController(Controller)} is called. It is recommended
* that started this one. Target Controllers are retained across instances. It is recommended
* that Controllers enforce that their target Controller conform to a specific Interface.
*
* @param target The Controller that is the target of this one.
*/
public void onTargetControllerSet(Controller target) { }
public void setTargetController(Controller target) {
mTargetInstanceId = target != null ? target.getInstanceId() : null;
}
/**
* Returns the target Controller that was set with the {@link #setTargetController(Controller)} method
@@ -297,21 +290,13 @@ public abstract class Controller {
return mTargetInstanceId != null ? mRouter.getControllerWithInstanceId(mTargetInstanceId) : null;
}
/**
* Called when this Controller's View is inflated. This should overridden to bind the View
* to variables, either using findViewById or something like Butterknife.
*
* @param view The View to which this Controller should be bound.
*/
protected void onBindView(@NonNull final View view) { }
/**
* Called when this Controller's View is being destroyed. This should overridden to unbind the View
* from any local variables.
*
* @param view The View to which this Controller should be bound.
*/
protected void onUnbindView(View view) { }
protected void onDestroyView(View view) { }
/**
* Called when this Controller begins the process of being swapped in or out of the host view.
@@ -543,7 +528,7 @@ public abstract class Controller {
mOverriddenPopHandler = overriddenPopHandler;
}
final void prepareForConfigurationChange() {
final void prepareForActivityPause() {
mNeedsAttach = mNeedsAttach || mAttached;
}
@@ -661,8 +646,6 @@ public abstract class Controller {
lifecycleListener.preDetach(this, view);
}
saveViewState(view);
mAttached = false;
onDetach(view);
@@ -685,16 +668,20 @@ public abstract class Controller {
private void removeViewReference() {
if (mView != null) {
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.preUnbindView(this, mView);
if (!mIsBeingDestroyed) {
saveViewState(mView);
}
onUnbindView(mView);
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.preDestroyView(this, mView);
}
onDestroyView(mView);
mView = null;
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.postUnbindView(this);
lifecycleListener.postDestroyView(this);
}
}
@@ -705,13 +692,32 @@ public abstract class Controller {
final View inflate(@NonNull ViewGroup parent) {
if (mView == null) {
View view = inflateView(LayoutInflater.from(parent.getContext()), parent);
bindView(view);
restoreViewState(view);
return view;
} else {
return mView;
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.preCreateView(this);
}
mView = onCreateView(LayoutInflater.from(parent.getContext()), parent);
restoreViewState(mView);
mView.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
attach(v);
}
@Override
public void onViewDetachedFromWindow(View v) {
detach(v);
}
});
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.postCreateView(this, mView);
}
}
return mView;
}
final void performDestroy() {
@@ -779,9 +785,9 @@ public abstract class Controller {
}
}
final Bundle saveInstanceState() {
final Bundle detachAndSaveInstanceState() {
if (mAttached && mView != null) {
saveViewState(mView);
detach(mView);
}
Bundle outState = new Bundle();
@@ -802,7 +808,7 @@ public abstract class Controller {
ArrayList<Bundle> childBundles = new ArrayList<>();
for (ChildControllerTransaction childController : mChildControllers) {
childBundles.add(childController.toBundle());
childBundles.add(childController.detachAndSaveInstanceState());
}
outState.putParcelableArrayList(KEY_CHILDREN, childBundles);
@@ -856,32 +862,6 @@ public abstract class Controller {
}
}
private void bindView(@NonNull final View view) {
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.preBindView(this, view);
}
mView = view;
onBindView(view);
view.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
attach(view);
}
@Override
public void onViewDetachedFromWindow(View v) {
detach(view);
}
});
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.postBindView(this, view);
}
}
private void ensureRequiredConstructor() {
Constructor[] constructors = getClass().getConstructors();
if (getBundleConstructor(constructors) == null && getDefaultConstructor(constructors) == null) {
@@ -921,18 +901,18 @@ public abstract class Controller {
public void onChangeStart(@NonNull Controller controller, @NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { }
public void onChangeEnd(@NonNull Controller controller, @NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { }
public void preBindView(@NonNull Controller controller, @NonNull View view) { }
public void postBindView(@NonNull Controller controller, @NonNull View view) { }
public void preCreateView(@NonNull Controller controller) { }
public void postCreateView(@NonNull Controller controller, @NonNull View view) { }
public void preAttach(@NonNull Controller controller, @NonNull View view) { }
public void postAttach(@NonNull Controller controller, @NonNull View view) { }
public void preUnbindView(@NonNull Controller controller, @NonNull View view) { }
public void postUnbindView(@NonNull Controller controller) { }
public void preDetach(@NonNull Controller controller, @NonNull View view) { }
public void postDetach(@NonNull Controller controller, @NonNull View view) { }
public void preDestroyView(@NonNull Controller controller, @NonNull View view) { }
public void postDestroyView(@NonNull Controller controller) { }
public void preDestroy(@NonNull Controller controller) { }
public void postDestroy(@NonNull Controller controller) { }
@@ -77,10 +77,10 @@ public class ControllerTransaction {
/**
* Used to serialize this transaction into a Bundle
*/
public Bundle toBundle() {
public Bundle detachAndSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putBundle(KEY_VIEW_CONTROLLER_BUNDLE, controller.saveInstanceState());
bundle.putBundle(KEY_VIEW_CONTROLLER_BUNDLE, controller.detachAndSaveInstanceState());
if (mPushControllerChangeHandler != null) {
bundle.putBundle(KEY_PUSH_TRANSITION, mPushControllerChangeHandler.toBundle());
@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import com.bluelinelabs.conductor.Controller.LifecycleListener;
@@ -237,7 +238,20 @@ public class Router {
* @param changeHandler The {@link ControllerChangeHandler} to use for setting the root
*/
public void setRoot(@NonNull Controller controller, String tag, ControllerChangeHandler changeHandler) {
mContainer.removeAllViews();
RouterTransaction currentTop = mBackStack.peek();
if (currentTop != null && currentTop.controller.getView() != null) {
final View fromView = currentTop.controller.getView();
final int childCount = mContainer.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = mContainer.getChildAt(i);
if (child != fromView) {
mContainer.removeView(child);
}
}
}
trackDestroyingControllers(mBackStack.popAll());
RouterTransaction transaction = RouterTransaction.builder(controller)
@@ -247,7 +261,7 @@ public class Router {
.build();
pushToBackstack(transaction);
performControllerChange(transaction, null, true);
performControllerChange(transaction, currentTop, true);
}
/**
@@ -358,13 +372,11 @@ public class Router {
}
public final void onActivitySaveInstanceState(Activity activity, Bundle outState) {
if (activity.isChangingConfigurations()) {
for (RouterTransaction transaction : mBackStack) {
transaction.controller.prepareForConfigurationChange();
}
for (RouterTransaction transaction : mBackStack) {
transaction.controller.prepareForActivityPause();
}
mBackStack.saveInstanceState(outState);
mBackStack.detachAndSaveInstanceState(outState);
}
public final void onActivityDestroyed(Activity activity) {
@@ -466,14 +478,16 @@ public class Router {
}
private void trackDestroyingController(RouterTransaction transaction) {
mDestroyingControllers.add(transaction.controller);
if (!transaction.controller.isDestroyed()) {
mDestroyingControllers.add(transaction.controller);
transaction.controller.addLifecycleListener(new LifecycleListener() {
@Override
public void postDestroy(@NonNull Controller controller) {
mDestroyingControllers.remove(controller);
}
});
transaction.controller.addLifecycleListener(new LifecycleListener() {
@Override
public void postDestroy(@NonNull Controller controller) {
mDestroyingControllers.remove(controller);
}
});
}
}
private void trackDestroyingControllers(List<RouterTransaction> transactions) {
@@ -17,7 +17,7 @@ public class ControllerChangeHandlerTests {
.pushChangeHandler(horizontalChangeHandler)
.popChangeHandler(fadeChangeHandler)
.build();
RouterTransaction restoredTransaction = new RouterTransaction(transaction.toBundle());
RouterTransaction restoredTransaction = new RouterTransaction(transaction.detachAndSaveInstanceState());
ControllerChangeHandler restoredHorizontal = restoredTransaction.getPushControllerChangeHandler();
ControllerChangeHandler restoredFade = restoredTransaction.getPopControllerChangeHandler();
@@ -29,9 +29,9 @@ public class ControllerTests {
private int mChangeStartCalls;
private int mChangeEndCalls;
private int mBindViewCalls;
private int mCreateViewCalls;
private int mAttachCalls;
private int mUnbindViewCalls;
private int mDestroyViewCalls;
private int mDetachCalls;
private int mDestroyCalls;
@@ -44,9 +44,9 @@ public class ControllerTests {
mChangeStartCalls = 0;
mChangeEndCalls = 0;
mBindViewCalls = 0;
mCreateViewCalls = 0;
mAttachCalls = 0;
mUnbindViewCalls = 0;
mDestroyViewCalls = 0;
mDestroyCalls = 0;
mDestroyCalls = 0;
}
@@ -228,9 +228,9 @@ public class ControllerTests {
private void assertCalls(int changeStart, int changeEnd, int bindView, int attach, int unbindView, int detach, int destroy) {
Assert.assertEquals(changeStart, mChangeStartCalls);
Assert.assertEquals(changeEnd, mChangeEndCalls);
Assert.assertEquals(bindView, mBindViewCalls);
Assert.assertEquals(bindView, mCreateViewCalls);
Assert.assertEquals(attach, mAttachCalls);
Assert.assertEquals(unbindView, mUnbindViewCalls);
Assert.assertEquals(unbindView, mDestroyViewCalls);
Assert.assertEquals(detach, mDetachCalls);
Assert.assertEquals(destroy, mDestroyCalls);
}
@@ -248,8 +248,8 @@ public class ControllerTests {
}
@Override
public void postBindView(@NonNull Controller controller, @NonNull View view) {
mBindViewCalls++;
public void postCreateView(@NonNull Controller controller, @NonNull View view) {
mCreateViewCalls++;
}
@Override
@@ -258,8 +258,8 @@ public class ControllerTests {
}
@Override
public void postUnbindView(@NonNull Controller controller) {
mUnbindViewCalls++;
public void postDestroyView(@NonNull Controller controller) {
mDestroyViewCalls++;
}
@Override
@@ -20,7 +20,7 @@ public class ControllerTransactionTests {
.tag("Test Tag")
.build();
Bundle bundle = transaction.toBundle();
Bundle bundle = transaction.detachAndSaveInstanceState();
RouterTransaction restoredTransaction = new RouterTransaction(bundle);
@@ -39,7 +39,7 @@ public class ControllerTransactionTests {
.tag("Test Tag")
.build();
Bundle bundle = transaction.toBundle();
Bundle bundle = transaction.detachAndSaveInstanceState();
ChildControllerTransaction restoredTransaction = new ChildControllerTransaction(bundle);
@@ -15,7 +15,7 @@ public class TestController extends Controller {
@NonNull
@Override
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
View view = new FrameLayout(inflater.getContext());
view.setId(VIEW_ID);
return view;
@@ -41,8 +41,8 @@ public class ChildController extends RefWatchingController {
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
mTvTitle.setText(getArgs().getString(KEY_TITLE));
@@ -36,9 +36,7 @@ public class DragDismissController extends RefWatchingController {
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
((ElasticDragDismissFrameLayout)view).addListener(mDragDismissListener);
mTvLoremIpsum.setText("Lorem ipsum dolor sit amet, volutpat lacus egestas integer vitae, tempus potenti posuere dolore, elit cras ut vulputate pede eros. Pharetra curabitur, cum ultrices nisi nulla, non a est diamlorem in pede. Feugiat vivamus id, leo massa, pede ligula libero wisi, posuere nec interdum risus. Mauris eros. Scelerisque etiam dignissim, sem odio magna posuere libero in. Eget non posuere, rutrum nunc ut, ipsum ornare, vestibulum nisl turpis, urna interdum. Arcu mi velit. Sem dolor amet sed hymenaeos tempor. Cras felis.\n" +
@@ -48,9 +46,10 @@ public class DragDismissController extends RefWatchingController {
}
@Override
protected void onUnbindView(View view) {
super.onUnbindView(view);
protected void onDestroyView(View view) {
super.onDestroyView(view);
((ElasticDragDismissFrameLayout)view).removeListener(mDragDismissListener);
}
}
@@ -52,8 +52,8 @@ public class HomeController extends RefWatchingController {
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
@@ -45,8 +45,8 @@ public class NavigationDemoController extends RefWatchingController {
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
view.setBackgroundColor(ColorUtil.getMaterialColor(getResources(), mIndex));
mTvTitle.setText(getResources().getString(R.string.navigation_title, mIndex));
@@ -22,8 +22,8 @@ public class OverlayController extends RefWatchingController {
}
@Override
public void onBindView(@NonNull View view) {
super.onBindView(view);
public void onViewBound(@NonNull View view) {
super.onViewBound(view);
mTextView.setText("I'm an Overlay");
}
@@ -42,8 +42,8 @@ public class PagerController extends RefWatchingController {
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
mViewPager.setAdapter(mPagerAdapter);
}
@@ -48,10 +48,8 @@ public class RxLifecycleController extends RefWatchingController {
}
@Override
public void onBindView(@NonNull View view) {
super.onBindView(view);
Log.i(TAG, "onBindView() called");
public void onViewBound(@NonNull View view) {
Log.i(TAG, "onCreateView() called");
mTvTitle.setText(getResources().getString(R.string.rxlifecycle_title, TAG));
@@ -59,14 +57,14 @@ public class RxLifecycleController extends RefWatchingController {
.doOnUnsubscribe(new Action0() {
@Override
public void call() {
Log.i(TAG, "Unsubscribing from onBindView()");
Log.i(TAG, "Unsubscribing from onCreateView)");
}
})
.compose(this.<Long>bindUntilEvent(ControllerEvent.UNBIND_VIEW))
.compose(this.<Long>bindUntilEvent(ControllerEvent.DESTROY_VIEW))
.subscribe(new Action1<Long>() {
@Override
public void call(Long num) {
Log.i(TAG, "Started in onBindView(), running until onUnbindView(): " + num);
Log.i(TAG, "Started in onCreateView(), running until onDestroyView(): " + num);
}
});
}
@@ -94,10 +92,10 @@ public class RxLifecycleController extends RefWatchingController {
}
@Override
protected void onUnbindView(View view) {
super.onUnbindView(view);
protected void onDestroyView(View view) {
super.onDestroyView(view);
Log.i(TAG, "onUnbindView() called");
Log.i(TAG, "onDestroyView() called");
}
@Override
@@ -123,7 +121,7 @@ public class RxLifecycleController extends RefWatchingController {
@OnClick(R.id.btn_next_release_view) void onNextWithReleaseClicked() {
setRetainViewMode(RetainViewMode.RELEASE_DETACH);
getRouter().pushController(RouterTransaction.builder(new TextController("Logcat should now report that the observables from onAttach() and onBindView() have been unsubscribed from, while the constructor observable is still running."))
getRouter().pushController(RouterTransaction.builder(new TextController("Logcat should now report that the observables from onAttach() and onViewBound() have been unsubscribed from, while the constructor observable is still running."))
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())
.build()
@@ -133,7 +131,7 @@ public class RxLifecycleController extends RefWatchingController {
@OnClick(R.id.btn_next_retain_view) void onNextWithRetainClicked() {
setRetainViewMode(RetainViewMode.RETAIN_DETACH);
getRouter().pushController(RouterTransaction.builder(new TextController("Logcat should now report that the observables from onAttach() has been unsubscribed from, while the constructor and onBindView() observables are still running."))
getRouter().pushController(RouterTransaction.builder(new TextController("Logcat should now report that the observables from onAttach() has been unsubscribed from, while the constructor and onViewBound() observables are still running."))
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())
.build()
@@ -70,8 +70,8 @@ public class TargetDisplayController extends RefWatchingController implements Ta
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
setTextView();
setImageView();
}
@@ -21,10 +21,15 @@ public class TargetTitleEntryController extends RefWatchingController {
@Bind(R.id.edit_text) EditText mEditText;
public <T extends Controller & TargetTitleEntryControllerListener> TargetTitleEntryController(T targetController) {
super.setTargetController(targetController);
}
public TargetTitleEntryController() { }
public TargetTitleEntryController(Controller targetController) {
setTargetController(targetController);
@Override
public void setTargetController(Controller target) {
throw new RuntimeException(getClass().getSimpleName() + "s can only have their target set through the constructor.");
}
@NonNull
@@ -33,15 +38,6 @@ public class TargetTitleEntryController extends RefWatchingController {
return inflater.inflate(R.layout.controller_target_title_entry, container, false);
}
@Override
public void onTargetControllerSet(Controller target) {
super.onTargetControllerSet(target);
if (!(target instanceof TargetTitleEntryControllerListener)) {
throw new RuntimeException(getClass().getSimpleName() + " target Controllers must implement the " + TargetTitleEntryControllerListener.class.getSimpleName() + " interface.");
}
}
@OnClick(R.id.btn_use_title) void optionPicked() {
Controller targetController = getTargetController();
if (targetController != null) {
@@ -37,8 +37,8 @@ public class TextController extends RefWatchingController {
}
@Override
public void onBindView(@NonNull View view) {
super.onBindView(view);
public void onViewBound(@NonNull View view) {
super.onViewBound(view);
mTextView.setText(getArgs().getString(KEY_TEXT));
}
@@ -80,8 +80,8 @@ public class TransitionDemoController extends RefWatchingController {
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
View bgView = ButterKnife.findById(view, R.id.bg_view);
if (mTransitionDemo.colorId != 0 && bgView != null) {
@@ -2,7 +2,9 @@ package com.bluelinelabs.conductor.demo.controllers.base;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bluelinelabs.conductor.rxlifecycle.RxController;
@@ -15,16 +17,23 @@ public abstract class ButterKnifeController extends RxController {
super(args);
}
protected abstract View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container);
@NonNull
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
View view = inflateView(inflater, container);
ButterKnife.bind(this, view);
onViewBound(view);
return view;
}
protected void onViewBound(@NonNull View view) { }
@Override
protected void onUnbindView(View view) {
super.onUnbindView(view);
protected void onDestroyView(View view) {
super.onDestroyView(view);
ButterKnife.unbind(this);
}
}
}
@@ -1,8 +1,6 @@
package com.bluelinelabs.conductor.demo.controllers.base;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import com.bluelinelabs.conductor.demo.DemoApplication;
@@ -13,20 +11,9 @@ public abstract class RefWatchingController extends ButterKnifeController {
super(args);
}
@Override
protected void onDetach(@NonNull View view) {
super.onDetach(view);
if (isDestroyed()) {
DemoApplication.refWatcher.watch(view);
}
}
@Override
public void onDestroy() {
if (getView() != null) {
DemoApplication.refWatcher.watch(getView());
}
super.onDestroy();
DemoApplication.refWatcher.watch(this);
}
+2 -2
View File
@@ -5,8 +5,8 @@ ext {
buildToolsVersion = '23.0.2'
versionCode = 1
versionName = '1.0.5'
publishedVersionName = '1.0.5'
versionName = '1.1.0'
publishedVersionName = '1.1.0'
supportV4 = 'com.android.support:support-v4:23.1.1'
supportDesign = 'com.android.support:design:23.1.1'
Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 103 KiB