Skip to content

Commit

Permalink
#42 Right align numbers of days from today in a Single line layout
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Mar 27, 2017
1 parent a94ac4b commit 0d30ad1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/calendar-widget/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
dependencies {
compile 'joda-time:joda-time:2.9.7'
compile 'com.larswerkman:HoloColorPicker:1.5'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,27 @@ protected String getTitleString(Context context, CalendarEntry event) {
protected void setEventDate(Context context, CalendarEntry entry, RemoteViews rv) {
if (CalendarPreferences.getShowDayHeaders(context)) {
rv.setViewVisibility(R.id.event_entry_date, View.GONE);
rv.setViewVisibility(R.id.event_entry_date_right, View.GONE);
} else {
rv.setViewVisibility(R.id.event_entry_date, View.VISIBLE);
rv.setTextViewText(R.id.event_entry_date, entry.getDateString(context));
int days = entry.getDaysFromToday();
int viewToShow = days < -1 || days > 1 ? R.id.event_entry_date_right : R.id.event_entry_date;
int viewToHide = viewToShow == R.id.event_entry_date? R.id.event_entry_date_right : R.id.event_entry_date;
rv.setViewVisibility(viewToHide, View.GONE);
rv.setViewVisibility(viewToShow, View.VISIBLE);
rv.setTextViewText(viewToShow, getDaysFromTodayString(context, days));
}
}

private CharSequence getDaysFromTodayString(Context context, int daysFromToday) {
switch (daysFromToday) {
case -1:
return context.getText(R.string.yesterday);
case 0:
return context.getText(R.string.today);
case 1:
return context.getText(R.string.tomorrow);
default:
return Integer.toString(daysFromToday);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@ public String toString() {
return this.getClass().getSimpleName() + " [startDate=" + startDate + "]";
}

public CharSequence getDateString(Context context) {
Days days = Days.daysBetween(DateUtil.now().withTimeAtStartOfDay(), startDate.withTimeAtStartOfDay());
switch (days.getDays()) {
case -1:
return context.getText(R.string.yesterday);
case 0:
return context.getText(R.string.today);
case 1:
return context.getText(R.string.tomorrow);
default:
return Integer.toString(days.getDays());
}
public int getDaysFromToday() {
return Days.daysBetween(DateUtil.now().withTimeAtStartOfDay(), startDate.withTimeAtStartOfDay()).getDays();
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions app/calendar-widget/src/main/res/layout/event_entry_one_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
tools:ignore="SelectableText"
tools:text="@string/today"/>

<TextView
android:id="@+id/event_entry_date_right"
style="@style/EventEntryTitle"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="end"
android:textAlignment="gravity"
android:paddingRight="12dp"
tools:ignore="SelectableText"
tools:text="-325"/>

<TextView
android:id="@+id/event_entry_time"
style="@style/EventEntryDetails"
Expand Down

0 comments on commit 0d30ad1

Please sign in to comment.