Skip to content

Commit b3a5bcc

Browse files
committed
Modification v1.15
- Added Feature: View Clothes in Laundry where user can view total number of clothes in laundry, all the clothes, and a button to clear all laundry at once - Added ViewLaundryActivity.java - Added activity_view_laundry.xml
1 parent a04eabc commit b3a5bcc

5 files changed

Lines changed: 172 additions & 2 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<activity android:name=".RemoveClothesActivity"/>
3232
<activity android:name=".ProfileActivity"/>
3333
<activity android:name=".ClothesDetailsActivity" />
34+
<activity android:name=".ViewLaundryActivity" />
3435
</application>
3536
</manifest>

app/src/main/java/com/example/initial/DashboardActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class DashboardActivity extends AppCompatActivity {
1111

1212
private Button uploadClothesButton, viewClothesButton, manageLaundryButton, removeClothesButton;
13-
private Button profileButton;
13+
private Button profileButton, viewLaundryButton;
1414
@Override
1515
protected void onCreate(Bundle savedInstanceState) {
1616
super.onCreate(savedInstanceState);
@@ -19,6 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
1919
uploadClothesButton = findViewById(R.id.uploadClothesButton);
2020
viewClothesButton = findViewById(R.id.viewClothesButton);
2121
manageLaundryButton = findViewById(R.id.manageLaundryButton);
22+
viewLaundryButton = findViewById(R.id.viewLaundryButton);
2223
removeClothesButton = findViewById(R.id.removeClothesButton);
2324
profileButton = findViewById(R.id.profileButton);
2425

@@ -54,6 +55,13 @@ public void onClick(View view) {
5455
startActivity(new Intent(DashboardActivity.this, LaundryActivity.class));
5556
}
5657
});
58+
viewLaundryButton.setOnClickListener(new View.OnClickListener() {
59+
@Override
60+
public void onClick(View view) {
61+
// Navigate to LaundryActivity
62+
startActivity(new Intent(DashboardActivity.this, ViewLaundryActivity.class));
63+
}
64+
});
5765
removeClothesButton.setOnClickListener(new View.OnClickListener() {
5866
@Override
5967
public void onClick(View view) {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.example.initial;
2+
3+
import android.os.Bundle;
4+
import android.view.View;
5+
import android.widget.Button;
6+
import android.widget.TextView;
7+
import android.widget.Toast;
8+
import androidx.appcompat.app.AppCompatActivity;
9+
import androidx.recyclerview.widget.LinearLayoutManager;
10+
import androidx.recyclerview.widget.RecyclerView;
11+
import com.google.firebase.auth.FirebaseAuth;
12+
import com.google.firebase.firestore.DocumentSnapshot;
13+
import com.google.firebase.firestore.FirebaseFirestore;
14+
import com.google.firebase.firestore.QuerySnapshot;
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
public class ViewLaundryActivity extends AppCompatActivity {
19+
20+
private TextView totalClothesTextView;
21+
private RecyclerView recyclerView;
22+
private ClothesAdapter clothesAdapter;
23+
private List<Clothes> clothesList;
24+
private FirebaseFirestore db;
25+
private FirebaseAuth mAuth;
26+
private Button clearLaundryButton;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.activity_view_laundry);
32+
33+
totalClothesTextView = findViewById(R.id.totalClothesTextView);
34+
recyclerView = findViewById(R.id.recyclerView);
35+
recyclerView.setLayoutManager(new LinearLayoutManager(this));
36+
37+
clearLaundryButton = findViewById(R.id.clearLaundryButton);
38+
39+
clothesList = new ArrayList<>();
40+
clothesAdapter = new ClothesAdapter(this, clothesList);
41+
recyclerView.setAdapter(clothesAdapter);
42+
43+
mAuth = FirebaseAuth.getInstance();
44+
db = FirebaseFirestore.getInstance();
45+
46+
loadClothesInLaundry();
47+
48+
clearLaundryButton.setOnClickListener(new View.OnClickListener() {
49+
@Override
50+
public void onClick(View v) {
51+
clearAllClothesFromLaundry();
52+
}
53+
});
54+
}
55+
56+
// Load clothes that are currently in laundry
57+
private void loadClothesInLaundry() {
58+
String userId = mAuth.getCurrentUser().getUid();
59+
db.collection("clothes")
60+
.whereEqualTo("userId", userId)
61+
.whereEqualTo("inLaundry", true)
62+
.get()
63+
.addOnCompleteListener(task -> {
64+
if (task.isSuccessful()) {
65+
QuerySnapshot querySnapshot = task.getResult();
66+
clothesList.clear();
67+
if (querySnapshot != null) {
68+
for (DocumentSnapshot document : querySnapshot.getDocuments()) {
69+
Clothes clothes = document.toObject(Clothes.class);
70+
clothesList.add(clothes);
71+
}
72+
// Update RecyclerView
73+
clothesAdapter.notifyDataSetChanged();
74+
// Update total count
75+
updateTotalClothesCount();
76+
}
77+
} else {
78+
Toast.makeText(ViewLaundryActivity.this, "Failed to load clothes", Toast.LENGTH_SHORT).show();
79+
}
80+
});
81+
}
82+
83+
// Update the text view with the total number of clothes in laundry
84+
private void updateTotalClothesCount() {
85+
int totalClothes = clothesList.size();
86+
totalClothesTextView.setText("Total Clothes in Laundry: " + totalClothes);
87+
}
88+
89+
// Clear all clothes from laundry (set inLaundry to false)
90+
private void clearAllClothesFromLaundry() {
91+
for (Clothes clothes : clothesList) {
92+
db.collection("clothes").document(clothes.getId())
93+
.update("inLaundry", false)
94+
.addOnSuccessListener(aVoid -> {
95+
Toast.makeText(ViewLaundryActivity.this, "All clothes cleared from laundry", Toast.LENGTH_SHORT).show();
96+
loadClothesInLaundry(); // Reload the list after clearing
97+
})
98+
.addOnFailureListener(e -> Toast.makeText(ViewLaundryActivity.this, "Failed to clear clothes from laundry", Toast.LENGTH_SHORT).show());
99+
}
100+
}
101+
}
102+
103+
//public class ViewLaundryActivity {
104+
//}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@
7777
app:layout_constraintStart_toStartOf="parent"
7878
app:layout_constraintEnd_toEndOf="parent" />
7979

80+
<Button
81+
android:id="@+id/viewLaundryButton"
82+
android:layout_width="0dp"
83+
android:layout_height="wrap_content"
84+
android:layout_margin="16dp"
85+
android:layout_marginTop="16dp"
86+
android:text="View Clothes in Laundry"
87+
android:background="@drawable/button_background"
88+
android:fontFamily="@font/sf"
89+
android:textColor="@android:color/white"
90+
android:textSize="18sp"
91+
app:layout_constraintTop_toBottomOf="@id/manageLaundryButton"
92+
app:layout_constraintStart_toStartOf="parent"
93+
app:layout_constraintEnd_toEndOf="parent" />
94+
95+
8096
<Button
8197
android:id="@+id/removeClothesButton"
8298
android:layout_width="0dp"
@@ -88,7 +104,7 @@
88104
android:textColor="@android:color/white"
89105
android:fontFamily="@font/sf"
90106
android:textSize="18sp"
91-
app:layout_constraintTop_toBottomOf="@id/manageLaundryButton"
107+
app:layout_constraintTop_toBottomOf="@id/viewLaundryButton"
92108
app:layout_constraintStart_toStartOf="parent"
93109
app:layout_constraintEnd_toEndOf="parent" />
94110

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:padding="16dp">
7+
8+
<!-- Total clothes in laundry count -->
9+
<TextView
10+
android:id="@+id/totalClothesTextView"
11+
android:layout_width="0dp"
12+
android:layout_height="wrap_content"
13+
android:text="Total Clothes in Laundry: 0"
14+
android:textSize="18sp"
15+
android:textStyle="bold"
16+
app:layout_constraintTop_toTopOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintEnd_toEndOf="parent" />
19+
20+
<!-- RecyclerView to display the list of clothes in laundry -->
21+
<androidx.recyclerview.widget.RecyclerView
22+
android:id="@+id/recyclerView"
23+
android:layout_width="0dp"
24+
android:layout_height="0dp"
25+
app:layout_constraintTop_toBottomOf="@id/totalClothesTextView"
26+
app:layout_constraintStart_toStartOf="parent"
27+
app:layout_constraintEnd_toEndOf="parent"
28+
app:layout_constraintBottom_toTopOf="@id/clearLaundryButton" />
29+
30+
<!-- Button to clear all clothes from laundry -->
31+
<Button
32+
android:id="@+id/clearLaundryButton"
33+
android:layout_width="0dp"
34+
android:layout_height="wrap_content"
35+
android:text="Clear All Clothes from Laundry"
36+
android:layout_marginTop="16dp"
37+
app:layout_constraintTop_toBottomOf="@id/recyclerView"
38+
app:layout_constraintStart_toStartOf="parent"
39+
app:layout_constraintEnd_toEndOf="parent"
40+
app:layout_constraintBottom_toBottomOf="parent" />
41+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)