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
internal suspend fun <T> runCatchingNetworkException(block: suspend () -> T): T { | |
return try { | |
block() | |
} catch (e: HttpException) { | |
val response = e.response() | |
throw NetworkException( | |
response?.code(), | |
response?.message(), | |
response?.errorBody()?.charStream()?.readText()?.replace("\"", "") | |
) |
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
/** | |
* To prevent the device to put in sleep after a period of the time | |
* | |
* @param enablePreventSleep ON/OFF prevent sleep | |
*/ | |
internal fun FragmentActivity.setPreventSleep(enablePreventSleep: Boolean) { | |
if (enablePreventSleep) { | |
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) | |
} else { | |
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
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
root = true | |
[*] | |
charset = utf-8 | |
end_of_line = crlf | |
indent_size = 4 | |
indent_style = space | |
insert_final_newline = true | |
max_line_length = 100 | |
tab_width = 4 |
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
/** | |
* To use delegate property from map, getting value from a snakeCase key | |
* | |
* eg.: | |
* ```kotlin | |
* val myMap = mapOf("hello_world" to "Some Value") | |
* val helloWorld: String by myMap.fromSnakeCase() | |
* ``` | |
* | |
* So, the val "helloWorld" will contain "Some Value" |