Skip to content

Instantly share code, notes, and snippets.

@manoj-mili
manoj-mili / CancelSingleJobCorotuine.kt
Created December 14, 2021 04:43
Cancel Single job in Coroutine
coroutineScope.launch {
val job = coroutineScope.launch {
var counter = 0
while (true) {
counter++
println("Current Counter is $counter")
}
}
delay(1000)
println("Cancelling Job")
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 {
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)
}
/**
* 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"
)
private fun observeDataChange() {
holidayViewModel.holidays.observe(viewLifecycleOwner, {
when (it) {
is Resource.Error -> {}
is Resource.Loading -> {}
is Resource.Success -> {}
}
})
}
//Naming Activities
class HomeActivity
class HomeScreen
class Home
//Interface naming conventions
interface IHolidaysRepository