Skip to content

Instantly share code, notes, and snippets.

View BapNesS's full-sized avatar
🌱
Design, Develop, Distribute… always with music 🎶

Baptiste Carlier BapNesS

🌱
Design, Develop, Distribute… always with music 🎶
View GitHub Profile
@BapNesS
BapNesS / SyncViewModel.kt
Created June 9, 2021 17:24
Sample for suspend usage of Firebase Remote Config "fetchAndActivate()". Check the full sample for more informations: https://github.com/BapNesS/android-sample-firebaseremoteconfiguration/
class SyncViewModel : BaseViewModel() {
fun loadCacheFirebaseConfig() {
firebaseRemoteConfigInstance.apply {
RemoteConfigKey.values().forEach { key ->
getString(key.name)
.takeIf { it.isNotBlank() }
?.let { newValue ->
val remoteConfigData = RemoteConfigData(key, newValue)
LocalConfig.setData(remoteConfigData)
@BapNesS
BapNesS / KotlinToastextensions.kt
Created February 11, 2020 14:55
Extension method to show toast for Context.
/**
* Extension method to show toast for Context.
*/
fun Context?.toast(@StringRes textId: Int, duration: Int = Toast.LENGTH_SHORT) = this?.let { Toast.makeText(it, textId, duration).show() }
@BapNesS
BapNesS / UsableViewModel.kt
Created February 11, 2020 14:28
Easy way to Toast with ViewModel, LiveData & a bit of abstraction. 4/4
class UsableViewModel : BaseViewModel() {
fun load() {
setMessage(R.string.data_loaded)
}
fun reset() {
setMessage(R.string.data_reset)
}
@BapNesS
BapNesS / UsableActivity.kt
Created February 11, 2020 14:28
Easy way to Toast with ViewModel, LiveData & a bit of abstraction. 3/4
class UsableActivity : BaseActivity() {
private lateinit var viewModel: UsableViewModel
override val baseViewModel: BaseViewModel?
get() = viewModel
// DataBinding stuff
private lateinit var binding: ActivityUsableBinding
override fun onCreate(savedInstanceState: Bundle?) {
@BapNesS
BapNesS / BaseViewModel.kt
Created February 11, 2020 14:27
Easy way to Toast with ViewModel, LiveData & a bit of abstraction. 2/4
/**
* Base for other ViewModel
*/
abstract class BaseViewModel: ViewModel() {
// Mutable/LiveData of String resource reference Event
private val _message = MutableLiveData<Event<Int>>()
val message : LiveData<Event<Int>>
get() = _message
@BapNesS
BapNesS / BaseActivity.kt
Created February 11, 2020 14:27
Easy way to Toast with ViewModel, LiveData & a bit of abstraction. 1/4
/**
* Base for other activities
*/
abstract class BaseActivity : AppCompatActivity() {
abstract val baseViewModel: BaseViewModel?
// Get a ViewModel that is a BaseViewModel
protected inline fun <reified T : BaseViewModel> provideViewModel(): T = ViewModelProviders.of(this)[T::class.java]
@BapNesS
BapNesS / designer.html
Created August 7, 2014 12:01
designer
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;