Skip to content

Commit 74648f7

Browse files
author
Targholi
committed
check user contributor, if size is 1 and name is like current user set contributor view to gone.
1 parent 419c809 commit 74648f7

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

app/src/main/java/com/milad/githoob/ui/profile/repositories/project/ProfileProjectViewModel.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package 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.*
75
import com.milad.githoob.data.MainRepository
86
import com.milad.githoob.data.model.event.Contributor
97
import com.milad.githoob.data.model.event.Repo
8+
import com.milad.githoob.utils.GlobalState.TAG
109
import com.milad.githoob.utils.Status
1110
import dagger.hilt.android.lifecycle.HiltViewModel
1211
import 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) {

app/src/main/res/layout/profile_project_fragment.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@
414414
app:layout_constraintStart_toStartOf="@+id/profile_contributor_list"
415415
app:layout_constraintTop_toBottomOf="@+id/profile_contributor_list" />
416416

417+
<androidx.constraintlayout.widget.Group
418+
android:visibility="@{viewmodel.contributors.size() == 0 ? View.GONE : View.VISIBLE}"
419+
android:id="@+id/group"
420+
android:layout_width="wrap_content"
421+
android:layout_height="wrap_content"
422+
app:constraint_referenced_ids="profile_contributor_list,profile_all_contributions_graph_title" />
423+
417424
</androidx.constraintlayout.widget.ConstraintLayout>
418425

419426
</androidx.core.widget.NestedScrollView>

0 commit comments

Comments
 (0)