Compare commits

...

3 Commits

Author SHA1 Message Date
Eric Kuck 511c229364 Fixed issue with re-attaching when the host Activity never left with window 2016-04-04 23:23:01 -05:00
Eric Kuck b5d0e46740 Now enforces only setting a controller's target one time. 2016-04-04 17:45:29 -05:00
Eric Kuck 8f1be7fe21 Updated readme to reflect latest lifecycle updates 2016-04-04 17:29:22 -05:00
4 changed files with 33 additions and 21 deletions
+8 -13
View File
@@ -14,7 +14,7 @@ A small, yet full-featured framework that allows building View-based Android app
:floppy_disk: | State persistence
:phone: | Callbacks for onActivityResult, onRequestPermissionsResult, etc
:european_post_office: | MVP / MVVM / VIPER / MVC ready
Conductor is architecture-agnostic and does not try to force any design decisions on the developer. We here at BlueLine Labs tend to use either MVP or MVVM, but it would work equally well with standard MVC or whatever else you want to throw at it.
## Installation
@@ -53,9 +53,9 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewGroup container = (ViewGroup)findViewById(R.id.controller_container)
ViewGroup container = (ViewGroup)findViewById(R.id.controller_container)
mRouter = Conductor.attachRouter(this, container, savedInstanceState);
if (!mRouter.hasRootController()) {
mRouter.setRoot(new HomeController());
@@ -78,15 +78,10 @@ public class MainActivity extends Activity {
public class HomeController extends Controller {
@Override
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
return inflater.inflate(R.layout.controller_home, container, false);
}
@Override
public void onBindView(@NonNull View view) {
super.onBindView(view);
((TextView)view.findViewById(R.id.tv_title)).setText("Hello World");
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
View view = inflater.inflate(R.layout.controller_home, container, false);
((TextView)view.findViewById(R.id.tv_title)).setText("Hello World");
return view;
}
}
@@ -12,7 +12,7 @@ import com.bluelinelabs.conductor.internal.LifecycleHandler;
*/
public final class Conductor {
private Conductor(){}
private Conductor() {}
/**
* Conductor will create a {@link Router} that has been initialized for your Activity and containing ViewGroup.
@@ -53,6 +53,7 @@ public abstract class Controller {
private boolean mIsBeingDestroyed;
private boolean mDestroyed;
private boolean mAttached;
private boolean mViewIsAttached;
private Router mRouter;
private View mView;
private Controller mParentController;
@@ -278,6 +279,10 @@ public abstract class Controller {
* @param target The Controller that is the target of this one.
*/
public void setTargetController(Controller target) {
if (mTargetInstanceId != null) {
throw new RuntimeException("Target controller already set. A controller's target may only be set once.");
}
mTargetInstanceId = target != null ? target.getInstanceId() : null;
}
@@ -586,6 +591,10 @@ public abstract class Controller {
}
final void activityResumed(Activity activity) {
if (!mAttached && mView != null && mViewIsAttached) {
attach(mView);
}
onActivityResumed(activity);
for (ChildControllerTransaction child : mChildControllers) {
@@ -640,7 +649,9 @@ public abstract class Controller {
}
}
private void detach(@NonNull View view) {
private void detach(@NonNull View view, boolean allowViewRefRemoval) {
final boolean removeViewRef = allowViewRefRemoval && (mRetainViewMode == RetainViewMode.RELEASE_DETACH || mIsBeingDestroyed);
if (mAttached) {
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.preDetach(this, view);
@@ -656,13 +667,15 @@ public abstract class Controller {
}
}
if (mRetainViewMode == RetainViewMode.RELEASE_DETACH || mIsBeingDestroyed) {
if (removeViewRef) {
removeViewReference();
}
for (LifecycleListener lifecycleListener : mLifecycleListeners) {
lifecycleListener.postDetach(this, view);
}
} else if (removeViewRef) {
removeViewReference();
}
}
@@ -703,12 +716,16 @@ public abstract class Controller {
mView.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
if (v == mView) {
mViewIsAttached = true;
}
attach(v);
}
@Override
public void onViewDetachedFromWindow(View v) {
detach(v);
mViewIsAttached = false;
detach(v, true);
}
});
@@ -750,7 +767,7 @@ public abstract class Controller {
if (!mAttached) {
removeViewReference();
} else if (removeViews) {
detach(mView);
detach(mView, true);
}
}
@@ -787,7 +804,7 @@ public abstract class Controller {
final Bundle detachAndSaveInstanceState() {
if (mAttached && mView != null) {
detach(mView);
detach(mView, mIsBeingDestroyed);
}
Bundle outState = new Bundle();
+2 -2
View File
@@ -5,8 +5,8 @@ ext {
buildToolsVersion = '23.0.2'
versionCode = 1
versionName = '1.1.0'
publishedVersionName = '1.1.0'
versionName = '1.1.1'
publishedVersionName = '1.1.1'
supportV4 = 'com.android.support:support-v4:23.1.1'
supportDesign = 'com.android.support:design:23.1.1'