Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 74a822a

Browse files
committed
feat: add summary to history #0
1 parent 93dc9cf commit 74a822a

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

app/src/main/java/com/polytech/poubelledroid/history/HistoryActivity.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.os.Bundle;
66
import android.util.Log;
77
import android.view.MenuItem;
8+
import android.widget.TextView;
89
import androidx.appcompat.app.AppCompatActivity;
910
import androidx.recyclerview.widget.LinearLayoutManager;
1011
import androidx.recyclerview.widget.RecyclerView;
@@ -28,6 +29,10 @@ public class HistoryActivity extends AppCompatActivity {
2829
private AlertDialog loadingDialog;
2930
private SwipeRefreshLayout swipeRefreshLayout;
3031
private String userId;
32+
private TextView reportedWastesTextView;
33+
private TextView cleanedWastesTextView;
34+
private TextView submittedRequestsTextView;
35+
private TextView approvedRequestsTextView;
3136

3237
@Override
3338
protected void onCreate(Bundle savedInstanceState) {
@@ -55,6 +60,13 @@ protected void onCreate(Bundle savedInstanceState) {
5560

5661
swipeRefreshLayout = findViewById(R.id.swipe_refresh_layout);
5762
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();
5870
}
5971

6072
@Override
@@ -133,4 +145,44 @@ private void loadHistoryData() {
133145
// Start loading wastes which will then load cleaning requests and sort the history items
134146
loadWastes();
135147
}
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+
}
136188
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@
55
android:layout_height="match_parent"
66
android:orientation="vertical">
77

8+
<LinearLayout
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:orientation="vertical"
12+
android:padding="8dp">
13+
14+
<TextView
15+
android:id="@+id/reported_wastes"
16+
android:layout_width="wrap_content"
17+
android:layout_height="wrap_content" />
18+
19+
<TextView
20+
android:id="@+id/cleaned_wastes"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content" />
23+
24+
<TextView
25+
android:id="@+id/submitted_requests"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content" />
28+
29+
<TextView
30+
android:id="@+id/approved_requests"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content" />
33+
</LinearLayout>
34+
835
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
936
android:id="@+id/swipe_refresh_layout"
1037
android:layout_width="match_parent"

0 commit comments

Comments
 (0)