Fixed recurrence mapping bug
This commit is contained in:
parent
affab12f75
commit
4de02ed353
@ -58,7 +58,6 @@ public class DaysOfWeek {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return the week day whose order is specified by {@code ordinalDay} */
|
/** @return the week day whose order is specified by {@code ordinalDay} */
|
||||||
// Compiler complains if annotated with @Day
|
|
||||||
public int weekDay(int ordinalDay) {
|
public int weekDay(int ordinalDay) {
|
||||||
if (ordinalDay < 0 || ordinalDay > 6)
|
if (ordinalDay < 0 || ordinalDay > 6)
|
||||||
throw new ArrayIndexOutOfBoundsException("Ordinal day out of range");
|
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)
|
if (firstDayOfWeek != SATURDAY && firstDayOfWeek != SUNDAY && firstDayOfWeek != MONDAY)
|
||||||
throw new IllegalArgumentException("Invalid first day of week: " + firstDayOfWeek);
|
throw new IllegalArgumentException("Invalid first day of week: " + firstDayOfWeek);
|
||||||
DAYS[0] = firstDayOfWeek;
|
DAYS[0] = firstDayOfWeek;
|
||||||
|
|||||||
@ -95,11 +95,10 @@ public class AlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
text = getContext().getString(R.string.every_day);
|
text = getContext().getString(R.string.every_day);
|
||||||
} else {
|
} else {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; // ordinal number, i.e. the position in the week, not an actual day!
|
for (int i = 0 /* Ordinal days*/; i < NUM_DAYS; i++) {
|
||||||
i < NUM_DAYS; i++) {
|
// What day is at this position in the week?
|
||||||
if (alarm.isRecurring(i)) { // Is the i-th day in the week recurring?
|
int weekDay = DaysOfWeek.getInstance(getContext()).weekDay(i);
|
||||||
// This is the actual day at the i-th position in the week.
|
if (alarm.isRecurring(weekDay)) {
|
||||||
int weekDay = DaysOfWeek.getInstance(getContext()).weekDay(i);
|
|
||||||
sb.append(DaysOfWeek.getLabel(weekDay)).append(", ");
|
sb.append(DaysOfWeek.getLabel(weekDay)).append(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,8 @@ import java.util.Date;
|
|||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
import static com.philliphsu.clock2.DaysOfWeek.SUNDAY;
|
||||||
|
|
||||||
public class EditAlarmActivity extends BaseActivity {
|
public class EditAlarmActivity extends BaseActivity {
|
||||||
|
|
||||||
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
|
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());
|
mSwitch.setChecked(alarm.isEnabled());
|
||||||
mTimeText.setText(DateFormat.getTimeFormat(this).format(new Date(alarm.ringsAt())));
|
mTimeText.setText(DateFormat.getTimeFormat(this).format(new Date(alarm.ringsAt())));
|
||||||
for (int i = 0; i < mDays.length; i++) {
|
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)
|
@OnClick(R.id.save)
|
||||||
void save() {
|
void save() {
|
||||||
boolean[] days = new boolean[7];
|
boolean[] days = new boolean[7];
|
||||||
days[0] = true;
|
days[SUNDAY] = true;
|
||||||
Alarm a = Alarm.builder()
|
Alarm a = Alarm.builder()
|
||||||
.recurringDays(days)
|
.recurringDays(days)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@ -107,7 +107,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:background="?selectableItemBackground"/>
|
/>
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/day2"
|
android:id="@+id/day2"
|
||||||
@ -115,7 +115,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:background="?selectableItemBackground"/>
|
/>
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/day3"
|
android:id="@+id/day3"
|
||||||
@ -123,7 +123,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:background="?selectableItemBackground"/>
|
/>
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/day4"
|
android:id="@+id/day4"
|
||||||
@ -131,7 +131,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:background="?selectableItemBackground"/>
|
/>
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/day5"
|
android:id="@+id/day5"
|
||||||
@ -139,7 +139,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:background="?selectableItemBackground"/>
|
/>
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/day6"
|
android:id="@+id/day6"
|
||||||
@ -147,7 +147,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:background="?selectableItemBackground"/>
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user