Commit before bug fixing of alarm recurrence and DaysOfWeek
This commit is contained in:
parent
e80596060b
commit
affab12f75
@ -43,7 +43,7 @@ public class DaysOfWeek {
|
|||||||
sAppContext = context.getApplicationContext();
|
sAppContext = context.getApplicationContext();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
// TODO First day of week preference. Entries are the full days' names and values are their respective integers.
|
// TODO First day of week preference. Entries are the full days' names and values are their respective integers.
|
||||||
String preferredFirstDay = prefs.getString("", "6");
|
String preferredFirstDay = prefs.getString("", "1");
|
||||||
if (sInstance == null || !preferredFirstDay.equals(sLastPreferredFirstDay)) {
|
if (sInstance == null || !preferredFirstDay.equals(sLastPreferredFirstDay)) {
|
||||||
sLastPreferredFirstDay = preferredFirstDay;
|
sLastPreferredFirstDay = preferredFirstDay;
|
||||||
sInstance = new DaysOfWeek(Integer.parseInt(preferredFirstDay));
|
sInstance = new DaysOfWeek(Integer.parseInt(preferredFirstDay));
|
||||||
|
|||||||
@ -57,7 +57,7 @@ public class MainActivity extends BaseActivity implements AlarmsFragment.OnAlarm
|
|||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
startActivity(new Intent(MainActivity.this, EditAlarmActivity.class));
|
startEditAlarmActivity(-1);
|
||||||
/*
|
/*
|
||||||
scheduleAlarm();
|
scheduleAlarm();
|
||||||
Snackbar.make(view, "Alarm set for 1 minute from now", Snackbar.LENGTH_INDEFINITE)
|
Snackbar.make(view, "Alarm set for 1 minute from now", Snackbar.LENGTH_INDEFINITE)
|
||||||
@ -78,6 +78,8 @@ public class MainActivity extends BaseActivity implements AlarmsFragment.OnAlarm
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int layoutResId() {
|
protected int layoutResId() {
|
||||||
return R.layout.activity_main;
|
return R.layout.activity_main;
|
||||||
@ -183,7 +185,13 @@ public class MainActivity extends BaseActivity implements AlarmsFragment.OnAlarm
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemInteraction(Alarm item) {
|
public void onListItemInteraction(Alarm item) {
|
||||||
startActivity(new Intent(this, EditAlarmActivity.class));
|
startEditAlarmActivity(item.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startEditAlarmActivity(long alarmId) {
|
||||||
|
Intent intent = new Intent(this, EditAlarmActivity.class);
|
||||||
|
intent.putExtra(EditAlarmActivity.EXTRA_ALARM_ID, alarmId);
|
||||||
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleAlarm() {
|
private void scheduleAlarm() {
|
||||||
|
|||||||
@ -38,8 +38,7 @@ public class DummyContent {
|
|||||||
b.hour(21).minutes(0);
|
b.hour(21).minutes(0);
|
||||||
}
|
}
|
||||||
boolean[] recurrences = new boolean[DaysOfWeek.NUM_DAYS];
|
boolean[] recurrences = new boolean[DaysOfWeek.NUM_DAYS];
|
||||||
recurrences[1] = true;
|
recurrences[0] = true;
|
||||||
recurrences[3] = true;
|
|
||||||
Alarm a = b.id(position).recurringDays(recurrences).build();
|
Alarm a = b.id(position).recurringDays(recurrences).build();
|
||||||
a.setEnabled(true);
|
a.setEnabled(true);
|
||||||
return a;
|
return a;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.philliphsu.clock2.editalarm;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -13,11 +14,15 @@ import com.philliphsu.clock2.DaysOfWeek;
|
|||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.AlarmsRepository;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class EditAlarmActivity extends BaseActivity {
|
public class EditAlarmActivity extends BaseActivity {
|
||||||
|
|
||||||
|
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
|
||||||
|
|
||||||
@Bind(R.id.save) Button mSave;
|
@Bind(R.id.save) Button mSave;
|
||||||
@Bind(R.id.delete) Button mDelete;
|
@Bind(R.id.delete) Button mDelete;
|
||||||
@Bind(R.id.on_off) SwitchCompat mSwitch;
|
@Bind(R.id.on_off) SwitchCompat mSwitch;
|
||||||
@ -31,8 +36,19 @@ public class EditAlarmActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setWeekDaysText();
|
|
||||||
getSupportActionBar().setTitle("Snoozing until 12:40 PM");
|
getSupportActionBar().setTitle("Snoozing until 12:40 PM");
|
||||||
|
setWeekDaysText();
|
||||||
|
long alarmId = getIntent().getLongExtra(EXTRA_ALARM_ID, -1);
|
||||||
|
if (alarmId > -1) {
|
||||||
|
Alarm alarm = AlarmsRepository.getInstance(this).getItem(alarmId);
|
||||||
|
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++) {
|
||||||
|
mDays[i].setChecked(alarm.isRecurring(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -52,7 +68,19 @@ public class EditAlarmActivity extends BaseActivity {
|
|||||||
|
|
||||||
@OnClick(R.id.save)
|
@OnClick(R.id.save)
|
||||||
void save() {
|
void save() {
|
||||||
AlarmsRepository.getInstance(this).addItem(Alarm.builder().build());
|
boolean[] days = new boolean[7];
|
||||||
|
days[0] = true;
|
||||||
|
Alarm a = Alarm.builder()
|
||||||
|
.recurringDays(days)
|
||||||
|
.build();
|
||||||
|
AlarmsRepository.getInstance(this).addItem(a);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.delete)
|
||||||
|
void delete() {
|
||||||
|
//AlarmsRepository.getInstance(this).deleteItem();
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setWeekDaysText() {
|
private void setWeekDaysText() {
|
||||||
|
|||||||
@ -99,8 +99,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
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/day1"
|
android:id="@+id/day1"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user