Skip to content

Commit

Permalink
Modernize demo
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanenicolas committed Apr 28, 2016
1 parent 8432d84 commit df342b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class LessSimpleActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
scope = ToothPick.openScopes(getApplication(), this);
scope.installModules(new ActivityModule(this));
super.onCreate(savedInstanceState);
ToothPick.inject(this, scope);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class PersistActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
scope = ToothPick.openScopes(getApplication(), PRESENTER_SCOPE, this);
scope.installModules(new ActivityModule(this));
super.onCreate(savedInstanceState);
ToothPick.inject(this, scope);

setContentView(R.layout.simple_activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import com.example.smoothie.deps.RxPresenter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Inject;
import rx.Subscription;
import toothpick.Scope;
Expand All @@ -17,7 +21,7 @@

public class RxMVPActivity extends Activity {

public static final String PRESENTER_SCOPE = "PRESENTER_SCOPE";
public static final Class PRESENTER_SCOPE = Presenter.class;
private Scope scope;

@Inject RxPresenter rxPresenter;
Expand All @@ -28,11 +32,10 @@ public class RxMVPActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
scope = ToothPick.openScopes(getApplication(), PRESENTER_SCOPE, this);
scope.installModules(new ActivityModule(this));
super.onCreate(savedInstanceState);
ToothPick.inject(this, scope);
ToothPick.openScope(PRESENTER_SCOPE).installModules(new PresenterModule());

setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
Expand All @@ -57,9 +60,8 @@ public void onBackPressed() {
super.onBackPressed();
}

private class PresenterModule extends Module {
{
bind(RxPresenter.class).to(rxPresenter);
}
}
@javax.inject.Scope
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Presenter {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ public class SimpleActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Smoothie.openApplicationScope(getApplication(), <modules...>) no need to include application module
//.openActivityScope(this, <modules...>) no need to include activity module
//.inject(this) // all DSL scope state can inject
scope = ToothPick.openScopes(getApplication(), this);
scope.installModules(new ActivityModule(this));
super.onCreate(savedInstanceState);
ToothPick.inject(this, scope);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
Expand Down

0 comments on commit df342b7

Please sign in to comment.