This file contains 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
//Naming Activities | |
class HomeActivity | |
class HomeScreen | |
class Home | |
//Interface naming conventions | |
interface IHolidaysRepository |
This file contains 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
private fun observeDataChange() { | |
holidayViewModel.holidays.observe(viewLifecycleOwner, { | |
when (it) { | |
is Resource.Error -> {} | |
is Resource.Loading -> {} | |
is Resource.Success -> {} | |
} | |
}) | |
} |
This file contains 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
/** | |
* 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" | |
) |
This file contains 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 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) | |
} |
This file contains 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
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 { |
This file contains 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
coroutineScope.launch { | |
val job = coroutineScope.launch { | |
var counter = 0 | |
while (true) { | |
counter++ | |
println("Current Counter is $counter") | |
} | |
} | |
delay(1000) | |
println("Cancelling Job") |
This file contains 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
//Helper class which hides the library and exposes only required functionality | |
class ImageLoader { | |
fun setImageFromUrl(url: String, imageView: SomeViewHolder) { | |
// Do your Picasso or what ever library related stuff here | |
Picasso.get().load(url).into(imageView) | |
} | |
} | |
class SomeScreen { |
This file contains 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
// Don't pass too many arguments | |
fun saveUserDetails( | |
firstName: String, | |
lastName: String, | |
phoneNumber: String, | |
gender: String, | |
age: Int | |
) {} | |
// Do create a type and pass it as function param |
This file contains 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
//Don't add validation in this function as the name of the function only suggest to add it to db | |
fun savePhoneNumber(phoneNumber: String) { | |
if (!phoneNumber.equals("") && phoneNumber.length == 10 && phoneNumber regex check and etc...) { | |
dao.saveNumber(phoneNumber) | |
} | |
} | |
//Do only pass numbers post validation | |
fun savePhoneNumber(phoneNumber: String) { | |
dao.saveNumber(phoneNumber) |
This file contains 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
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
//to access data from list we have getItem(position) and no need to implement | |
val task = getItem(position) | |
holder.tvDesc.text = task.body | |
holder.tvTitle.text = task.title | |
} | |
//Also no need to implement getItemCount() |
NewerOlder