License This project is licensed under Apache 2.0 license.
Better, type safe version of creating bundle.
implementation "sk.32bit:kbundle:0.2.0"
val bundle = bundle {
"IntKey" to 4
"LongKey" to 7L
"StringKey" to "Some text"
putAll(existingBundle) // Adds values from existing bundle
}
val bundle = bundle(existingBundle) {
"IntKey" to 4
"LongKey" to 7L
"StringKey" to "Some text"
}
val persistableBundle = persistableBundle(existingBundle) {
"IntKey" to 4
"LongKey" to 7L
"StringKey" to "Some text"
}
class CustomFragment : Fragment() {
private val intParameter by requireArgument<Int>()
private val stringWithDefaultParameter by requireArgument<String>("default text")
private var longOptionalParameter by instanceArgument<Long>()
// Error throw, when missing
private val parcelableParameter by requireArgument<Rect>("parcelableParameter parameter is required")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
println("intParameter is $intParameter")
println("stringWithDefaultParameter is $stringWithDefaultParameter")
println("longOptionalParameter is $longOptionalParameter")
println("parcelableParameter is $parcelableParameter")
// Parameter can be changed
longOptionalParameter = 22L
}
companion object {
fun newInstance(
intParameter: Int,
stringWithDefaultParameter: String,
parcelableParameter: Rect,
longOptionalParameter: Long? = null,
) = CustomFragment().also { fragment ->
fragment.arguments = bundle {
fragment::intParameter.name to intParameter
fragment::stringWithDefaultParameter.name to stringWithDefaultParameter
fragment::longOptionalParameter.name to longOptionalParameter
fragment::parcelableParameter.name to parcelableParameter
}
}
}
}
./gradlew spotlessApply
Make sure you update spotless.license.kt and LICENSE.md to reflect your own license and author info! Other settings for this plugin can be tweaked in gradle/spotless_plugin_config.gradle.
./gradlew dependencyUpdates
Settings can be tweaked for this plugin within gradle/versions_plugin_config.gradle.
This repository is setup to automatically publish to Bintray when you create a new release from GitHub.
But there are some pre-requisites:
- Update library_info.gradle to contain your library's information (group, description, etc.).
- From your GitHub repository settings, add secrets for
BINTRAY_ORG
,BINTRAY_USER
, andBINTRAY_API_KEY
. These will be used by theBintray Release
GitHub Actions workflow. - With each release, update the version name and code in library_info.gradle.
- Once you've deployed to Bintray for the first time, you can link your Bintray repository to jCenter so people can depend on your library from Android projects without having to add any special Maven repositories.
How does releasing work?
- Automatically when you create a Release in your GitHub repository.
- OR if you set the three environment variables mentioned above, and invoke
./gradlew bintrayUpload
.