• Stars
    star
    354
  • Rank 120,042 (Top 3 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This library holds a class to handle single live events in Android MVVM architectural pattern. https://proandroiddev.com/livedata-with-single-events-2395dea972a8

Health Check Maven Central

Live Event

This library holds a class to handle single live events in Android MVVM architectural pattern. This class is extended form LiveData class, from androidx.lifecycle:lifecycle-extensions library, to propagate the data as an event, which means it emits data just once, not after configuration changes again. Note that event will only be sent to active observers, any observers that started observing after the emit won't be notified of the event.

Usage

This source has a sample app where you can find LiveEventViewModel in it, in which the LiveEvent class is used as follows.

class LiveEventViewModel : ViewModel() {
    private val clickedState = LiveEvent<String>()
    val state: LiveData<String> = clickedState

    fun clicked() {
        clickedState.value = ...
    }
}

LiveEventConfig

There are two behaviours of LiveEvent in-demand. First one is LiveEventConfig.Normal, where supports multi-observers on all cases the same. This config was originally implemented for this library so it's the default config, but if you want to be explicit, you can pass it to the constructor of LiveEvent.

The second config is LiveEventConfig.PreferFirstObserver. This one is useful when you want to emit an event in the init method of ViewModel and expect the first observer receive it. To set it up you need to pass it to the constructor

private val clickedState = LiveEvent<String>(config = LiveEventConfig.PreferFirstObserver)

Download

Download via gradle

implementation "com.github.hadilq:live-event:$libVersion"

where you can find the libVersion in the Releases page of this repository.

Snapshots of the development version are available in Sonatype's snapshots repository.

Contribution

Just create your branch from the master branch, change it, write additional tests, satisfy all tests, create your pull request, thank you, you're awesome.

More Repositories

1

molecule-sample-app

This is a sample app to use [Molecule library](https://github.com/cashapp/molecule) and solve some scoping problems in Android development.
Kotlin
37
star
2

CleanArchitecture

A sample app for clean architecture.
Kotlin
35
star
3

rust-flutter-reactive

This is a sample app to improve consistency over Mobile App Development.
Rust
35
star
4

youtube-app

This is a sample Android app. The main goal of this project is to provide a full implementation for a No-Framework Dependency Injection in Kotlin.
Kotlin
13
star
5

happy

This library provides an annotation to auto-generate a Kotlin DSL for `sealed` classes to make working with them more concise. You can find more in https://hadilq.com/posts/happy-railway/
Kotlin
10
star
6

java-persian-calendar

Java
9
star
7

RxLifecycleHandler

A glue between the lifecycle of LifecycleOwner in Android and upstreams in RxJava.
Kotlin
9
star
8

trackable-compiler-plugin

A Kotlin compiler plugin that generates trackable method
Kotlin
9
star
9

log4k

This is a simple library for logging in Kotlin. https://proandroiddev.com/logging-in-kotlin-8ecfb97a4840
Kotlin
7
star
10

nixos-configuration

My NixOS configuration
Nix
6
star
11

Mastan

A Mastodon Client
Kotlin
3
star
12

CommandKU

Yet another message queue
Kotlin
2
star
13

cv-english

This is my resume
TeX
2
star
14

CoroutineLifecycleHandler

A glue between the lifecycle of LifecycleOwner in Android and Flow upstream of Kotlin Coroutines.
Kotlin
2
star
15

num4k

Modularized, mathematical and multiplatform Kotlin library
Kotlin
1
star
16

persian-calendar-important-functions

Python
1
star
17

HobbyTaste

Just a hobby android project
Java
1
star