Skip to content

Instantly share code, notes, and snippets.


JinHo Kang lagoJin

View GitHub Profile
View viewModelScope.kt
private const val JOB_KEY = "androidx.lifecycle.ViewModelCoroutineScope.JOB_KEY"
* [CoroutineScope] tied to this [ViewModel].
* This scope will be canceled when ViewModel will be cleared, i.e [ViewModel.onCleared] is called
* This scope is bound to [Dispatchers.Main]
val ViewModel.viewModelScope: CoroutineScope
get() {
View MainViewModel.kt
class MainViewModel @Inject constructor(
private val githubUseCase: GIthubUseCase) : BaseViewModel() {
private val _result = MutableLiveData<List<DomainEntityGithub>>()
val result: LiveData<List<DomainEntityGithub>>
get() = _result
fun search(query: String, page:Int, count :Int) {
githubUseCase.invoke(viewModelScope, GithubUseCase.Params(query, page, count),
View GithubUseCase.kt
class GithubUseCase constructor(
private val githubRepository: GithubRepository
) : BaseUseCase<GithubUseCase.Params, List<DomainEntityGithub>> {
data class Params(val userId: String, val page: Int, val perPage: Int)
override fun invoke(
scope: CoroutineScope,
params: Params,
onSuccess: (List<DomainEntityGithub>) -> Unit,
View GithubService.kt
interface GithubService {
suspend fun getSearchUsers(
@Query("q") q: String,
@Query("page") page: Int,
@Query("per_page") perPage: Int
): DataEntityGithub
View GithubRepositoryImple.kt
class GithubRepositoryImpl constructor(
private val githubService: GithubService,
private val githubMapper: GithubMapper
) : GithubRepository {
override suspend fun getGithubs(
userId: String,
page: Int,
perPage: Int
): List<DomainEntityGithub> {