Created
December 25, 2014 02:02
-
-
Save eccyan/2f36323cfea38d58dee2 to your computer and use it in GitHub Desktop.
Mortal で Activity を利用する場合の実装方法 ref: http://qiita.com/eccyan/items/58f0f3b6c8554c7bfd66
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.ClassCastException: mortar.MortarContextWrapper cannot be cast to | |
android.app.Activity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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