Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #67 from lyft/scoop-vc-bind-fix
Browse files Browse the repository at this point in the history
Adding butterknife bind logic into vc
  • Loading branch information
itspbj committed May 3, 2016
2 parents 6f2cb31 + eb46592 commit c1c17ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 7 additions & 1 deletion scoop/src/main/java/com/lyft/scoop/ViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

public abstract class ViewController {

static final int VIEW_CONTROLLER_TAG = 0x80000001;

private boolean isDetaching = false;
private boolean attached;
private Scoop scoop;
private View view;

final void attach(View view) {
this.view = view;
Scoop.viewBinder.bind(this, view);
view.setTag(VIEW_CONTROLLER_TAG, this);
onAttach();
this.attached = true;
if (this.isDetaching) {
Expand All @@ -28,6 +32,8 @@ final void detach(View view) {
this.isDetaching = true;
if(this.attached) {
onDetach();
view.setTag(VIEW_CONTROLLER_TAG, null);
Scoop.viewBinder.unbind(this);
this.view = null;
this.attached = false;
this.isDetaching = false;
Expand Down Expand Up @@ -55,7 +61,7 @@ void setScoop(Scoop scoop) {

static ViewController fromView(View view) {
if (view != null) {
ViewController viewController = (ViewController) view.getTag(ViewControllerInflater.VIEW_CONTROLLER_TAG);
ViewController viewController = (ViewController) view.getTag(VIEW_CONTROLLER_TAG);
return viewController;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

public class ViewControllerInflater {

static final int VIEW_CONTROLLER_TAG = 0x80000001;

protected ViewController createViewController(Scoop scoop, Class<? extends ViewController> clazz) {
try {
return clazz.newInstance();
Expand All @@ -32,16 +30,13 @@ private static void bindViewControllerToView(final View view, final ViewControll
final View.OnAttachStateChangeListener viewAttachListener = new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
Scoop.viewBinder.bind(viewController, v);
viewController.attach(view);
view.setTag(VIEW_CONTROLLER_TAG, viewController);

}

@Override
public void onViewDetachedFromWindow(View v) {
viewController.detach(view);
view.setTag(VIEW_CONTROLLER_TAG, null);
Scoop.viewBinder.unbind(viewController);
}
};

Expand Down

0 comments on commit c1c17ef

Please sign in to comment.