This commit is contained in:
2026-04-30 10:37:16 +01:00
parent b0b7a4087e
commit ae6cf5413c
3 changed files with 3 additions and 80 deletions

View File

@@ -84,54 +84,12 @@ 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() {

View File

@@ -84,41 +84,6 @@
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>