DaysOfWeek finished
This commit is contained in:
@@ -44,7 +44,7 @@ public class DaysOfWeek {
|
||||
sAppContext = context.getApplicationContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// TODO First day of week preference. Entries are the full days' names and values are their respective integers.
|
||||
String preferredFirstDay = prefs.getString("", "1");
|
||||
String preferredFirstDay = prefs.getString("", "0");
|
||||
if (sInstance == null || !preferredFirstDay.equals(sLastPreferredFirstDay)) {
|
||||
sLastPreferredFirstDay = preferredFirstDay;
|
||||
sInstance = new DaysOfWeek(Integer.parseInt(preferredFirstDay));
|
||||
@@ -59,7 +59,7 @@ public class DaysOfWeek {
|
||||
}
|
||||
|
||||
/** @return the week day at {@code position} within the user-defined week */
|
||||
public int weekDay(int position) {
|
||||
public int weekDayAt(int position) {
|
||||
if (position < 0 || position > 6)
|
||||
throw new ArrayIndexOutOfBoundsException("Ordinal day out of range");
|
||||
return DAYS[position];
|
||||
|
||||
@@ -97,7 +97,7 @@ public class AlarmViewHolder extends BaseViewHolder<Alarm> {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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);
|
||||
int weekDay = DaysOfWeek.getInstance(getContext()).weekDayAt(i);
|
||||
if (alarm.isRecurring(weekDay)) {
|
||||
sb.append(DaysOfWeek.getLabel(weekDay)).append(", ");
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.philliphsu.clock2.DaysOfWeek.SATURDAY;
|
||||
import static com.philliphsu.clock2.DaysOfWeek.SUNDAY;
|
||||
|
||||
public class EditAlarmActivity extends BaseActivity {
|
||||
@@ -46,11 +47,11 @@ public class EditAlarmActivity extends BaseActivity {
|
||||
if (alarm != null) {
|
||||
mSwitch.setChecked(alarm.isEnabled());
|
||||
mTimeText.setText(DateFormat.getTimeFormat(this).format(new Date(alarm.ringsAt())));
|
||||
for (int i = 0; i < mDays.length; 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));
|
||||
for (int i = SUNDAY; i <= SATURDAY; i++) {
|
||||
// What position in the week is this day located at?
|
||||
int at = DaysOfWeek.getInstance(this).positionOf(i);
|
||||
// Toggle the button that corresponds to this day
|
||||
mDays[at].setChecked(alarm.isRecurring(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +75,9 @@ public class EditAlarmActivity extends BaseActivity {
|
||||
@OnClick(R.id.save)
|
||||
void save() {
|
||||
boolean[] days = new boolean[7];
|
||||
days[SUNDAY] = true;
|
||||
days[0] = true;
|
||||
days[1] = true;
|
||||
days[6] = true;
|
||||
Alarm a = Alarm.builder()
|
||||
.recurringDays(days)
|
||||
.build();
|
||||
@@ -90,7 +93,7 @@ public class EditAlarmActivity extends BaseActivity {
|
||||
|
||||
private void setWeekDaysText() {
|
||||
for (int i = 0; i < mDays.length; i++) {
|
||||
int weekDay = DaysOfWeek.getInstance(this).weekDay(i);
|
||||
int weekDay = DaysOfWeek.getInstance(this).weekDayAt(i);
|
||||
String label = DaysOfWeek.getLabel(weekDay);
|
||||
mDays[i].setTextOn(label);
|
||||
mDays[i].setTextOff(label);
|
||||
|
||||
Reference in New Issue
Block a user