Skip to content

Instantly share code, notes, and snippets.

View Kiolk's full-sized avatar
🏠
Working from home

Yauheni Slizh Kiolk

🏠
Working from home
View GitHub Profile
@Kiolk
Kiolk / CoroutineWithFlow.kt
Created October 4, 2020 20:48
Example coroutine with Flow
abstract class BaseFlowUseCase<out Type, in Params> {
abstract suspend fun execute(param: Params): Flow<Type>
}
override suspend fun getNumberInvites(): Flow<Int> {
return local.getNumberInvites()
}
override suspend fun getNumberInvites(): Flow<Int> {
@Kiolk
Kiolk / GoalDataSource.kt
Created October 4, 2020 20:02
Use coroutine outside viewModelScope
class GoalDataSource(private val getReactGoalsUseCase: GetReactGoalsUseCase) :
PositionalDataSource<Goal>() {
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Goal>) {
CoroutineScope(Dispatchers.Main).launch {
getReactGoalsUseCase.invoke(this, GetReactGoalsUseCase.Param(params.startPosition)) {
it.either({}, { goals: List<Goal> ->
callback.onResult(goals)
})
}
@Kiolk
Kiolk / BaseUseCase.kt
Last active October 4, 2020 19:56
Coroutines Example: Base UseCase with coroutine
abstract class BaseUseCase<in Param, out Type> where Type : Any {
abstract suspend fun run(param: Param): Either<Failure, Type>
open val dispatcher: CoroutineDispatcher = Dispatchers.Main
open operator fun invoke(
scope: CoroutineScope,
param: Param,
result: (Either<Failure, Type>) -> Unit = {}
@Kiolk
Kiolk / Example.kt
Last active July 31, 2020 06:20
Popup menu with icons
private fun showPopupMenu() {
val wrapper = ContextThemeWrapper(requireContext(), R.style.AppTheme)
val popup = PopupMenu(wrapper, ANCHOR_VIEW)
try {
val fields = popup::class.java.declaredFields
fields.forEach {
if ("mPopup" == it.name) {
it.isAccessible = true
val helper = it.get(popup)
@Kiolk
Kiolk / Linux_shell_command.txt
Last active May 20, 2020 20:51
Data notification with cURL
curl -X POST \
-H "Authorization: key=<SERVER_KEY>" \
-H "Content-Type: application/json" \
-d '{"to":"<DEVICE_ID>","collapse_key":"type_a","data":{"body":"Notification body","title":"Notification title","key1":"Your value","key2":"Your other value"}}' \
https://fcm.googleapis.com/fcm/send
@Kiolk
Kiolk / file1.txt
Created February 17, 2019 19:33
Created via API
Demo