From ad2e054802a1797bb1ae472a04e43de56ff7d09c Mon Sep 17 00:00:00 2001 From: Stephen L Date: Fri, 10 Nov 2023 04:53:54 +0100 Subject: [PATCH] feat: emphasize the date of events happening today in bold + bump v2.1 Signed-off-by: Stephen L. --- README.md | 10 +++--- app/build.gradle | 4 +-- .../polycalx/CalendarRemoteViewsFactory.java | 32 ++++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0539cdb..51ddca3 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,16 @@ This is a widget for Android to display the calendar/agenda in a concise text-based form factor. -It has two major differences that sets it apart from other similar widgets: +It has a few major differences that sets it apart from other similar widgets: * There is no repetition: when an event spans a long timeframe, it will just be shown once but stay in the list as long as it is still undergoing. For example, if an event starts on May, 1st, and ends May, 10th, then if today is May, 5th, the event will still be shown at the top of our list, shown as starting on May, 1st, and will stay there until May, 10th. This simple intuitive feature is essential in displaying the agenda - concisely. + concisely over days or weeks. +* Current day is not shown explicitly, but when an event starts happening exactly today, + the date is shown in bold. * Each line is color coded depending on the calendar the event is taken from. This is intended to be especially useful for people who must coordinate multiple calendars. @@ -49,5 +51,5 @@ This is a fork of the awesome [PolyCal](https://github.com/jasongyorog/PolyCal). ## Similar projects -* [Todo Agenda](https://github.com/andstatus/todoagenda) widget for Android. -* [MinCal](https://github.com/mvmike/min-cal-widget) widget for Android. +* [Todo Agenda](https://github.com/andstatus/todoagenda) widget for Android - if you prefer to distinctively separate events per day, this is the widget you need. +* [MinCal](https://github.com/mvmike/min-cal-widget) widget for Android - a concise monthly calendar, no title, only events counts are displayed. diff --git a/app/build.gradle b/app/build.gradle index 60324e2..052ba77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { minSdkVersion 24 compileSdk 33 targetSdkVersion 31 - versionCode 10 - versionName "2.0" + versionCode 11 + versionName "2.1" } buildTypes { diff --git a/app/src/main/java/org/lrq3000/polycalx/CalendarRemoteViewsFactory.java b/app/src/main/java/org/lrq3000/polycalx/CalendarRemoteViewsFactory.java index f05d4a7..cb5191a 100644 --- a/app/src/main/java/org/lrq3000/polycalx/CalendarRemoteViewsFactory.java +++ b/app/src/main/java/org/lrq3000/polycalx/CalendarRemoteViewsFactory.java @@ -7,11 +7,14 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.graphics.Color; +import android.graphics.Typeface; import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.provider.CalendarContract; +import android.text.SpannableString; import android.text.TextUtils; +import android.text.style.StyleSpan; import android.util.Log; import android.util.TypedValue; import android.widget.AdapterView; @@ -84,6 +87,9 @@ public int getCount() { return mCursor == null ? 0 : mCursor.getCount(); } + /** + * A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy. + */ @Override public RemoteViews getViewAt(int position) { Log.d(TAG, "RemoteViews getViewAt(" + position + ")"); @@ -114,7 +120,17 @@ public RemoteViews getViewAt(int position) { int other_color = Color.LTGRAY; - rv.setTextViewText(R.id.event_time, formatter.format(StartDate) ); + String formattedDate = formatter.format(StartDate); + long eventBeginTime = mCursor.getLong(EVENT_INDEX_BEGIN); + if (isEventToday(eventBeginTime)) { + // If the event is today, display the date/time in bold + SpannableString spanString = new SpannableString(formattedDate); + spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0); + rv.setTextViewText(R.id.event_time, spanString); + } else { + // Else, if the event is any other day than today, just display it without bold + rv.setTextViewText(R.id.event_time, formattedDate ); + } rv.setTextColor(R.id.event_time, other_color); rv.setTextViewTextSize(R.id.event_time, TypedValue.COMPLEX_UNIT_SP, text_size); @@ -139,6 +155,20 @@ public RemoteViews getViewAt(int position) { return rv; } + private boolean isEventToday(long eventBeginTime) { + Calendar today = Calendar.getInstance(); + today.set(Calendar.HOUR_OF_DAY, 0); + today.set(Calendar.MINUTE, 0); + today.set(Calendar.SECOND, 0); + today.set(Calendar.MILLISECOND, 0); + + Calendar eventDate = Calendar.getInstance(); + eventDate.setTimeInMillis(eventBeginTime); + + return today.get(Calendar.YEAR) == eventDate.get(Calendar.YEAR) && + today.get(Calendar.DAY_OF_YEAR) == eventDate.get(Calendar.DAY_OF_YEAR); + } + @Override public RemoteViews getLoadingView() { return null;