From 4d07797f4ec49caa51bcffd6137383b052cf92d1 Mon Sep 17 00:00:00 2001 From: kloud Date: Tue, 31 Oct 2023 19:58:10 +0200 Subject: [PATCH] Added info dialog for calendar entries --- .../adapters/TodoListViewAdapter.java | 17 ++++-- .../entities/SystemCalendarEventData.java | 13 +++-- .../CalendarEventInfoDialogFragment.java | 52 +++++++++++++++++++ .../utilities/SystemCalendarUtils.java | 1 + .../layout/add_edit_entry_dialog_fragment.xml | 2 +- .../dialogs/layout/calendar_entry_info.xml | 26 ++++++++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/prototype/xd/scheduler/fragments/dialogs/CalendarEventInfoDialogFragment.java create mode 100644 app/src/main/res/layouts/dialogs/layout/calendar_entry_info.xml diff --git a/app/src/main/java/prototype/xd/scheduler/adapters/TodoListViewAdapter.java b/app/src/main/java/prototype/xd/scheduler/adapters/TodoListViewAdapter.java index 0c7b41d3..361e70c0 100644 --- a/app/src/main/java/prototype/xd/scheduler/adapters/TodoListViewAdapter.java +++ b/app/src/main/java/prototype/xd/scheduler/adapters/TodoListViewAdapter.java @@ -35,6 +35,7 @@ import prototype.xd.scheduler.entities.Group; import prototype.xd.scheduler.entities.TodoEntry; import prototype.xd.scheduler.fragments.dialogs.AddEditEntryDialogFragment; +import prototype.xd.scheduler.fragments.dialogs.CalendarEventInfoDialogFragment; import prototype.xd.scheduler.utilities.DialogUtilities; import prototype.xd.scheduler.utilities.Static; import prototype.xd.scheduler.utilities.TodoEntryManager; @@ -61,14 +62,17 @@ static class EntryViewHolder extends RecyclerView.ViewHol private final ContextWrapper wrapper; private final AddEditEntryDialogFragment addEditEntryDialog; + private final CalendarEventInfoDialogFragment calendarEventInfoDialog; EntryViewHolder(@NonNull final V viewBinding, @NonNull final ContextWrapper wrapper, - @NonNull final AddEditEntryDialogFragment addEditEntryDialog) { + @NonNull final AddEditEntryDialogFragment addEditEntryDialog, + @NonNull final CalendarEventInfoDialogFragment calendarEventInfoDialog) { super(viewBinding.getRoot()); this.viewBinding = viewBinding; this.wrapper = wrapper; this.addEditEntryDialog = addEditEntryDialog; + this.calendarEventInfoDialog = calendarEventInfoDialog; } /** @@ -133,13 +137,16 @@ private void bindToSystemCalendarEntry(@NonNull final TodoEntry entry, bnd.timeText.setTextColor(getHarmonizedSecondaryFontColorWithBg( entry.fontColor.get(currentlySelectedDayUTC), entry.bgColor.get(currentlySelectedDayUTC))); - + // open calendar settings on settings icon click and on entry long click bnd.openSettingsButton.setOnClickListener(v -> systemCalendarSettings.show(entry.event, wrapper)); bnd.backgroundLayer.setOnLongClickListener(v -> { systemCalendarSettings.show(entry.event, wrapper); return true; }); + + // Open event info on entry click + bnd.backgroundLayer.setOnClickListener(v -> calendarEventInfoDialog.show(entry, wrapper)); } /** @@ -254,6 +261,7 @@ void bindTo(@NonNull final TodoEntry currentEntry, private final ContextWrapper wrapper; public final AddEditEntryDialogFragment addEditEntryDialog; + public final CalendarEventInfoDialogFragment calendarEventInfoDialog; // default capacity is fine @SuppressWarnings("CollectionWithoutInitialCapacity") @@ -266,6 +274,7 @@ public TodoListViewAdapter(@NonNull final ContextWrapper wrapper, entrySettings = new EntrySettings(todoEntryManager); systemCalendarSettings = new SystemCalendarSettings(todoEntryManager); addEditEntryDialog = new AddEditEntryDialogFragment(); + calendarEventInfoDialog = new CalendarEventInfoDialogFragment(); // each entry has a unique id setHasStableIds(true); } @@ -297,12 +306,12 @@ public EntryViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, in // calendar entry return new EntryViewHolder<>( ListSelectionCalendarBinding.inflate(wrapper.getLayoutInflater(), parent, false), - wrapper, addEditEntryDialog); + wrapper, addEditEntryDialog, calendarEventInfoDialog); } else { // regular entry return new EntryViewHolder<>( ListSelectionTodoBinding.inflate(wrapper.getLayoutInflater(), parent, false), - wrapper, addEditEntryDialog); + wrapper, addEditEntryDialog, calendarEventInfoDialog); } } diff --git a/app/src/main/java/prototype/xd/scheduler/entities/SystemCalendarEventData.java b/app/src/main/java/prototype/xd/scheduler/entities/SystemCalendarEventData.java index 747c8f2b..d73eea63 100644 --- a/app/src/main/java/prototype/xd/scheduler/entities/SystemCalendarEventData.java +++ b/app/src/main/java/prototype/xd/scheduler/entities/SystemCalendarEventData.java @@ -23,10 +23,11 @@ public class SystemCalendarEventData { public static final String NAME = SystemCalendarEvent.class.getSimpleName(); - final long id; + protected final long id; @Nullable - protected String title; + public final String title; + public final String description; @ColorInt public final int color; @@ -51,8 +52,9 @@ public SystemCalendarEventData(@NonNull Cursor cursor) { color = getInt(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.DISPLAY_COLOR); id = getLong(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events._ID); - - title = getString(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.TITLE).trim(); + + title = getString(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.TITLE); + description = getString(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.DESCRIPTION); refStartMsUTC = getLong(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.DTSTART); refEndMsUTC = getLong(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.DTEND); allDay = getBoolean(cursor, CALENDAR_EVENT_COLUMNS, CalendarContract.Events.ALL_DAY); @@ -87,6 +89,7 @@ public boolean equals(Object o) { refEndMsUTC == event.refEndMsUTC && allDay == event.allDay && Objects.equals(title, event.title) && + Objects.equals(description, event.description) && Objects.equals(rRuleStr, event.rRuleStr) && Objects.equals(rDateStr, event.rDateStr) && Objects.equals(exRuleStr, event.exRuleStr) && @@ -98,7 +101,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(id, title, color, + return Objects.hash(id, title, description, color, refStartMsUTC, refEndMsUTC, allDay, rRuleStr, rDateStr, exRuleStr, exDateStr, durationStr, timeZoneId, exceptions); diff --git a/app/src/main/java/prototype/xd/scheduler/fragments/dialogs/CalendarEventInfoDialogFragment.java b/app/src/main/java/prototype/xd/scheduler/fragments/dialogs/CalendarEventInfoDialogFragment.java new file mode 100644 index 00000000..b4b49136 --- /dev/null +++ b/app/src/main/java/prototype/xd/scheduler/fragments/dialogs/CalendarEventInfoDialogFragment.java @@ -0,0 +1,52 @@ +package prototype.xd.scheduler.fragments.dialogs; + +import static prototype.xd.scheduler.utilities.DateManager.currentlySelectedDayUTC; + +import android.view.LayoutInflater; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; + +import prototype.xd.scheduler.R; +import prototype.xd.scheduler.databinding.CalendarEntryInfoBinding; +import prototype.xd.scheduler.entities.TodoEntry; +import prototype.xd.scheduler.utilities.misc.ContextWrapper; + +public class CalendarEventInfoDialogFragment extends BaseCachedDialogFragment { // NOSONAR This is a fragment + + private TodoEntry entry; + + public void show(@Nullable TodoEntry entry, + @NonNull ContextWrapper wrapper) { + this.entry = entry; + show(wrapper.fragmentManager, entry + " info"); + } + + @Override + protected void buildDialogStatic(@NonNull CalendarEntryInfoBinding binding, @NonNull AlertDialog dialog) { + dialog.setIcon(R.drawable.ic_info_24); + } + + @Override + protected void buildDialogDynamic(@NonNull CalendarEntryInfoBinding binding, @NonNull AlertDialog dialog) { + dialog.setTitle(entry.event.data.title); + String desc = entry.event.data.description; + dialog.setMessage(desc.isEmpty() ? wrapper.getString(R.string.no_description) : desc); + binding.date.setText(entry.getCalendarEntryTimeSpan(wrapper.context, currentlySelectedDayUTC)); + } + + @NonNull + @Override + protected CalendarEntryInfoBinding inflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { + return CalendarEntryInfoBinding.inflate(inflater, container, false); + } + + @NonNull + @Override + protected AlertDialog buildDialog() { + return getAlertDialog(); + } + +} diff --git a/app/src/main/java/prototype/xd/scheduler/utilities/SystemCalendarUtils.java b/app/src/main/java/prototype/xd/scheduler/utilities/SystemCalendarUtils.java index 126eb9fc..a441c42e 100644 --- a/app/src/main/java/prototype/xd/scheduler/utilities/SystemCalendarUtils.java +++ b/app/src/main/java/prototype/xd/scheduler/utilities/SystemCalendarUtils.java @@ -54,6 +54,7 @@ private SystemCalendarUtils() throws InstantiationException { Events._ID, Events.CALENDAR_ID, Events.TITLE, + Events.DESCRIPTION, Events.DISPLAY_COLOR, Events.DTSTART, Events.DTEND, diff --git a/app/src/main/res/layouts/dialogs/layout/add_edit_entry_dialog_fragment.xml b/app/src/main/res/layouts/dialogs/layout/add_edit_entry_dialog_fragment.xml index 98df4333..8a946270 100644 --- a/app/src/main/res/layouts/dialogs/layout/add_edit_entry_dialog_fragment.xml +++ b/app/src/main/res/layouts/dialogs/layout/add_edit_entry_dialog_fragment.xml @@ -90,7 +90,7 @@ app:layout_constraintBottom_toBottomOf="@+id/day_from_button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/divider" + app:layout_constraintTop_toTopOf="@+id/day_from_button" app:srcCompat="@drawable/ic_arrow_right_24" /> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be6d57db..f3962a02 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -92,6 +92,7 @@ Enable per day wallpapers You have selected a wallpaper for a single day but “per day wallpapers” is not enabled Edit group + This event has no description The group will be renamed, no parameters will be changed Add group Nothing to edit, assign a group first