11package com.milad.githoob.ui.profile.repositories.project
22
3- import androidx.lifecycle.LiveData
4- import androidx.lifecycle.MutableLiveData
5- import androidx.lifecycle.ViewModel
6- import androidx.lifecycle.viewModelScope
3+ import android.util.Log
4+ import androidx.lifecycle.*
75import com.milad.githoob.data.MainRepository
86import com.milad.githoob.data.model.event.Contributor
97import com.milad.githoob.data.model.event.Repo
8+ import com.milad.githoob.utils.GlobalState.TAG
109import com.milad.githoob.utils.Status
1110import dagger.hilt.android.lifecycle.HiltViewModel
1211import kotlinx.coroutines.CoroutineDispatcher
@@ -20,20 +19,32 @@ class ProfileProjectViewModel @Inject constructor(
2019 private val mainRepository : MainRepository ,
2120 private val ioDispatcher : CoroutineDispatcher
2221) : ViewModel() {
22+ private lateinit var userId: String
2323 private val _repo = MutableLiveData <Repo >()
2424 val repo: LiveData <Repo > = _repo
2525
2626 private val _contributors = MutableLiveData <List <Contributor >>()
27- val contributors: LiveData <List <Contributor >> = _contributors
27+ val contributors: LiveData <List <Contributor >> = Transformations .switchMap(_contributors ) {
28+ it.forEach { item -> Log .d(TAG , item.toString()) }
29+ val readme = MutableLiveData <List <Contributor >>()
30+ if (it.size == 1 && it.first().login == userId){
31+ readme.postValue(emptyList<Contributor >())
32+ }else
33+ readme.postValue(it)
34+
35+ return @switchMap readme
36+ }
2837
2938 private val _markdown = MutableLiveData <String >(" " )
3039 val markdown: LiveData <String > = _markdown
3140
3241 private val _dataLoading = MutableLiveData (true )
3342 val dataLoading: LiveData <Boolean > = _dataLoading
3443
35- fun setUser (token : String? , userId : String , projectName : String ) =
44+ fun setUser (token : String? , userId : String , projectName : String ) {
45+ this .userId = userId;
3646 loadProjectData(token, userId, projectName)
47+ }
3748
3849 private fun loadProjectData (token : String? , userId : String , projectName : String ) {
3950 viewModelScope.launch(ioDispatcher) {
0 commit comments