Skip to content

Commit 419c809

Browse files
author
Targholi
committed
add linear indicator to show progress in ui fragments.
1 parent c934596 commit 419c809

File tree

12 files changed

+80
-11
lines changed

12 files changed

+80
-11
lines changed

app/src/main/java/com/milad/githoob/ui/profile/ProfileViewModel.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ class ProfileViewModel @Inject constructor(
2727
private lateinit var token: String
2828

2929
private val _forceUpdate = MutableLiveData(false)
30-
private val _dataLoading = MutableLiveData<Boolean>()
30+
private val _dataLoading = MutableLiveData(true)
3131
private val _user = Transformations.switchMap(_forceUpdate) { bool ->
3232
val user = MutableLiveData<User>()
3333
if (bool) {
34-
_dataLoading.postValue(true)
3534
viewModelScope.launch(ioDispatcher) {
3635

3736
getUserInfo(token, userId).collect {
@@ -84,22 +83,18 @@ class ProfileViewModel @Inject constructor(
8483
val userContributes: LiveData<List<ContributionsDay>> = Transformations.switchMap(_user) {
8584
val list = MutableLiveData<List<ContributionsDay>>()
8685

87-
_dataLoading.postValue(true)
8886
val url = String.format(AppConstants.CONTRIBUTE_URL, it.login)
8987

9088
viewModelScope.launch(ioDispatcher) {
9189
mainRepository.getUserContribute(url).collect {
9290
when (it.status) {
9391
Status.SUCCESS -> {
94-
_dataLoading.postValue(false)
9592
val listCont = ContributionsProvider().getContributions(it.data?.string())
9693
list.postValue(listCont)
9794
}
9895
Status.LOADING -> {
99-
_dataLoading.postValue(true)
10096
}
10197
Status.ERROR -> {
102-
_dataLoading.postValue(false)
10398
}
10499
}
105100
}

app/src/main/java/com/milad/githoob/ui/profile/connection/ConnectionViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ConnectionViewModel @Inject constructor(
2525
private var _connectionList = MutableLiveData<ArrayList<User>>()
2626

2727
val connectionList: LiveData<ArrayList<User>> = _connectionList
28+
private val _dataLoading = MutableLiveData(true)
29+
val dataLoading: LiveData<Boolean> = _dataLoading
2830

2931
fun setUser(token: String = "", userId: String = "", type: String) {
3032
getStarredRepo(token, userId, type)
@@ -40,12 +42,14 @@ class ConnectionViewModel @Inject constructor(
4042
when (it.status) {
4143
Status.SUCCESS -> {
4244
_connectionList.postValue((it.data!!))
45+
_dataLoading.postValue(false)
4346
}
4447
Status.LOADING -> {
45-
// TODO: 2/1/2022 set loading
48+
_dataLoading.postValue(true)
4649
}
4750
Status.ERROR -> {
4851
Timber.d(it.message.toString())
52+
_dataLoading.postValue(false)
4953
}
5054
}
5155
}

app/src/main/java/com/milad/githoob/ui/profile/organization/ProfileOrgsViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ProfileOrgsViewModel @Inject constructor(
2626
private val _orgsList: MutableLiveData<ArrayList<Org>> = MutableLiveData()
2727
val orgsList: LiveData<ArrayList<Org>> = _orgsList
2828

29+
private val _dataLoading = MutableLiveData(true)
30+
val dataLoading: LiveData<Boolean> = _dataLoading
31+
2932
fun setUser(token: String, userId: String) {
3033
getOrgs(token, userId)
3134
}
@@ -37,12 +40,14 @@ class ProfileOrgsViewModel @Inject constructor(
3740
Status.SUCCESS -> {
3841
Log.d("@@", "getOrgs: ${it.data?.size}")
3942
_orgsList.postValue((it.data!!))
43+
_dataLoading.postValue(false)
4044
}
4145
Status.LOADING -> {
42-
// TODO: 2/1/2022 set loading
46+
_dataLoading.postValue(true)
4347
}
4448
Status.ERROR -> {
4549
Timber.d(it.message.toString())
50+
_dataLoading.postValue(false)
4651
}
4752
}
4853
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class ProfileRepositoriesViewModel @Inject constructor(
3030
switchMatData(it)
3131
}
3232

33+
private val _dataLoading = MutableLiveData(true)
34+
val dataLoading: LiveData<Boolean> = _dataLoading
35+
3336
private fun switchMatData(list: ArrayList<Repo>): LiveData<ArrayList<Repo>> {
3437
val d = MutableLiveData<ArrayList<Repo>>()
3538
val jsonUser = JsonUtils(context)
@@ -52,12 +55,14 @@ class ProfileRepositoriesViewModel @Inject constructor(
5255
when (it.status) {
5356
Status.SUCCESS -> {
5457
_repoList.postValue(it.data!!)
58+
_dataLoading.postValue(false)
5559
}
5660
Status.LOADING -> {
57-
// TODO: 2/1/2022 set loading
61+
_dataLoading.postValue(true)
5862
}
5963
Status.ERROR -> {
6064
Timber.d(it.message.toString())
65+
_dataLoading.postValue(false)
6166
}
6267
}
6368
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class ProfileProjectViewModel @Inject constructor(
2929
private val _markdown = MutableLiveData<String>("")
3030
val markdown: LiveData<String> = _markdown
3131

32+
private val _dataLoading = MutableLiveData(true)
33+
val dataLoading: LiveData<Boolean> = _dataLoading
34+
3235
fun setUser(token: String?, userId: String, projectName: String) =
3336
loadProjectData(token, userId, projectName)
3437

@@ -62,12 +65,14 @@ class ProfileProjectViewModel @Inject constructor(
6265
when (it.status) {
6366
Status.SUCCESS -> {
6467
_repo.postValue(it.data!!)
68+
_dataLoading.postValue(false)
6569
}
6670
Status.LOADING -> {
67-
// TODO: 2/1/2022 set loading
71+
_dataLoading.postValue(true)
6872
}
6973
Status.ERROR -> {
7074
Timber.d(it.message.toString())
75+
_dataLoading.postValue(false)
7176
}
7277
}
7378
}

app/src/main/java/com/milad/githoob/ui/profile/stared/ProfileStaredViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class ProfileStaredViewModel @Inject constructor(
2929
getRepoLangColor(it)
3030
}
3131

32+
private val _dataLoading = MutableLiveData(true)
33+
val dataLoading: LiveData<Boolean> = _dataLoading
34+
3235
private fun getRepoLangColor(list: ArrayList<Repo>): LiveData<ArrayList<Repo>> {
3336
val d = MutableLiveData<ArrayList<Repo>>()
3437
val jsonUser = JsonUtils(context)
@@ -51,12 +54,14 @@ class ProfileStaredViewModel @Inject constructor(
5154
when (it.status) {
5255
Status.SUCCESS -> {
5356
_starredList.postValue((it.data!!))
57+
_dataLoading.postValue(false)
5458
}
5559
Status.LOADING -> {
56-
// TODO: 2/1/2022 set loading
60+
_dataLoading.postValue(true)
5761
}
5862
Status.ERROR -> {
5963
Timber.d(it.message.toString())
64+
_dataLoading.postValue(false)
6065
}
6166
}
6267
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@
9292
android:layout_height="wrap_content"
9393
app:tabMode="fixed" />
9494

95+
<com.google.android.material.progressindicator.LinearProgressIndicator
96+
android:id="@+id/progressBar"
97+
android:layout_width="match_parent"
98+
android:indeterminate="true"
99+
android:layout_height="wrap_content"
100+
android:visibility="@{viewmodel.dataLoading == true ? View.VISIBLE: View.GONE}"
101+
tools:visibility="visible" />
102+
95103
</com.milad.githoob.utils.collapsingToolbar.CollapsibleAppbar>
96104

97105
<androidx.viewpager2.widget.ViewPager2

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@
484484

485485
</com.milad.githoob.utils.collapsingToolbar.CollapsibleToolbar>
486486

487+
<com.google.android.material.progressindicator.LinearProgressIndicator
488+
android:id="@+id/progressBar"
489+
android:layout_width="match_parent"
490+
android:indeterminate="true"
491+
android:layout_height="wrap_content"
492+
android:visibility="@{viewmodel.dataLoading == true ? View.VISIBLE: View.GONE}"
493+
tools:visibility="visible" />
494+
487495
</com.milad.githoob.utils.collapsingToolbar.CollapsibleAppbar>
488496

489497
<androidx.core.widget.NestedScrollView

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070

7171
</com.milad.githoob.utils.collapsingToolbar.CollapsibleToolbar>
7272

73+
<com.google.android.material.progressindicator.LinearProgressIndicator
74+
android:id="@+id/progressBar"
75+
android:layout_width="match_parent"
76+
android:indeterminate="true"
77+
android:layout_height="wrap_content"
78+
android:visibility="@{viewmodel.dataLoading == true ? View.VISIBLE: View.GONE}"
79+
tools:visibility="visible" />
80+
7381
</com.milad.githoob.utils.collapsingToolbar.CollapsibleAppbar>
7482

7583
<androidx.core.widget.NestedScrollView

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@
346346
</LinearLayout>
347347

348348
</com.milad.githoob.utils.collapsingToolbar.CollapsibleToolbar>
349+
350+
<com.google.android.material.progressindicator.LinearProgressIndicator
351+
android:id="@+id/progressBar"
352+
android:layout_width="match_parent"
353+
android:indeterminate="true"
354+
android:layout_height="wrap_content"
355+
android:visibility="@{viewmodel.dataLoading == true ? View.VISIBLE: View.GONE}"
356+
tools:visibility="visible" />
357+
349358
</com.milad.githoob.utils.collapsingToolbar.CollapsibleAppbar>
350359

351360
<androidx.core.widget.NestedScrollView

0 commit comments

Comments
 (0)