Skip to content

Commit

Permalink
feat: emphasize the date of events happening today in bold + bump v2.1
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen L. <LRQ3000@gmail.com>
  • Loading branch information
lrq3000 committed Nov 10, 2023
1 parent f763992 commit ad2e054
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
minSdkVersion 24
compileSdk 33
targetSdkVersion 31
versionCode 10
versionName "2.0"
versionCode 11
versionName "2.1"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + ")");
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit ad2e054

Please sign in to comment.