Android library to simplify passing params to activities and fragments (currently it's working only with the androidx fragments).
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.cregus:android-params:1.1'
}
class UserActivity : AppCompatActivity() {
companion object : ActivityParams<UserActivity, Long> by activityParams()
private val id by loadParams()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("Params", "id: $id")
}
}
and then:
val intent = UserActivity.createIntent(context, 1)
class UserFragment : Fragment() {
companion object : FragmentParams<UserFragment, Long> by fragmentParams()
private val id by loadParams(0)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("Params", "id: $id")
}
}
and then:
val fragment = UserFragment.newInstance(1)
class UserFragment : Fragment() {
@Parcelize
data class Params(val id: Long, val name: String) : Parcelable
companion object : FragmentParams<UserFragment, Params> by fragmentParams()
private val params by loadParams()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("Params", "id: ${params.id}, name: ${params.name}")
}
}
and then:
val fragment = UserFragment.newInstance(UserFragment.Params(1, "John Smith"))