Skip to content

Commit

Permalink
Use material 3 text input and date/time pickers (#81)
Browse files Browse the repository at this point in the history
* Store text fixes

* Using material views now
  • Loading branch information
Futsch1 authored Apr 14, 2024
1 parent 049cda8 commit 808e5b2
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void setupTimePicker() {
preference.setSummary(TimeHelper.minutesToTime(defaultSharedPreferences.getInt(WEEKEND_TIME, 540)));
preference.setOnPreferenceClickListener(preference1 -> {
int weekendTime = defaultSharedPreferences.getInt(WEEKEND_TIME, 540);
new TimeHelper.TimePickerWrapper(requireContext()).show(weekendTime / 60, weekendTime % 60, minutes -> {
new TimeHelper.TimePickerWrapper(getActivity()).show(weekendTime / 60, weekendTime % 60, minutes -> {
defaultSharedPreferences.edit().putInt(WEEKEND_TIME, minutes).apply();
preference1.setSummary(TimeHelper.minutesToTime(minutes));
requestReschedule();
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/java/com/futsch1/medtimer/helpers/TimeHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.futsch1.medtimer.helpers;

import android.app.TimePickerDialog;
import android.content.Context;
import android.text.format.DateFormat;

import androidx.fragment.app.FragmentActivity;

import com.google.android.material.timepicker.MaterialTimePicker;
import com.google.android.material.timepicker.TimeFormat;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -28,15 +31,23 @@ public interface TimePickerResult {
}

public static class TimePickerWrapper {
Context context;
FragmentActivity activity;

public TimePickerWrapper(Context context) {
this.context = context;
public TimePickerWrapper(FragmentActivity activity) {
this.activity = activity;
}

public void show(int hourOfDay, int minute, TimePickerResult timePickerResult) {
TimePickerDialog timePickerDialog = new TimePickerDialog(context, (view, hourOfDayLocal, minuteLocal) -> timePickerResult.onTimeSelected(hourOfDayLocal * 60 + minuteLocal), hourOfDay, minute, DateFormat.is24HourFormat(context));
timePickerDialog.show();
MaterialTimePicker timePickerDialog = new MaterialTimePicker.Builder()
.setTimeFormat(DateFormat.is24HourFormat(activity) ? TimeFormat.CLOCK_24H : TimeFormat.CLOCK_12H)
.setHour(hourOfDay)
.setMinute(minute)
.setInputMode(MaterialTimePicker.INPUT_MODE_CLOCK)
.build();

timePickerDialog.addOnPositiveButtonClickListener(view -> timePickerResult.onTimeSelected(timePickerDialog.getHour() * 60 + timePickerDialog.getMinute()));

timePickerDialog.show(activity.getSupportFragmentManager(), "time_picker");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.format.DateUtils;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
Expand All @@ -21,7 +21,9 @@
import com.futsch1.medtimer.R;
import com.futsch1.medtimer.database.Reminder;
import com.futsch1.medtimer.helpers.TimeHelper;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.datepicker.MaterialDatePicker;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -34,8 +36,8 @@ public class AdvancedReminderSettings extends AppCompatActivity {
private EditText editConsecutiveDays;
private EditText editPauseDays;
private EditText editCycleStartDate;
private EditText editInstructions;
private MaterialButton instructionSuggestions;
private TextInputEditText editInstructions;
private TextInputLayout instructionSuggestions;
private MedicineViewModel medicineViewModel;
private Reminder reminder;
private TextView remindOnDays;
Expand Down Expand Up @@ -73,7 +75,7 @@ private void setupView() {
editConsecutiveDays = findViewById(R.id.consecutiveDays);
editCycleStartDate = findViewById(R.id.cycleStartDate);
editInstructions = findViewById(R.id.editInstructions);
instructionSuggestions = findViewById(R.id.instructionSuggestions);
instructionSuggestions = findViewById(R.id.editInstructionsLayout);
remindOnDays = findViewById(R.id.remindOnDays);

editConsecutiveDays.setText(Integer.toString(reminder.consecutiveDays));
Expand All @@ -90,7 +92,7 @@ private void setupView() {
}

private void setupInstructionSuggestions() {
instructionSuggestions.setOnClickListener(v -> {
instructionSuggestions.setEndIconOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.instruction_templates);
builder.setItems(R.array.instructions_suggestions, (dialog, which) -> {
Expand Down Expand Up @@ -140,11 +142,14 @@ private void setupCycleStartDate() {
editCycleStartDate.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
LocalDate startDate = LocalDate.ofEpochDay(reminder.cycleStartDay);
DatePickerDialog datePickerDialog = new DatePickerDialog(this, (view, year, month, dayOfMonth) -> {
reminder.cycleStartDay = LocalDate.of(year, month, dayOfMonth).toEpochDay();
MaterialDatePicker<Long> datePickerDialog = MaterialDatePicker.Builder.datePicker()
.setSelection(startDate.toEpochDay() * DateUtils.DAY_IN_MILLIS)
.build();
datePickerDialog.addOnPositiveButtonClickListener(selectedDate -> {
reminder.cycleStartDay = selectedDate / DateUtils.DAY_IN_MILLIS;
setCycleStartDate();
}, startDate.getYear(), startDate.getMonthValue(), startDate.getDayOfMonth());
datePickerDialog.show();
});
datePickerDialog.show(getSupportFragmentManager(), "date_picker");
}
});
}
Expand Down Expand Up @@ -182,7 +187,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
protected void onDestroy() {
super.onDestroy();

reminder.instructions = editInstructions.getText().toString();
reminder.instructions = editInstructions.getText() != null ? editInstructions.getText().toString() : "";
try {
reminder.consecutiveDays = Integer.parseInt(editConsecutiveDays.getText().toString());
if (reminder.consecutiveDays <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
String medicineName = getIntent().getStringExtra(EXTRA_MEDICINE_NAME);

RecyclerView recyclerView = findViewById(R.id.reminderList);
adapter = new ReminderViewAdapter(new ReminderViewAdapter.ReminderDiff(), EditMedicine.this::deleteItem, medicineName);
adapter = new ReminderViewAdapter(new ReminderViewAdapter.ReminderDiff(), EditMedicine.this::deleteItem, medicineName, this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;

Expand All @@ -13,11 +14,16 @@ public class ReminderViewAdapter extends ListAdapter<Reminder, ReminderViewHolde

private final ReminderViewHolder.DeleteCallback deleteCallback;
private final String medicineName;
private final FragmentActivity fragmentActivity;

public ReminderViewAdapter(@NonNull DiffUtil.ItemCallback<Reminder> diffCallback, ReminderViewHolder.DeleteCallback deleteCallback, String medicineName) {
public ReminderViewAdapter(@NonNull DiffUtil.ItemCallback<Reminder> diffCallback,
ReminderViewHolder.DeleteCallback deleteCallback,
String medicineName,
FragmentActivity fragmentActivity) {
super(diffCallback);
this.deleteCallback = deleteCallback;
this.medicineName = medicineName;
this.fragmentActivity = fragmentActivity;
setHasStableIds(true);
}

Expand All @@ -26,7 +32,7 @@ public ReminderViewAdapter(@NonNull DiffUtil.ItemCallback<Reminder> diffCallback
@NonNull
@Override
public ReminderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return ReminderViewHolder.create(parent);
return ReminderViewHolder.create(parent, fragmentActivity);
}

// Replace the contents of a view (invoked by the layout manager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.EditText;
import android.widget.PopupMenu;

import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;

Expand All @@ -27,22 +28,25 @@ public class ReminderViewHolder extends RecyclerView.ViewHolder {
private final EditText editAmount;
private final View holderItemView;
private final MaterialButton advancedSettings;
private final FragmentActivity fragmentActivity;

private Reminder reminder;


private ReminderViewHolder(View itemView) {
private ReminderViewHolder(View itemView, FragmentActivity fragmentActivity) {
super(itemView);
editTime = itemView.findViewById(R.id.editReminderTime);
editAmount = itemView.findViewById(R.id.editAmount);
advancedSettings = itemView.findViewById(R.id.open_advanced_settings);

this.holderItemView = itemView;
this.fragmentActivity = fragmentActivity;
}

static ReminderViewHolder create(ViewGroup parent) {
static ReminderViewHolder create(ViewGroup parent, FragmentActivity fragmentActivity) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_reminder, parent, false);
return new ReminderViewHolder(view);
return new ReminderViewHolder(view, fragmentActivity);
}

@SuppressLint("SetTextI18n")
Expand All @@ -53,7 +57,7 @@ public void bind(Reminder reminder, String medicineName, DeleteCallback deleteCa

editTime.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
new TimeHelper.TimePickerWrapper(editTime.getContext()).show(reminder.timeInMinutes / 60, reminder.timeInMinutes % 60, minutes -> {
new TimeHelper.TimePickerWrapper(fragmentActivity).show(reminder.timeInMinutes / 60, reminder.timeInMinutes % 60, minutes -> {
String selectedTime = minutesToTime(minutes);
editTime.setText(selectedTime);
reminder.timeInMinutes = minutes;
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/play/listings/de-DE/full-description.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
Behalten Sie die Kontrolle über Ihre Medikamente mit MedTimer
Behalten Sie den Überblick über Ihre Medikamente mit MedTimer

MedTimer ist eine Open-Source App zur Erinnerung an die Einnahme von Medikamenten, mit der Sie Ihre
Medikamente effektiv und mit voller Kontrolle über Ihre sensiblen Daten zu verwalten.
MedTimer ist eine Open-Source App zur Erinnerung an die Einnahme von Medikamenten, mit der Sie Ihre Medikamente effektiv und mit voller Kontrolle über Ihre sensiblen Daten zu verwalten.

Flexible und personalisierte Erinnerungen:

- Verwalten eine unbegrenzte Anzahl Medikamente mit individuellen Erinnerungen pro Medikament
(mit einfacher Standardeinstellung für tägliche Erinnerungen).
- Verwalten eine unbegrenzte Anzahl Medikamente mit individuellen Erinnerungen pro Medikament (mit einfacher Standardeinstellung für tägliche Erinnerungen).
- Erstelle flexible Erinnerungen mit Pausen und nur für bestimmten Tage (z.B. für die Antibabypille).
- Wochenendmodus: Verschiebe Erinnerungen an wählbaren Tagen auf eine festgelegte Uhrzeit.
- Verschiebe ("snooze") Benachrichtigungen um später erneut erinnert zu werden.
Expand All @@ -15,14 +13,12 @@ Flexible und personalisierte Erinnerungen:
Einfache und sichere Datenverwaltung:

- Bestätige oder verwerfe Erinnerungen, um die Medikamenteneinnahme genau zu erfassen.
- Exportiere deine Medikamentenhistorie als CSV-Datei für eine einfache Aufzeichnung oder Weitergabe
an medizinisches Fachpersonal.
- Exportiere deine Medikamentenhistorie als CSV-Datei für eine einfache Aufzeichnung oder Weitergabe an medizinisches Fachpersonal.
- Sichern und Wiederherstellen deiner Medikamentenliste als JSON-Datei.

Datenschutz und Offline-Zugriff:

- Alle Daten werden sicher auf Ihrem Gerät gespeichert, so dass ein vollständiger Datenschutz und
Offline-Zugriff gewährleistet ist.
- Alle Daten werden sicher auf Ihrem Gerät gespeichert, so dass ein vollständiger Datenschutz und Offline-Zugriff gewährleistet ist.
- Keine Internetverbindung erforderlich - deine Medikamentenerinnerungen sind immer verfügbar.

MedTimer ist eine kostenlose, werbefreie App.
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/play/listings/en-US/full-description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ MedTimer is an open-source medication reminder app designed to help you manage y

Flexible & Personalized Reminders:

- Manage unlimited medications with customizable reminders per medication (including simple defaults
for daily reminders).
- Manage unlimited medications with customizable reminders per medication (including simple defaults for daily reminders).
- Create flexible reminders with breaks and specific days (e.g. for birth control pills).
- Weekend mode: Delay reminders to a defined time on chosen days.
- Snooze notifications for later reminders.
Expand All @@ -16,8 +15,7 @@ for daily reminders).
Simple & Secure Data Management:

- Confirm or dismiss reminders to record medication adherence accurately.
- Export your medication history as a CSV file for easy record-keeping or sharing with healthcare
professionals.
- Export your medication history as a CSV file for easy record-keeping or sharing with healthcare professionals.
- Backup and restore your medication list as JSON file.

Privacy & Offline Accessibility:
Expand Down
14 changes: 4 additions & 10 deletions app/src/main/play/listings/es-ES/full-description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@ Historial y recordatorios de medicación con total privacidad offline

Controle su medicación con MedTimer

MedTimer es una aplicación de código abierto que permite asignar recordatorios de medicación,
diseñada para ayudarte a gestionar tus medicamentos de forma eficaz mientras mantienes el control
total de tus datos confidenciales.
MedTimer es una aplicación de código abierto que permite asignar recordatorios de medicación, diseñada para ayudarte a gestionar tus medicamentos de forma eficaz mientras mantienes el control total de tus datos confidenciales.

Recordatorios flexibles y personalizados:

- Añade un número ilimitado de medicamentos con múltiples recordatorios por medicamento.
- Configure recordatorios complejos con días consecutivos y de pausa (por ejemplo, para píldoras
anticonceptivas)
o limitados a determinados días de la semana.
- Configure recordatorios complejos con días consecutivos y de pausa (por ejemplo, para píldoras anticonceptivas) o limitados a determinados días de la semana.
- Modo fin de semana que retrasa los recordatorios hasta una hora definida en días seleccionables.
- Posponer ("snooze") notificaciones para ser recordado más tarde.
- Añade dosis adicionales no planificadas.

Gestión de datos sencilla y segura:

- Confirma o descarta los recordatorios para registrar con precisión el seguimiento de la medicación.
- Puedes exportar tu historial de medicación como un archivo CSV para facilitar el mantenimiento de
registros o compartirlo con profesionales de la salud.
- Puedes exportar tu historial de medicación como un archivo CSV para facilitar el mantenimiento de registros o compartirlo con profesionales de la salud.
- Haz una copia de seguridad y restaura tu lista de medicamentos como archivo JSON.

Privacidad y accesibilidad sin conexión:

- Todos los datos se almacenan de forma segura en tu dispositivo, lo que garantiza una total
privacidad y accesibilidad sin conexión.
- Todos los datos se almacenan de forma segura en tu dispositivo, lo que garantiza una total privacidad y accesibilidad sin conexión.
- No requiere conexión a Internet - tus recordatorios de medicación están siempre disponibles.

MedTimer es una aplicación gratuita sin anuncios.
Expand Down
16 changes: 5 additions & 11 deletions app/src/main/play/listings/fr-FR/full-description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@ médicaments efficacement et avec un contrôle total sur vos données sensibles.

Flexible et flexible rappels personnalisés:

- Gestion d'un nombre illimité de médicaments avec des rappels personnalisables par médicament
(y compris des valeurs par défaut simples pour les rappels quotidiens).
- Gestion d'un nombre illimité de médicaments avec des rappels personnalisables par médicament (y compris des valeurs par défaut simples pour les rappels quotidiens).
pour les rappels quotidiens).
- Créez des rappels flexibles avec des pauses et des jours spécifiques (idéal pour les pilules
contraceptives).
médicaments).
- Créez des rappels flexibles avec des pauses et des jours spécifiques (idéal pour les pilules contraceptives).
- Mode week-end : Retardez les rappels à une heure définie les jours choisis.
- Répétez les notifications pour les rappels ultérieurs.
- Ajoutez des doses supplémentaires à la volée.

Simple et efficace Gestion sécurisée des données:

- Confirmez ou rejetez les rappels pour enregistrer avec précision l'observance du traitement.
- Exportez votre historique de médicaments sous forme de fichier CSV pour faciliter la tenue de
dossiers ou le partage avec les soins de santé
professionnels.
- Exportez votre historique de médicaments sous forme de fichier CSV pour faciliter la tenue de dossiers ou le partage avec les soins de santé professionnels.
- Sauvegardez et restaurez votre liste de médicaments sous forme de fichier JSON.

Confidentialité et confidentialité Accessibilité hors ligne:

- Toutes les données sont stockées en toute sécurité sur votre appareil, garantissant une
confidentialité totale et une accessibilité hors ligne.
- Aucune connexion Internet requise – vos rappels de médicaments sont toujours disponibles.
- Toutes les données sont stockées en toute sécurité sur votre appareil, garantissant une confidentialité totale et une accessibilité hors ligne.
- Aucune connexion Internet requise – vos rappels de médicaments sont toujours disponibles.

MedTimer est une application gratuite sans ajout.

Expand Down
Loading

0 comments on commit 808e5b2

Please sign in to comment.