Skip to content

Instantly share code, notes, and snippets.

abstract class IConfigProvider {
abstract fun getString(key: String): String
abstract fun getBoolean(key: String): Boolean
abstract fun getDouble(key: String): Double
abstract fun getLong(key: String): Long
abstract fun getInt(key: String): Int
inline fun <reified T> dataFromJson(data: String?): T? {
var configData: T? = null
try {
/**
* common remote config data source for configs used in more than 1 module
*/
class CommonRemoteConfigData(private val config: IConfigProvider) {
fun getListOfEnabledCities(): List<String>? {
return config.dataFromJson(
config.getString(
"SOMEKEY"
)
class ConfigProviderImpl(private val remoteConfig: FirebaseRemoteConfig) :
IConfigProvider() {
override fun getString(key: String): String {
return remoteConfig.getString(key)
}
override fun getBoolean(key: String): Boolean {
return remoteConfig.getBoolean(key)
}
//Naming Activities
class HomeActivity
class HomeScreen
class Home
//Interface naming conventions
interface IHolidaysRepository
private fun observeDataChange() {
holidayViewModel.holidays.observe(viewLifecycleOwner, {
when (it) {
is Resource.Error -> {}
is Resource.Loading -> {}
is Resource.Success -> {}
}
})
}
@manoj-mili
manoj-mili / PostAdapterGist.kt
Created August 9, 2020 19:04
Implementing Recyclerview Adapter with DiffCallBack
class PostAdapter :
ListAdapter<Post, PostAdapter.ViewHolder>(TaskDiffCallBack()) {
//This check runs on background thread
class TaskDiffCallBack : DiffUtil.ItemCallback<Post>() {
override fun areItemsTheSame(oldItem: Post, newItem: Post): Boolean {
Log.d(TAG,Thread.currentThread().name)
return oldItem.id == newItem.id;
}