a ia esta com erro 429 mas esta a funcionar (segundo o anti gravity)
This commit is contained in:
@@ -17,8 +17,8 @@ import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class Gemini {
|
||||
private static final String API_KEY = "AIzaSyBmLgn-SHaTDvAeDWsw2iTZRR9gahhOu7k";
|
||||
private static final String MODEL_NAME = "gemini-1.5-flash";
|
||||
private static final String API_KEY = "AIzaSyBYar6Yv0rhrZX8cIQQxd77TLERHRsjAtY";
|
||||
private static final String MODEL_NAME = "gemini-2.0-flash";
|
||||
private static final String API_URL = "https://generativelanguage.googleapis.com/v1beta/models/" + MODEL_NAME + ":generateContent?key=" + API_KEY;
|
||||
private final OkHttpClient client;
|
||||
private final Handler mainHandler;
|
||||
|
||||
@@ -196,5 +196,12 @@ public class ScheduleAppointmentFragment extends Fragment {
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
scheduleViewModel.getSelectedDoctorSchedule().observe(getViewLifecycleOwner(), schedule -> {
|
||||
android.widget.TextView textSchedule = getView().findViewById(R.id.text_doctor_schedule);
|
||||
if (textSchedule != null) {
|
||||
textSchedule.setText(schedule);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,11 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
private final MutableLiveData<String> selectedTime = new MutableLiveData<>();
|
||||
private final MutableLiveData<String> selectedDoctor = new MutableLiveData<>();
|
||||
private final MutableLiveData<List<TimeSlot>> timeSlots = new MutableLiveData<>();
|
||||
private final MutableLiveData<String> selectedDoctorSchedule = new MutableLiveData<>();
|
||||
private final MutableLiveData<Boolean> saveSuccess = new MutableLiveData<>();
|
||||
private final MutableLiveData<String> saveError = new MutableLiveData<>();
|
||||
private final MutableLiveData<List<String>> doctorsList = new MutableLiveData<>(new ArrayList<>());
|
||||
private final java.util.Map<String, String> doctorSchedules = new java.util.HashMap<>();
|
||||
|
||||
private ListenerRegistration snapshotListener;
|
||||
|
||||
@@ -46,6 +48,7 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
.addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful() && task.getResult() != null) {
|
||||
List<String> docs = new ArrayList<>();
|
||||
doctorSchedules.clear();
|
||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||
String name = document.getString("nome");
|
||||
if (name == null) name = document.getString("nome_completo");
|
||||
@@ -53,6 +56,7 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
|
||||
String specialty = document.getString("especialidade");
|
||||
String gender = document.getString("genero");
|
||||
String horario = document.getString("horario");
|
||||
|
||||
if (name != null && !name.trim().isEmpty()) {
|
||||
String displayName = name;
|
||||
@@ -67,6 +71,9 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
}
|
||||
}
|
||||
docs.add(displayName);
|
||||
if (horario != null) {
|
||||
doctorSchedules.put(displayName, horario);
|
||||
}
|
||||
}
|
||||
}
|
||||
doctorsList.postValue(docs);
|
||||
@@ -84,12 +91,18 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
|
||||
public void setSelectedDoctor(String doctor) {
|
||||
selectedDoctor.setValue(doctor);
|
||||
String schedule = doctorSchedules.get(doctor);
|
||||
selectedDoctorSchedule.setValue(schedule != null ? "Horário: " + schedule : "Horário: 08:00 - 19:00");
|
||||
String date = selectedDate.getValue();
|
||||
if (date != null) {
|
||||
loadTimeSlots(date);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<String> getSelectedDoctorSchedule() {
|
||||
return selectedDoctorSchedule;
|
||||
}
|
||||
|
||||
public LiveData<String> getSelectedDate() {
|
||||
return selectedDate;
|
||||
}
|
||||
@@ -179,6 +192,25 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
List<TimeSlot> slots = new ArrayList<>();
|
||||
int startHour = 8;
|
||||
int endHour = 19;
|
||||
int startMinute = 0;
|
||||
int endMinute = 0;
|
||||
|
||||
String doctor = selectedDoctor.getValue();
|
||||
String schedule = doctorSchedules.get(doctor);
|
||||
|
||||
if (schedule != null && schedule.contains(" - ")) {
|
||||
try {
|
||||
String[] parts = schedule.split(" - ");
|
||||
String[] startParts = parts[0].split(":");
|
||||
String[] endParts = parts[1].split(":");
|
||||
startHour = Integer.parseInt(startParts[0]);
|
||||
startMinute = Integer.parseInt(startParts[1]);
|
||||
endHour = Integer.parseInt(endParts[0]);
|
||||
endMinute = Integer.parseInt(endParts[1]);
|
||||
} catch (Exception e) {
|
||||
Log.e("ScheduleViewModel", "Error parsing schedule: " + schedule);
|
||||
}
|
||||
}
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
boolean isToday = false;
|
||||
@@ -196,16 +228,30 @@ 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++) {
|
||||
if (!isToday || hour > currentHour || (hour == currentHour && 0 > currentMinute)) {
|
||||
addSlot(slots, String.format("%02d:00", hour), bookedTimes);
|
||||
}
|
||||
if (hour != endHour) {
|
||||
if (!isToday || hour > currentHour || (hour == currentHour && 30 > currentMinute)) {
|
||||
addSlot(slots, String.format("%02d:30", hour), bookedTimes);
|
||||
}
|
||||
Calendar cursor = Calendar.getInstance();
|
||||
cursor.set(Calendar.HOUR_OF_DAY, startHour);
|
||||
cursor.set(Calendar.MINUTE, startMinute);
|
||||
cursor.set(Calendar.SECOND, 0);
|
||||
cursor.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Calendar endLimit = Calendar.getInstance();
|
||||
endLimit.set(Calendar.HOUR_OF_DAY, endHour);
|
||||
endLimit.set(Calendar.MINUTE, endMinute);
|
||||
endLimit.set(Calendar.SECOND, 0);
|
||||
endLimit.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
while (cursor.before(endLimit)) {
|
||||
int h = cursor.get(Calendar.HOUR_OF_DAY);
|
||||
int m = cursor.get(Calendar.MINUTE);
|
||||
String timeStr = String.format("%02d:%02d", h, m);
|
||||
|
||||
if (!isToday || h > currentHour || (h == currentHour && m > currentMinute)) {
|
||||
addSlot(slots, timeStr, bookedTimes);
|
||||
}
|
||||
|
||||
cursor.add(Calendar.MINUTE, 20);
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
android:textColor="@color/black"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<!-- 1. Selecionar Data -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -31,6 +32,40 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- 2. Selecionar Médico/Especialidade -->
|
||||
<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="4dp"
|
||||
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>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_doctor_schedule"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Horário: --"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/black"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:textStyle="italic"/>
|
||||
|
||||
<!-- 3. Selecionar Horário -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -46,28 +81,7 @@
|
||||
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>
|
||||
|
||||
<!-- 4. Motivo -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user