Skip to content

Commit 1949ae7

Browse files
committed
Add sync related UI changes
1 parent affc4ba commit 1949ae7

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

app/src/main/java/ro/code4/monitorizarevot/ui/forms/FormsListFragment.kt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ class FormsListFragment : ViewModelFragment<FormsViewModel>() {
4848
super.onViewCreated(view, savedInstanceState)
4949
viewModel.forms().observe(this, Observer {
5050
formAdapter.items = it
51+
updateSyncStatus()
5152
})
5253
viewModel.syncVisibility().observe(this, Observer {
5354
syncGroup.visibility = it
55+
updateSyncStatus()
5456
})
5557

5658
viewModel.setTitle(getString(R.string.title_forms_list))
@@ -60,9 +62,11 @@ class FormsListFragment : ViewModelFragment<FormsViewModel>() {
6062
logAnalyticsEvent(Event.MANUAL_SYNC, Param(ParamKey.NUMBER_NOT_SYNCED, 0))
6163

6264
if (!mContext.isOnline()) {
63-
Snackbar.make(syncButton, getString(R.string.form_sync_no_internet), Snackbar.LENGTH_SHORT)
64-
.show()
65-
65+
Snackbar.make(
66+
syncButton,
67+
getString(R.string.form_sync_no_internet),
68+
Snackbar.LENGTH_SHORT
69+
).show()
6670
return@setOnClickListener
6771
}
6872

@@ -78,4 +82,26 @@ class FormsListFragment : ViewModelFragment<FormsViewModel>() {
7882
)
7983
}
8084
}
85+
86+
/**
87+
* Update the status of the sync indicators based on the values of the LiveDatas for forms and the sync
88+
* Button. If we only use the syncVisibility() LiveData then we could get into a situation when the
89+
* syncVisibility LiveData will trigger before the forms LiveData and we will have an empty screen which
90+
* shows that everything is synchronized(and the info views will also jump around after the forms will be
91+
* added).
92+
*/
93+
private fun updateSyncStatus() {
94+
val newSyncVisibility = viewModel.syncVisibility().value
95+
val areFormsVisible = viewModel.forms().value?.let { true } ?: false
96+
newSyncVisibility?.let {
97+
// remember that the sync visibility we use it's for the sync button so the success info will use
98+
// the complementary visibility(ex: received View.VISIBLE should set View.GONE)
99+
when (it) {
100+
View.VISIBLE -> syncSuccessGroup.visibility = View.GONE
101+
View.GONE -> syncSuccessGroup.visibility =
102+
if (areFormsVisible) View.VISIBLE else View.GONE
103+
}
104+
Unit
105+
}
106+
}
81107
}

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,44 @@
6868
android:layout_height="0dp"
6969
android:visibility="gone"
7070
app:constraint_referenced_ids="syncButton,syncIcon,syncInfo"
71-
tools:visibility="visible" />
71+
tools:layout_editor_absoluteX="16dp"
72+
tools:layout_editor_absoluteY="24dp"
73+
tools:visibility="gone" />
74+
75+
<ImageView
76+
android:id="@+id/syncIconSuccess"
77+
android:layout_width="@dimen/small_icon_size"
78+
android:layout_height="@dimen/small_icon_size"
79+
android:contentDescription="@null"
80+
app:layout_constraintBottom_toBottomOf="@id/syncInfoSuccess"
81+
app:layout_constraintEnd_toStartOf="@id/syncInfoSuccess"
82+
app:layout_constraintHorizontal_chainStyle="packed"
83+
app:layout_constraintStart_toStartOf="parent"
84+
app:layout_constraintTop_toTopOf="@id/syncInfoSuccess"
85+
app:srcCompat="@drawable/ic_synced" />
86+
87+
<TextView
88+
android:id="@+id/syncInfoSuccess"
89+
style="@style/Text.Label.Small"
90+
android:layout_width="wrap_content"
91+
android:layout_height="wrap_content"
92+
android:layout_marginTop="@dimen/big_margin"
93+
android:paddingStart="@dimen/small_margin"
94+
android:paddingEnd="@dimen/small_margin"
95+
android:text="@string/sync_info_success"
96+
app:layout_constraintEnd_toEndOf="parent"
97+
app:layout_constraintHorizontal_chainStyle="packed"
98+
app:layout_constraintStart_toEndOf="@id/syncIconSuccess"
99+
app:layout_constraintTop_toBottomOf="@id/formsList" />
100+
101+
<androidx.constraintlayout.widget.Group
102+
android:id="@+id/syncSuccessGroup"
103+
android:layout_width="0dp"
104+
android:layout_height="0dp"
105+
android:visibility="gone"
106+
app:constraint_referenced_ids="syncIconSuccess,syncInfoSuccess"
107+
tools:visibility="gone" />
108+
72109
</androidx.constraintlayout.widget.ConstraintLayout>
73110

74111
</androidx.core.widget.NestedScrollView>

app/src/main/res/values-ro-rRO/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
<!-- Forms list -->
8989
<string name="form_notes">Adaugă notă</string>
9090

91-
<string name="sync_info">Unele întrebări nu au fost sincronizate. Apasă butonul pentru a trimite răspunsurile din nou.</string>
91+
<string name="sync_info">Unele răspunsuri sau note nu au fost sincronizate. Apasă butonul pentru a trimite răspunsurile din nou.</string>
92+
<string name="sync_info_success">Toate răspunsurile și notele au fost sincronizate cu succes</string>
9293
<string name="sync_manual">Sincronizează datele manual</string>
9394

9495
<string name="form_sync_no_internet">Ai nevoie de o conexiune la internet pentru a sincroniza datele!</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<string name="form_notes">Add a message</string>
9090

9191
<string name="sync_info">It appears that some of the questions have not been synchronised. Tap the button below to send the answers again</string>
92+
<string name="sync_info_success">All the answers and notes were synchronized successfully</string>
9293
<string name="sync_manual">Synchronize data manually</string>
9394

9495
<string name="form_sync_no_internet">You need to be connected to the internet to be able to sync the data!</string>

0 commit comments

Comments
 (0)