Skip to content

Releases: skydoves/lazybones

1.0.4

01 Feb 05:32
3136cf0
Compare
Choose a tag to compare

馃帀 Released a new version 1.0.4! 馃帀

What's Changed

  • Added Proguard Rules for lazybones-viewmodel by @skydoves in #6

Full Changelog: 1.0.3...1.0.4

1.0.3

31 Jan 06:36
a7c4513
Compare
Choose a tag to compare

馃帀 A new version 1.0.3 has been released! 馃帀

Introduce

Now Lazybones supports lifecycleAware for Jetpack ViewModel to track and observe the lifecycle changes of the ViewModel. Basically, Lazybones-ViewModel allows you to observe two lifecycle changes: Initialize and Clear.

class MyViewModel : ViewModel() {

  private val lifecycleAwareCompositeDisposable = lifecycleAware { CompositeDisposable() }
    .onInitialize {
      Log.d(TAG, "ViewModel is initialized")
    }.onClear {
      Log.d(TAG, "ViewModel is cleared")
      dispose() // dispose CompositeDisposable when viewModel is getting cleared
    }
}

What's Changed

Full Changelog: 1.0.2...1.0.3

1.0.2

19 Apr 12:03
Compare
Choose a tag to compare

馃帀 Released a new version 1.0.2! 馃帀

Coroutines and Flow

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

dependencies {
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$versions.lifecycle" // over the 2.4.0-alpha01
}

We can apply to the coroutines lifecycleScope for launching suspend functions. The Lifecycle-runtime-ktx supports launchWhenStarted, launchWhenCreated, and launchWhenResumed for the lifecycleScope. However those coroutines jobs will not be canceled automatically, so they must be canceled on a specific lifecycle. And we can declare canceling together with initialization like the below.

private val job: Job by lifecycleAware {
    lifecycleScope.launchWhenCreated {
      // call suspend
    }
  }.onDestroy {
    cancel() // cancel when the lifecycle is destroyed.
  }.lazy()

We can reduce the above codes like the below using the launchOnStarted, launchOnCreated, and launchOnResume.

private val job: Job by launchOnStarted {
    // call suspend
  }.onDestroy {
    cancel()
  }.lazy()

If we need to collect one flow on the coroutines lifecycle scope, we can use like the below.

private val job: Job by launchOnStarted(repository.fetchesDataFlow()) {
    // collected value from the repository.fetchesDataFlow()
  }.onDestroy {
    cancel()
  }.lazy()

addOnRepeatingJob

The addRepeatingJob extension has been added in the new version of the Lifecycle-runtime-ktx.

Launches and runs the given block in a coroutine when this LifecycleOwner's Lifecycle is at least at state. The launched coroutine will be canceled when the lifecycle state falls below the state.

We can collect a flow on the coroutines lifecycle scope and cancel it automatically if the lifecycle falls below that state, and will restart if it's in that state again.

private val job: Job by addOnRepeatingJob(Lifecycle.State.CREATED, simpleFlow()) {
    // collected value from the fetchesDataFlow()
  }.lazy()

1.0.1

10 Jan 18:01
2fddd8c
Compare
Choose a tag to compare

Released version 1.0.1.

  • The lifecycle related to lifecycleAware functionalities receives the parameter as applied.
    So we can omit the it receiver.
Before
private val balloon: Balloon by lifecycleAware { BalloonUtils.getProfileBalloon(baseContext) }
    .onCreate { it.showAlignTop(button) }
    .onDestroy { it.dismiss() }
    .lazy()
After
private val balloon: Balloon by lifecycleAware { BalloonUtils.getProfileBalloon(baseContext) }
    .onCreate { showAlignTop(button) }
    .onDestroy { dismiss() }
    .lazy()
  • Implemented LifecycleAwareProperty's kotlin dsl way for observing.
private val lifecycleAwareProperty = lifecycleAware(getDarkThemeDialog())
    .observe {
      onCreate { show() }
      onResume { restart() }
      onDestroy { dismiss() }
    }

1.0.0

09 Jan 16:19
9f96fe3
Compare
Choose a tag to compare

Published the first version 1.0.0.