Fixed recurrence mapping bug

This commit is contained in:
Phillip Hsu 2016-06-01 17:23:35 -07:00
parent affab12f75
commit 4de02ed353
4 changed files with 18 additions and 15 deletions

View File

@ -58,7 +58,6 @@ public class DaysOfWeek {
}
/** @return the week day whose order is specified by {@code ordinalDay} */
// Compiler complains if annotated with @Day
public int weekDay(int ordinalDay) {
if (ordinalDay < 0 || ordinalDay > 6)
throw new ArrayIndexOutOfBoundsException("Ordinal day out of range");
@ -72,7 +71,7 @@ public class DaysOfWeek {
+ "}";
}
private DaysOfWeek(int firstDayOfWeek /*Compiler complains if annotated with @Day*/) {
private DaysOfWeek(int firstDayOfWeek) {
if (firstDayOfWeek != SATURDAY && firstDayOfWeek != SUNDAY && firstDayOfWeek != MONDAY)
throw new IllegalArgumentException("Invalid first day of week: " + firstDayOfWeek);
DAYS[0] = firstDayOfWeek;

View File

@ -95,11 +95,10 @@ public class AlarmViewHolder extends BaseViewHolder<Alarm> {
text = getContext().getString(R.string.every_day);
} else {
StringBuilder sb = new StringBuilder();
for (int i = 0; // ordinal number, i.e. the position in the week, not an actual day!
i < NUM_DAYS; i++) {
if (alarm.isRecurring(i)) { // Is the i-th day in the week recurring?
// This is the actual day at the i-th position in the week.
int weekDay = DaysOfWeek.getInstance(getContext()).weekDay(i);
for (int i = 0 /* Ordinal days*/; i < NUM_DAYS; i++) {
// What day is at this position in the week?
int weekDay = DaysOfWeek.getInstance(getContext()).weekDay(i);
if (alarm.isRecurring(weekDay)) {
sb.append(DaysOfWeek.getLabel(weekDay)).append(", ");
}
}

View File

@ -19,6 +19,8 @@ import java.util.Date;
import butterknife.Bind;
import butterknife.OnClick;
import static com.philliphsu.clock2.DaysOfWeek.SUNDAY;
public class EditAlarmActivity extends BaseActivity {
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
@ -45,7 +47,10 @@ public class EditAlarmActivity extends BaseActivity {
mSwitch.setChecked(alarm.isEnabled());
mTimeText.setText(DateFormat.getTimeFormat(this).format(new Date(alarm.ringsAt())));
for (int i = 0; i < mDays.length; i++) {
mDays[i].setChecked(alarm.isRecurring(i));
// What day is at this position in the week?
int weekDay = DaysOfWeek.getInstance(this).weekDay(i);
// We toggle the button at this position because it represents that day
mDays[i].setChecked(alarm.isRecurring(weekDay));
}
}
}
@ -69,7 +74,7 @@ public class EditAlarmActivity extends BaseActivity {
@OnClick(R.id.save)
void save() {
boolean[] days = new boolean[7];
days[0] = true;
days[SUNDAY] = true;
Alarm a = Alarm.builder()
.recurringDays(days)
.build();

View File

@ -107,7 +107,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAllCaps="true"
android:background="?selectableItemBackground"/>
/>
<ToggleButton
android:id="@+id/day2"
@ -115,7 +115,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAllCaps="true"
android:background="?selectableItemBackground"/>
/>
<ToggleButton
android:id="@+id/day3"
@ -123,7 +123,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAllCaps="true"
android:background="?selectableItemBackground"/>
/>
<ToggleButton
android:id="@+id/day4"
@ -131,7 +131,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAllCaps="true"
android:background="?selectableItemBackground"/>
/>
<ToggleButton
android:id="@+id/day5"
@ -139,7 +139,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAllCaps="true"
android:background="?selectableItemBackground"/>
/>
<ToggleButton
android:id="@+id/day6"
@ -147,7 +147,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAllCaps="true"
android:background="?selectableItemBackground"/>
/>
</LinearLayout>