Skip to content

Commit dc84ac7

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

File tree

5 files changed

+95
-18
lines changed

5 files changed

+95
-18
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
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM14,13v4h-4v-4H7l5,-5 5,5h-3z" />
10+
</vector>

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

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,32 @@
2727

2828
<ImageView
2929
android:id="@+id/syncIcon"
30-
android:layout_width="wrap_content"
31-
android:layout_height="wrap_content"
32-
android:layout_marginTop="@dimen/big_margin"
30+
android:layout_width="@dimen/small_icon_size"
31+
android:layout_height="@dimen/small_icon_size"
3332
android:contentDescription="@null"
34-
android:src="@drawable/ic_sync_todo"
35-
app:layout_constraintBottom_toTopOf="@+id/syncInfo"
36-
app:layout_constraintEnd_toEndOf="parent"
33+
android:layout_marginEnd="@dimen/small_margin"
34+
app:layout_constraintBottom_toBottomOf="@id/syncInfo"
35+
app:layout_constraintEnd_toStartOf="@id/syncInfo"
36+
app:layout_constraintHorizontal_chainStyle="packed"
3737
app:layout_constraintStart_toStartOf="parent"
38-
app:layout_constraintTop_toBottomOf="@id/formsList"
39-
app:layout_constraintVertical_chainStyle="packed" />
38+
app:layout_constraintTop_toTopOf="@id/syncInfo"
39+
app:layout_constraintVertical_bias="0"
40+
app:srcCompat="@drawable/ic_sync_label_icon" />
4041

4142
<TextView
4243
android:id="@+id/syncInfo"
4344
style="@style/Text.Label.Small"
44-
android:layout_width="match_parent"
45+
android:layout_width="0dp"
4546
android:layout_height="wrap_content"
46-
android:layout_marginTop="@dimen/small_margin"
47-
android:gravity="center"
47+
android:layout_marginTop="@dimen/big_margin"
4848
android:paddingStart="@dimen/small_margin"
4949
android:paddingEnd="@dimen/small_margin"
5050
android:text="@string/sync_info"
51-
app:layout_constraintBottom_toTopOf="@+id/syncButton"
52-
app:layout_constraintTop_toBottomOf="@id/syncIcon"
53-
app:layout_constraintVertical_chainStyle="packed" />
51+
app:layout_constraintBottom_toTopOf="@id/syncButton"
52+
app:layout_constraintEnd_toEndOf="parent"
53+
app:layout_constraintHorizontal_chainStyle="packed"
54+
app:layout_constraintStart_toEndOf="@id/syncIcon"
55+
app:layout_constraintTop_toBottomOf="@id/formsList" />
5456

5557
<Button
5658
android:id="@+id/syncButton"
@@ -68,7 +70,44 @@
6870
android:layout_height="0dp"
6971
android:visibility="gone"
7072
app:constraint_referenced_ids="syncButton,syncIcon,syncInfo"
73+
tools:layout_editor_absoluteX="16dp"
74+
tools:layout_editor_absoluteY="24dp"
7175
tools:visibility="visible" />
76+
77+
<ImageView
78+
android:id="@+id/syncIconSuccess"
79+
android:layout_width="@dimen/small_icon_size"
80+
android:layout_height="@dimen/small_icon_size"
81+
android:contentDescription="@null"
82+
app:layout_constraintBottom_toBottomOf="@id/syncInfoSuccess"
83+
app:layout_constraintEnd_toStartOf="@id/syncInfoSuccess"
84+
app:layout_constraintHorizontal_chainStyle="packed"
85+
app:layout_constraintStart_toStartOf="parent"
86+
app:layout_constraintTop_toTopOf="@id/syncInfoSuccess"
87+
app:srcCompat="@drawable/ic_synced" />
88+
89+
<TextView
90+
android:id="@+id/syncInfoSuccess"
91+
style="@style/Text.Label.Small"
92+
android:layout_width="wrap_content"
93+
android:layout_height="wrap_content"
94+
android:layout_marginTop="@dimen/big_margin"
95+
android:paddingStart="@dimen/small_margin"
96+
android:paddingEnd="@dimen/small_margin"
97+
android:text="@string/sync_info_success"
98+
app:layout_constraintEnd_toEndOf="parent"
99+
app:layout_constraintHorizontal_chainStyle="packed"
100+
app:layout_constraintStart_toEndOf="@id/syncIconSuccess"
101+
app:layout_constraintTop_toBottomOf="@id/formsList" />
102+
103+
<androidx.constraintlayout.widget.Group
104+
android:id="@+id/syncSuccessGroup"
105+
android:layout_width="0dp"
106+
android:layout_height="0dp"
107+
android:visibility="gone"
108+
app:constraint_referenced_ids="syncIconSuccess,syncInfoSuccess"
109+
tools:visibility="gone" />
110+
72111
</androidx.constraintlayout.widget.ConstraintLayout>
73112

74113
</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)