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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user