Skip to content

Instantly share code, notes, and snippets.

@mataku
Last active July 11, 2019 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mataku/83334303f234fbe9047aa74682c8ed2b to your computer and use it in GitHub Desktop.
Save mataku/83334303f234fbe9047aa74682c8ed2b to your computer and use it in GitHub Desktop.
マルチモジュール構成での画面クラス名の名前解決
// startActivity(ActivityList.Main.toIntent()) で遷移
object ActivityList {
const val BASE_PACKAGE_NAME = "com.mataku.amazing"
object Main : MatakuActivity {
override val className: String
get() = "$BASE_PACKAGE_NAME.app.ui.activity.MainActivity"
}
interface MatakuActivity {
val className: String
}
fun packageName(debuggable: Boolean): String {
return if (debuggable) {
"$BASE_PACKAGE_NAME.app.dev"
} else {
"$BASE_PACKAGE_NAME.app"
}
}
}
fun ActivityList.MatakuActivity.toIntent(): Intent {
return Intent(Intent.ACTION_VIEW).setClassName(
ActivityList.packageName(BuildConfig.DEBUG),
this.className
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment