All Projects → skydoves → Bundler

skydoves / Bundler

Licence: apache-2.0
🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Bundler

Inlineactivityresult
Receive the activity result directly after the startActivityForResult with InlineActivityResult
Stars: ✭ 264 (+35.38%)
Mutual labels:  intent, activity, fragment
Navigator
Android Multi-module navigator, trying to find a way to navigate into a modularized android project
Stars: ✭ 131 (-32.82%)
Mutual labels:  intent, activity, fragment
Webpack.js.org
Repository for webpack documentation and more!
Stars: ✭ 2,049 (+950.77%)
Mutual labels:  bundle, bundler
Viewtooltip
A fluent tooltip for Android
Stars: ✭ 1,029 (+427.69%)
Mutual labels:  activity, fragment
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+439.49%)
Mutual labels:  activity, fragment
intentanimation
animattion between activities
Stars: ✭ 117 (-40%)
Mutual labels:  intent, activity
macpack
Makes a macOS binary redistributable by searching the dependency tree and copying/patching non-system libraries.
Stars: ✭ 20 (-89.74%)
Mutual labels:  bundler, bundle
Bili
Bili makes it easier to bundle JavaScript libraries.
Stars: ✭ 949 (+386.67%)
Mutual labels:  bundle, bundler
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (-59.49%)
Mutual labels:  activity, fragment
Nexe
🎉 create a single executable out of your node.js apps
Stars: ✭ 10,565 (+5317.95%)
Mutual labels:  bundle, bundler
Tieguanyin
Activity Builder.
Stars: ✭ 113 (-42.05%)
Mutual labels:  activity, fragment
AppListManager
📱 AppListManager (Android Library) makes managing application and activity lists easy.
Stars: ✭ 59 (-69.74%)
Mutual labels:  intent, activity
solid
Solid Android components
Stars: ✭ 33 (-83.08%)
Mutual labels:  fragment, activity
Flow
Android wrapper to simplify process for start an Activity
Stars: ✭ 54 (-72.31%)
Mutual labels:  intent, activity
BindingExtension
Android ViewBinding extension to provide simpler usage in Activity, Fragment and ViewHolder.
Stars: ✭ 26 (-86.67%)
Mutual labels:  fragment, activity
navigator
Annotation processor that eliminates navigation and Bundle boilerplate
Stars: ✭ 13 (-93.33%)
Mutual labels:  bundle, activity
RxComponentLifecycle
Rx binding of new Android Architecture Component Lifecycle
Stars: ✭ 57 (-70.77%)
Mutual labels:  fragment, activity
My Android Garage
A quick reference guide for Android development.
Stars: ✭ 66 (-66.15%)
Mutual labels:  fragment, activity
Robin
Robin is a logging library for Bundle data passed between Activities and fragments. It also provides a callback to send screen views of user visited pages to your analytics client
Stars: ✭ 63 (-67.69%)
Mutual labels:  bundle, intent
Binding
Simple API implement DataBinding and ViewBinding. 简单的 API 实现 DataBinding 和 ViewBinding,欢迎 star
Stars: ✭ 169 (-13.33%)
Mutual labels:  activity, fragment

Bundler

License API Build Status Android Weekly KotlinWeekly Medium Javadoc

🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.

Including in your project

Maven Central Jitpack

Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
        mavenCentral()
    }
}

And add a dependency code to your module's build.gradle file.

dependencies {
    implementation "com.github.skydoves:bundler:1.0.4"
}

SNAPSHOT

Bundler
Snapshots of the current development version of Bundler are available, which track the latest versions.

repositories {
   maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

Usage

Intent

intentOf is an expression for creating an Intent using Kotlin DSL style and we can put extras using the putExtra method. Also, we can put extras using the + keyword in front of a key/value pair.

val intent = intentOf {
    putExtra("posterId", poster.id) // put a Long type 'posterId' value.
    putExtra("posterName" to poster.name) // put a String type 'posterName' value.
    putExtra("poster", poster) // put a Parcelable type 'poster' value.

    +("id" to userInfo.id) // put a Long type 'id' value.
    +("name" to userInfo.nickname) // put a String type 'name' value.
    
    -"name" // remove a String type 'name' value.
}

StartActivity

We can start activities using the intentOf expression like below.

intentOf<SecondActivity> {
    putExtra("id" to userInfo.id)
    putExtra("name" to userInfo.nickname)
    putExtra("poster", poster)
    startActivity(this@MainActivity)
}

We can also use other options for creating an intent.

intentOf {
    setAction(Intent.ACTION_MAIN)
    addCategory(Intent.CATEGORY_APP_MUSIC)
    setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    startActivity(this@MainActivity)
}

bundle

bundle is an expression for initializing lazily extra values from the intent.

class SecondActivity : AppCompatActivity() {

  private val id: Long by bundle("id", -1) // initializes a Long extra value lazily.
  private val name: String by bundle("name", "") // initializes a String extra value lazily.
  private val poster: Poster? by bundle("poster") // initializes a Parcelable extra value lazily.

  // -- stubs -- //

We can initialize a Parcelable value with a defaut value.

private val poster: Poster? by bundle("poster") { Poster.create() }

Also, we can initialize type of Array and ArrayList using bundleArray and bundleArrayList expression.

// initialize lazily without default values.
private val posterArray by bundleArray<Poster>("posterArray")
private val posterListArray by bundleArrayList<Poster>("posterArrayList")

or

// initialize lazily with default values.
private val posterArray by bundleArray<Poster>("posterArray") { arrayOf() }
private val posterListArray by bundleArrayList<Poster>("posterArrayList") { arrayListOf() }

bundle in Fragment

The below example shows setting arguments using the intentOf expression.

arguments = intentOf {
    +("id" to userInfo.id)
    +("name" to userInfo.nickname)
    +("poster" to poster)
}.extras

We can initialize argument values lazily in Fragments using the bundle expression like below.

- val id: Long = arguments?.getLong("id", -1) ?: -1
+ val id: Long by bundle("id", -1)
- val poster: Poster? = arguments?.getParcelable("poster")
+ val poster: Poster? by bundle("poster")

bundleNonNull

The bundle expression for initializing objects (e.g. Bundle, CharSequence, Parcelable, Serializable, Arrays), the property type must be null-able. But If we want to initialize them non-nullable type, we can initialize them to non-nullable type using the bundleNonNull expression.

- val poster: Poster? by bundle("poster")
+ val poster: Poster by bundleNotNull("poster")

observeBundle

We can observe the bundle data as LiveData using the observeBundle expression. If there are no extra & arguments in the Activity or Fragment, null will be passed to the observers. The observeBundle emits data only a single time to a single observer. So We can observe only once using one observer. And the observer will be unregistered from the LiveData after observing data at once.

private val id: LiveData<Long> by observeBundle("id", -1L)
private val poster: LiveData<Poster> by observeBundle("poster")

id.observe(this) {
  vm.id = it
}

poster.observe(this) {
  binding.name = it.name
}

bundleValue

We can also retrieve intent & arguments extra values from Activity and Fragment immediately. We can use bundleValue, bundleNonNullValue, bundleArrayValue, bundleArrayListValue.

val id = bundleValue("id", 100L)
val name = bundleValue("name", "")
val poster = bundleValue<Poster>("poster")

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐️
And follow me for my next creations! 🤩

License

Copyright 2020 skydoves (Jaewoong Eum)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].