This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsableViewModel : BaseViewModel() { | |
fun load() { | |
setMessage(R.string.data_loaded) | |
} | |
fun reset() { | |
setMessage(R.string.data_reset) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../components/polymer/polymer.html"> | |
<polymer-element name="my-element"> | |
<template> | |
<style> | |
:host { | |
position: absolute; | |
width: 100%; | |
height: 100%; |