Git Product home page Git Product logo

kbundle's Introduction

License This project is licensed under Apache 2.0 license.

kBundle (ANDROID)

Android CI Maven Central

Better, type safe version of creating bundle.

Gradle

implementation "sk.32bit:kbundle:0.2.0"

Usage

Bundle creation

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"
}

Persistable bundle creation

val persistableBundle = persistableBundle(existingBundle) {
  "IntKey" to 4
  "LongKey" to 7L
  "StringKey" to "Some text"
}

Fragment with bundle arguments

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
      }
    }
  }
}

Code Formatting

./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.

Check if Dependencies Are Up-to-Date

./gradlew dependencyUpdates

Settings can be tweaked for this plugin within gradle/versions_plugin_config.gradle.

Publishing the Library to Bintray -> jCenter

This repository is setup to automatically publish to Bintray when you create a new release from GitHub.

But there are some pre-requisites:

  1. Update library_info.gradle to contain your library's information (group, description, etc.).
  2. From your GitHub repository settings, add secrets for BINTRAY_ORG, BINTRAY_USER, and BINTRAY_API_KEY. These will be used by the Bintray Release GitHub Actions workflow.
  3. With each release, update the version name and code in library_info.gradle.
  4. 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?

  1. Automatically when you create a Release in your GitHub repository.
  2. OR if you set the three environment variables mentioned above, and invoke ./gradlew bintrayUpload.

kbundle's People

Contributors

hanibalsk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.