esta guardar e nao esta a entar no perfil
This commit is contained in:
@@ -39,6 +39,14 @@ public class MedicationFragment extends Fragment {
|
||||
|
||||
medicationViewModel.getAllMedications().observe(getViewLifecycleOwner(), medications -> {
|
||||
adapter.setMedications(medications);
|
||||
|
||||
if (medications != null && !medications.isEmpty()) {
|
||||
binding.recyclerMedication.setVisibility(View.VISIBLE);
|
||||
binding.textEmptyMedications.setVisibility(View.GONE);
|
||||
} else {
|
||||
binding.recyclerMedication.setVisibility(View.GONE);
|
||||
binding.textEmptyMedications.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
binding.fabAddMedication.setOnClickListener(v -> showMedicationDialog(null));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.example.cuida.ui.schedule;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.Toast;
|
||||
@@ -22,6 +25,7 @@ public class ScheduleAppointmentFragment extends Fragment {
|
||||
|
||||
private ScheduleViewModel scheduleViewModel;
|
||||
private DatePicker datePicker;
|
||||
private AutoCompleteTextView spinnerDoctor;
|
||||
private RecyclerView recyclerTimeSlots;
|
||||
private Button btnConfirm;
|
||||
private TimeSlotAdapter timeSlotAdapter;
|
||||
@@ -34,9 +38,11 @@ public class ScheduleAppointmentFragment extends Fragment {
|
||||
scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class);
|
||||
|
||||
datePicker = root.findViewById(R.id.datePicker);
|
||||
spinnerDoctor = root.findViewById(R.id.spinner_doctor);
|
||||
recyclerTimeSlots = root.findViewById(R.id.recycler_time_slots);
|
||||
btnConfirm = root.findViewById(R.id.btn_confirm_appointment);
|
||||
|
||||
setupDoctorSpinner();
|
||||
setupDatePicker();
|
||||
setupRecyclerView();
|
||||
setupObservers();
|
||||
@@ -55,12 +61,69 @@ public class ScheduleAppointmentFragment extends Fragment {
|
||||
Toast.makeText(getContext(), "Por favor indique o motivo", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
scheduleViewModel.confirmAppointment(reason);
|
||||
|
||||
String selectedDoctor = spinnerDoctor.getText().toString();
|
||||
if (selectedDoctor.isEmpty()) {
|
||||
Toast.makeText(getContext(), "Por favor selecione um médico", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isUrgentSymptom(reason)) {
|
||||
showUrgencyAlert(selectedDoctor, reason);
|
||||
} else {
|
||||
scheduleViewModel.confirmAppointment(selectedDoctor, reason);
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean isUrgentSymptom(String reason) {
|
||||
String lowerReason = reason.toLowerCase();
|
||||
String[] urgentKeywords = {
|
||||
"dor no peito", "falta de ar", "desmaio", "sangramento",
|
||||
"paralisia", "perda de vis", "dormência", "confusão",
|
||||
"aperto no peito", "convulsão", "hemorragia", "asfixia"
|
||||
};
|
||||
|
||||
for (String keyword : urgentKeywords) {
|
||||
if (lowerReason.contains(keyword)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showUrgencyAlert(String selectedDoctor, String reason) {
|
||||
new AlertDialog.Builder(requireContext())
|
||||
.setTitle("Aviso de Urgência Médica")
|
||||
.setMessage("O motivo indicado parece necessitar de atendimento urgente. Para situações graves, dirija-se ao Hospital mais próximo ou ligue 112.\n\nPretende continuar com o agendamento normal?")
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton("Agendar na mesma", (dialog, which) -> {
|
||||
scheduleViewModel.confirmAppointment(selectedDoctor, reason);
|
||||
})
|
||||
.setNegativeButton("Cancelar", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void setupDoctorSpinner() {
|
||||
java.util.List<String> doctors = new java.util.ArrayList<>();
|
||||
doctors.add("Dr. Paulo Silva - Clínica Geral");
|
||||
doctors.add("Dra. Maria Mendes - Pediatria (Crianças)");
|
||||
doctors.add("Dr. Rui Costa - Cardiologia (Coração)");
|
||||
doctors.add("Dra. Ana Ferreira - Dermatologia (Pele)");
|
||||
doctors.add("Dr. João Almeida - Ortopedia (Ossos)");
|
||||
doctors.add("Dra. Sofia Martins - Oftalmologia (Olhos)");
|
||||
doctors.add("Dr. Pedro Oliveira - Psiquiatria (Saúde Mental)");
|
||||
doctors.add("Dra. Inês Cardoso - Ginecologia (Mulher)");
|
||||
doctors.add("Dr. Tiago Santos - Neurologia (Cérebro)");
|
||||
|
||||
java.util.Collections.shuffle(doctors); // Randomize the names as requested
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_dropdown_item_1line, doctors);
|
||||
spinnerDoctor.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void setupDatePicker() {
|
||||
Calendar today = Calendar.getInstance();
|
||||
datePicker.init(today.get(Calendar.YEAR), today.get(Calendar.MONTH),
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
private List<TimeSlot> generateTimeSlots(List<String> bookedTimes, String selectedDateStr) {
|
||||
List<TimeSlot> slots = new ArrayList<>();
|
||||
int startHour = 8;
|
||||
int endHour = 20;
|
||||
int endHour = 19;
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
boolean isToday = false;
|
||||
@@ -117,12 +117,14 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
int currentHour = now.get(Calendar.HOUR_OF_DAY);
|
||||
int currentMinute = now.get(Calendar.MINUTE);
|
||||
|
||||
for (int hour = startHour; hour < endHour; hour++) {
|
||||
for (int hour = startHour; hour <= endHour; hour++) {
|
||||
if (!isToday || hour > currentHour || (hour == currentHour && 0 > currentMinute)) {
|
||||
addSlot(slots, String.format("%02d:00", hour), bookedTimes);
|
||||
}
|
||||
if (!isToday || hour > currentHour || (hour == currentHour && 30 > currentMinute)) {
|
||||
addSlot(slots, String.format("%02d:30", hour), bookedTimes);
|
||||
if (hour != endHour) {
|
||||
if (!isToday || hour > currentHour || (hour == currentHour && 30 > currentMinute)) {
|
||||
addSlot(slots, String.format("%02d:30", hour), bookedTimes);
|
||||
}
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
@@ -134,7 +136,7 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
slots.add(new TimeSlot(time, isBooked, isSelected));
|
||||
}
|
||||
|
||||
public void confirmAppointment(String reason) {
|
||||
public void confirmAppointment(String type, String reason) {
|
||||
String date = selectedDate.getValue();
|
||||
String time = selectedTime.getValue();
|
||||
|
||||
@@ -143,7 +145,7 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
String userId = auth.getCurrentUser().getUid();
|
||||
|
||||
if (date != null && time != null) {
|
||||
Appointment appointment = new Appointment("Consulta Geral", date, time, reason, false, userId);
|
||||
Appointment appointment = new Appointment(type, date, time, reason, false, userId);
|
||||
|
||||
db.collection("consultas")
|
||||
.add(appointment)
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="4dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_greeting">
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -27,6 +27,20 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_empty_medications"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Ainda não tem medicamentos guardados."
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_title"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_add_medication"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardElevation="4dp"
|
||||
app:cardElevation="8dp"
|
||||
app:cardCornerRadius="24dp"
|
||||
app:cardBackgroundColor="@color/surface_color"
|
||||
android:layout_marginBottom="32dp">
|
||||
|
||||
|
||||
@@ -46,6 +46,28 @@
|
||||
android:layout_weight="1"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Selecionar Médico/Especialidade"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:hint="Escolha o médico">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/spinner_doctor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="none" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="2dp">
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="2dp">
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user