.
This commit is contained in:
@@ -84,9 +84,55 @@ public class HomeFragment extends Fragment {
|
||||
.navigate(com.example.cuida.R.id.action_home_to_schedule_appointment);
|
||||
});
|
||||
|
||||
// --- Feed Listener ---
|
||||
loadFeed();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void loadFeed() {
|
||||
com.google.firebase.auth.FirebaseAuth auth = com.google.firebase.auth.FirebaseAuth.getInstance();
|
||||
if (auth.getCurrentUser() == null) return;
|
||||
String userId = auth.getCurrentUser().getUid();
|
||||
|
||||
com.google.firebase.firestore.FirebaseFirestore.getInstance().collection("feed")
|
||||
.whereEqualTo("userId", userId)
|
||||
.orderBy("data", com.google.firebase.firestore.Query.Direction.DESCENDING)
|
||||
.addSnapshotListener((value, error) -> {
|
||||
if (error != null) return;
|
||||
if (value != null && isAdded()) {
|
||||
binding.layoutFeedContainer.removeAllViews();
|
||||
if (value.isEmpty()) {
|
||||
binding.layoutFeedContainer.addView(binding.textNoFeed);
|
||||
} else {
|
||||
for (com.google.firebase.firestore.DocumentSnapshot doc : value.getDocuments()) {
|
||||
addFeedItem(doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addFeedItem(com.google.firebase.firestore.DocumentSnapshot doc) {
|
||||
if (!isAdded()) return;
|
||||
View itemView = getLayoutInflater().inflate(com.example.cuida.R.layout.item_feed, binding.layoutFeedContainer, false);
|
||||
|
||||
android.widget.TextView title = itemView.findViewById(com.example.cuida.R.id.feed_item_title);
|
||||
android.widget.TextView content = itemView.findViewById(com.example.cuida.R.id.feed_item_content);
|
||||
android.widget.TextView date = itemView.findViewById(com.example.cuida.R.id.feed_item_date);
|
||||
|
||||
title.setText(doc.getString("titulo"));
|
||||
content.setText(doc.getString("conteudo"));
|
||||
|
||||
com.google.firebase.Timestamp ts = doc.getTimestamp("data");
|
||||
if (ts != null) {
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd MMM, HH:mm", java.util.Locale.getDefault());
|
||||
date.setText(sdf.format(ts.toDate()));
|
||||
}
|
||||
|
||||
binding.layoutFeedContainer.addView(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
@@ -79,9 +79,14 @@ public class ProfileFragment extends Fragment {
|
||||
currentUser.name = auth.getCurrentUser().getDisplayName();
|
||||
}
|
||||
|
||||
db.collection("utilizadores").document(userId).get()
|
||||
.addOnSuccessListener(doc -> {
|
||||
if (doc.exists() && isAdded()) {
|
||||
db.collection("utilizadores").document(userId)
|
||||
.addSnapshotListener((doc, error) -> {
|
||||
if (error != null) {
|
||||
Log.e("ProfileFragment", "Listen failed.", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (doc != null && doc.exists() && isAdded()) {
|
||||
currentUser.id = doc.getId();
|
||||
String nome = doc.getString("nome_completo");
|
||||
if (nome == null) nome = doc.getString("name");
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
displayName += " - " + specialty;
|
||||
}
|
||||
if (!displayName.startsWith("Dr.") && !displayName.startsWith("Dra.")) {
|
||||
if ("Feminino".equalsIgnoreCase(gender) || "Feminino".equals(gender)) {
|
||||
if ("Feminino".equalsIgnoreCase(gender)) {
|
||||
displayName = "Dra. " + displayName;
|
||||
} else {
|
||||
displayName = "Dr. " + displayName;
|
||||
@@ -148,12 +148,17 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
timeSlots.setValue(generateTimeSlots(new ArrayList<>(), date));
|
||||
|
||||
if (auth.getCurrentUser() == null) return;
|
||||
String userId = auth.getCurrentUser().getUid();
|
||||
String doctor = selectedDoctor.getValue();
|
||||
|
||||
// Listen in REAL-TIME for all appointments on the selected date
|
||||
if (doctor == null) {
|
||||
timeSlots.setValue(generateTimeSlots(new ArrayList<>(), date));
|
||||
return;
|
||||
}
|
||||
|
||||
// Listen in REAL-TIME for appointments of the selected doctor on the selected date
|
||||
snapshotListener = db.collection("consultas")
|
||||
.whereEqualTo("date", date)
|
||||
.whereEqualTo("type", doctor)
|
||||
.addSnapshotListener((queryDocumentSnapshots, e) -> {
|
||||
if (e != null) {
|
||||
Log.e("ScheduleViewModel", "Listen failed.", e);
|
||||
@@ -164,16 +169,11 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
if (queryDocumentSnapshots != null) {
|
||||
for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
|
||||
Appointment appt = document.toObject(Appointment.class);
|
||||
|
||||
boolean isDoctorAppointment = doctor != null && doctor.equals(appt.type);
|
||||
|
||||
if (isDoctorAppointment && appt.time != null) {
|
||||
if (!bookedTimes.contains(appt.time)) {
|
||||
if (appt.time != null && !bookedTimes.contains(appt.time)) {
|
||||
bookedTimes.add(appt.time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<TimeSlot> slots = generateTimeSlots(bookedTimes, date);
|
||||
timeSlots.setValue(slots);
|
||||
|
||||
@@ -84,4 +84,41 @@
|
||||
app:iconGravity="textStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/card_next_medication"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_feed_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Feed Clínico"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/primary_color"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/button_book_appointment"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_feed_title"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_feed_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_no_feed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Sem novos relatórios ou atualizações."
|
||||
android:textAlignment="center"
|
||||
android:padding="24dp"
|
||||
android:textColor="@android:color/darker_gray"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
Reference in New Issue
Block a user