Last active
December 8, 2019 05:49
-
-
Save HarryTylenol/bc59cce222e9067a92c05e1a96aaf327 to your computer and use it in GitHub Desktop.
This file contains 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
fun <T> intentExtra(defaultValue: T? = null) = object : ReadOnlyProperty<Activity, T?> { | |
override fun getValue(thisRef: Activity, property: KProperty<*>): T? { | |
return when (defaultValue) { | |
is String -> thisRef.intent.getStringExtra(property.name) as T | |
is Int -> thisRef.intent.getIntExtra(property.name, defaultValue) as T | |
is Long -> thisRef.intent.getLongExtra(property.name, defaultValue) as T | |
// And More... | |
else -> null | |
} | |
} | |
} |
This file contains 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 FestivalActivity : BaseActivity<ActvFestivalBinding, FestivalViewModel>() { | |
object FestivalDeepLinkIntents : DeeplinkActivityIntents { | |
@JvmStatic | |
@CommonUrlDeepLink("festivals/{extraId}") | |
fun intentForDeepLinkMethod(context: Context) = | |
createTaskBuilder(context, | |
Intent(context, MainActivity::class.java), | |
Intent(context, FestivalActivity::class.java) | |
) | |
} | |
override val viewModel: FestivalViewModel by viewModel() | |
override val layoutResId: Int = R.layout.actv_festival | |
private val extraId by intentExtra<String>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
loadKoinModules(FestivalModuleRepository.modules) | |
super.onCreate(savedInstanceState) | |
setupToolbar(binding.toolbar, true) | |
binding.viewModel = viewModel | |
extraId?.let(viewModel::requestFestival) ?: finish() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment