Skip to content

Instantly share code, notes, and snippets.

@eccyan
Created December 25, 2014 02:02
Show Gist options
  • Save eccyan/2f36323cfea38d58dee2 to your computer and use it in GitHub Desktop.
Save eccyan/2f36323cfea38d58dee2 to your computer and use it in GitHub Desktop.
Mortal で Activity を利用する場合の実装方法 ref: http://qiita.com/eccyan/items/58f0f3b6c8554c7bfd66
java.lang.ClassCastException: mortar.MortarContextWrapper cannot be cast to
android.app.Activity
class WindowOwner extends Presenter<WindowOwner.Activity> {
interface Activity {
void addFragsToWindow(int flags);
}
public static class Config() {
final private int flags;
Config(int flags) { this.flags = flags; }
public int getFlags() { return this.flags; }
}
private Config config;
public void setConfig(Config config) {
this.config = config;
update();
}
private void update() {
WindowOwner.Activity activity = getView();
if (activity != null) {
activity.addFlagsToWindow(config.getFlags());
}
}
@dagger.Module(injects = {}, library = true)
public static class WindowOwnerModule {
@Provides
@Singleton
WindowOwner provideWindowOwnerPersenter() { return new WindowOwner(); }
}
}
class AwesomeActivity extends Activity implements WindowOwner.Activity {
@Inject WindowOwner windowOwner;
@Override
protected void onCreate(Bundle savedInstanceState) {
Mortar.inject(this, this);
this.windowOwner.takeView(this);
}
@Override
void addFragsToWindow(int flags) {
getWindow().addFlags(flags);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment