Skip to content

A simple library to handle UI events based on Android LiveData architecture library

License

Notifications You must be signed in to change notification settings

HossainCo/LiveEvent

Repository files navigation

Android LiveEvent Library

License: MIT

pipeline status coverage report Build Status Coverage Status

Github All Releases

This is a simple library to handle UI events based on Android LiveData architecture library.

If observer is passed then: If lifecycleOwner is not passed or null it use observeForever(observer) insteadof observe(lifecycleOwner, observer).

How to use

Usage

// Simple create a SingleLiveEvent<String>
val event by liveEvent<String>

// Also register an default|first Observer
val event by liveEvent<String>(lifecycleOwner) { value ->
	Logger.e('test', value)
}

// lifecycleOwner parameter automaticly use in AppCompat activities !
// else if lifecycleOwner does not send then it observes for ever !!
val event by liveEvent { value: Boolean ->
	Logger.e('test', "check: $value")
}

// Use another LiveEvent types
val event by liveEvent<String>(clazz= OneShotLiveEvent::class)

// specify event class (default is SingleLiveEvent)
val event by liveEvent<String>(lifecycleOwner, OneShotLiveEvent::class) {
	// actions
}

// from google samples Handles only one observer
val event : LiveEvent<String> = SingleLiveEvent()
 
// from QAs Handles only one observer (not recommended)
val event : LiveEvent<String> = MutableLiveEvent()
 
// from QAs Handles many observers
val event : LiveEvent<String> = OneShotLiveEvent()

Observe

event.observe(lifecycleOwner, Observer {
	// actions on event
})

Gradle

// in root project
allprojects {
	repositories {
		// ...
		maven { url 'https://jitpack.io' }
	}
}
 
// in project
dependencies {
	compile 'com.github.HossainCo:LiveEvent:1.0.0-alpha4'
	// ...
}

License

MIT License
 
Copyright (c) 2017 HossainCo
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A simple library to handle UI events based on Android LiveData architecture library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published