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 GithubRepositoryImpl constructor( | |
private val githubService: GithubService, | |
private val githubMapper: GithubMapper | |
) : GithubRepository { | |
override suspend fun getGithubs( | |
userId: String, | |
page: Int, | |
perPage: Int | |
): List<DomainEntityGithub> { |
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
interface GithubService { | |
@GET("search/users") | |
suspend fun getSearchUsers( | |
@Query("q") q: String, | |
@Query("page") page: Int, | |
@Query("per_page") perPage: Int | |
): DataEntityGithub | |
} |
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 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, |
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 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) { | |
_dataLoading.postValue(true) | |
githubUseCase.invoke(viewModelScope, GithubUseCase.Params(query, page, count), |
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 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() { |