Skip to content

Commit

Permalink
Added info dialog for calendar entries
Browse files Browse the repository at this point in the history
  • Loading branch information
dgudim committed Oct 31, 2023
1 parent df5ff53 commit 4d07797
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,14 +62,17 @@ static class EntryViewHolder<V extends ViewBinding> 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;
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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")
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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) &&
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CalendarEntryInfoBinding, AlertDialog> { // 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private SystemCalendarUtils() throws InstantiationException {
Events._ID,
Events.CALENDAR_ID,
Events.TITLE,
Events.DESCRIPTION,
Events.DISPLAY_COLOR,
Events.DTSTART,
Events.DTEND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<prototype.xd.scheduler.views.DateSelectButton
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/layouts/dialogs/layout/calendar_entry_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/date"
style="@style/LargeHeadingSubtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/divider2" />

<com.google.android.material.divider.MaterialDivider
android:id="@+id/divider2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<string name="enable_per_day_wallpapers">Enable per day wallpapers</string>
<string name="dynamic_wallpaper_off_warning">You have selected a wallpaper for a single day but “per day wallpapers” is not enabled</string>
<string name="edit_group">Edit group</string>
<string name="no_description">This event has no description</string>
<string name="edit_group_message">The group will be renamed, no parameters will be changed</string>
<string name="add_group">Add group</string>
<string name="null_group_edit_message">Nothing to edit, assign a group first</string>
Expand Down

0 comments on commit 4d07797

Please sign in to comment.