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

Clean up ViewController and remove final to attach() and detach() methods #57

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions scoop/src/main/java/com/lyft/scoop/ViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,10 @@ public abstract class ViewController {
private Scoop scoop;
private View view;

final void attach(View view) {
this.attached = true;
this.view = view;
onAttach();
}
protected abstract int layoutId();

public void onAttach() {}

protected final boolean attached() {
return this.attached;
}

final void detach(View view) {
onDetach();
this.view = null;
this.attached = false;
}

public void onDetach() {}

public View getView() {
Expand All @@ -35,20 +21,33 @@ public View getView() {
return this.view;
}

protected abstract int layoutId();
protected final boolean attached() {
return this.attached;
}

protected Scoop getScoop() {
return scoop;
}

void attach(View view) {
this.attached = true;
this.view = view;
onAttach();
}

void detach() {
onDetach();
this.view = null;
this.attached = false;
}

void setScoop(Scoop scoop) {
this.scoop = scoop;
}

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

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onViewAttachedToWindow(View v) {

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