5
5
import android .os .Bundle ;
6
6
import android .util .Log ;
7
7
import android .view .MenuItem ;
8
+ import android .widget .TextView ;
8
9
import androidx .appcompat .app .AppCompatActivity ;
9
10
import androidx .recyclerview .widget .LinearLayoutManager ;
10
11
import androidx .recyclerview .widget .RecyclerView ;
@@ -28,6 +29,10 @@ public class HistoryActivity extends AppCompatActivity {
28
29
private AlertDialog loadingDialog ;
29
30
private SwipeRefreshLayout swipeRefreshLayout ;
30
31
private String userId ;
32
+ private TextView reportedWastesTextView ;
33
+ private TextView cleanedWastesTextView ;
34
+ private TextView submittedRequestsTextView ;
35
+ private TextView approvedRequestsTextView ;
31
36
32
37
@ Override
33
38
protected void onCreate (Bundle savedInstanceState ) {
@@ -55,6 +60,13 @@ protected void onCreate(Bundle savedInstanceState) {
55
60
56
61
swipeRefreshLayout = findViewById (R .id .swipe_refresh_layout );
57
62
swipeRefreshLayout .setOnRefreshListener (this ::loadHistoryData );
63
+
64
+ reportedWastesTextView = findViewById (R .id .reported_wastes );
65
+ cleanedWastesTextView = findViewById (R .id .cleaned_wastes );
66
+ submittedRequestsTextView = findViewById (R .id .submitted_requests );
67
+ approvedRequestsTextView = findViewById (R .id .approved_requests );
68
+
69
+ loadStatistics ();
58
70
}
59
71
60
72
@ Override
@@ -133,4 +145,44 @@ private void loadHistoryData() {
133
145
// Start loading wastes which will then load cleaning requests and sort the history items
134
146
loadWastes ();
135
147
}
148
+
149
+ private void loadStatistics () {
150
+ db .collection (WasteFields .COLLECTION_NAME )
151
+ .whereEqualTo (WasteFields .USER_ID , userId )
152
+ .get ()
153
+ .addOnSuccessListener (
154
+ queryDocumentSnapshots ->
155
+ reportedWastesTextView .setText (
156
+ "\uD83D \uDEA8 Déchets signalés : "
157
+ + queryDocumentSnapshots .size ()));
158
+
159
+ db .collection (WasteFields .COLLECTION_NAME )
160
+ .whereEqualTo (WasteFields .USER_ID , userId )
161
+ .whereEqualTo ("cleaned" , true )
162
+ .get ()
163
+ .addOnSuccessListener (
164
+ queryDocumentSnapshots ->
165
+ cleanedWastesTextView .setText (
166
+ "\uD83D \uDEAE Déchets nettoyés : "
167
+ + queryDocumentSnapshots .size ()));
168
+
169
+ db .collection (CleaningRequestsFields .COLLECTION_NAME )
170
+ .whereEqualTo (CleaningRequestsFields .CLEANER_ID , userId )
171
+ .get ()
172
+ .addOnSuccessListener (
173
+ queryDocumentSnapshots ->
174
+ submittedRequestsTextView .setText (
175
+ "\uD83E \uDDF9 Nettoyages soumis : "
176
+ + queryDocumentSnapshots .size ()));
177
+
178
+ db .collection (CleaningRequestsFields .COLLECTION_NAME )
179
+ .whereEqualTo (CleaningRequestsFields .CLEANER_ID , userId )
180
+ .whereEqualTo ("status" , 1 )
181
+ .get ()
182
+ .addOnSuccessListener (
183
+ queryDocumentSnapshots ->
184
+ approvedRequestsTextView .setText (
185
+ "\uD83E \uDDFC Nettoyages approuvés : "
186
+ + queryDocumentSnapshots .size ()));
187
+ }
136
188
}
0 commit comments