Removed usages of AlarmRepository
This commit is contained in:
parent
7747e4ee39
commit
11c4be68b9
@ -38,7 +38,7 @@ public abstract class Alarm implements JsonSerializable {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Alarm create(JSONObject jsonObject) {
|
public static Alarm create(JSONObject jsonObject) {
|
||||||
return null;
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
@ -184,30 +184,26 @@ public abstract class Alarm implements JsonSerializable {
|
|||||||
return ringsIn() <= hours * 3600000;
|
return ringsIn() <= hours * 3600000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public int intId() {
|
public int intId() {
|
||||||
return -1;
|
return (int) id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(long id) {
|
public void setId(long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
// TODO: Remove method signature from JsonSerializable interface.
|
||||||
return id;
|
// TODO: Remove final modifier.
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
@Override
|
||||||
public final long id() {
|
public final long id() {
|
||||||
return -1;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public JSONObject toJsonObject() {
|
public JSONObject toJsonObject() {
|
||||||
return null;
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AutoValue.Builder
|
@AutoValue.Builder
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import android.app.IntentService;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
import com.philliphsu.clock2.util.AlarmUtils;
|
import com.philliphsu.clock2.util.AlarmUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -60,7 +60,7 @@ public class OnBootUpAlarmScheduler extends IntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
List<Alarm> alarms = AlarmsRepository.getInstance(this).getItems();
|
List<Alarm> alarms = DatabaseManager.getInstance(this).getAlarms();
|
||||||
for (Alarm a : alarms) {
|
for (Alarm a : alarms) {
|
||||||
if (a.isEnabled()) {
|
if (a.isEnabled()) {
|
||||||
AlarmUtils.scheduleAlarm(this, a, false);
|
AlarmUtils.scheduleAlarm(this, a, false);
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
import com.philliphsu.clock2.util.AlarmUtils;
|
import com.philliphsu.clock2.util.AlarmUtils;
|
||||||
|
|
||||||
import static com.philliphsu.clock2.util.Preconditions.checkNotNull;
|
import static com.philliphsu.clock2.util.Preconditions.checkNotNull;
|
||||||
@ -26,7 +26,7 @@ public class PendingAlarmScheduler extends BroadcastReceiver {
|
|||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
throw new IllegalStateException("No alarm id received");
|
throw new IllegalStateException("No alarm id received");
|
||||||
}
|
}
|
||||||
Alarm alarm = checkNotNull(AlarmsRepository.getInstance(context).getItem(id));
|
Alarm alarm = checkNotNull(DatabaseManager.getInstance(context).getAlarm(id));
|
||||||
AlarmUtils.scheduleAlarm(context, alarm, false);
|
AlarmUtils.scheduleAlarm(context, alarm, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
import com.philliphsu.clock2.util.AlarmUtils;
|
import com.philliphsu.clock2.util.AlarmUtils;
|
||||||
|
|
||||||
import static android.app.PendingIntent.FLAG_ONE_SHOT;
|
import static android.app.PendingIntent.FLAG_ONE_SHOT;
|
||||||
@ -35,7 +35,7 @@ public class UpcomingAlarmReceiver extends BroadcastReceiver {
|
|||||||
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
|
if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) {
|
||||||
nm.cancel(getClass().getName(), (int) id);
|
nm.cancel(getClass().getName(), (int) id);
|
||||||
} else {
|
} else {
|
||||||
Alarm alarm = checkNotNull(AlarmsRepository.getInstance(context).getItem(id));
|
Alarm alarm = checkNotNull(DatabaseManager.getInstance(context).getAlarm(id));
|
||||||
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
||||||
AlarmUtils.cancelAlarm(context, alarm, true);
|
AlarmUtils.cancelAlarm(context, alarm, true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package com.philliphsu.clock2.alarms;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -13,8 +12,8 @@ import android.view.ViewGroup;
|
|||||||
import com.philliphsu.clock2.Alarm;
|
import com.philliphsu.clock2.Alarm;
|
||||||
import com.philliphsu.clock2.OnListItemInteractionListener;
|
import com.philliphsu.clock2.OnListItemInteractionListener;
|
||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
|
||||||
import com.philliphsu.clock2.model.BaseRepository;
|
import com.philliphsu.clock2.model.BaseRepository;
|
||||||
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -27,14 +26,9 @@ import butterknife.ButterKnife;
|
|||||||
*/
|
*/
|
||||||
public class AlarmsFragment extends Fragment implements BaseRepository.DataObserver<Alarm> {
|
public class AlarmsFragment extends Fragment implements BaseRepository.DataObserver<Alarm> {
|
||||||
|
|
||||||
// TODO: Customize parameter argument names
|
|
||||||
private static final String ARG_COLUMN_COUNT = "column-count";
|
|
||||||
// TODO: Customize parameters
|
|
||||||
private int mColumnCount = 1;
|
|
||||||
private OnAlarmInteractionListener mListener;
|
private OnAlarmInteractionListener mListener;
|
||||||
private AlarmsRepository mRepo;
|
|
||||||
|
|
||||||
private AlarmsAdapter mAdapter;
|
private AlarmsAdapter mAdapter;
|
||||||
|
private DatabaseManager mDatabaseManager;
|
||||||
|
|
||||||
@Bind(R.id.list) RecyclerView mList;
|
@Bind(R.id.list) RecyclerView mList;
|
||||||
|
|
||||||
@ -49,7 +43,7 @@ public class AlarmsFragment extends Fragment implements BaseRepository.DataObser
|
|||||||
public static AlarmsFragment newInstance(int columnCount) {
|
public static AlarmsFragment newInstance(int columnCount) {
|
||||||
AlarmsFragment fragment = new AlarmsFragment();
|
AlarmsFragment fragment = new AlarmsFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt(ARG_COLUMN_COUNT, columnCount);
|
// TODO Put any arguments in bundle
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
@ -59,8 +53,10 @@ public class AlarmsFragment extends Fragment implements BaseRepository.DataObser
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
|
// TODO Read arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mDatabaseManager = DatabaseManager.getInstance(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,12 +66,8 @@ public class AlarmsFragment extends Fragment implements BaseRepository.DataObser
|
|||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
// Set the adapter
|
// Set the adapter
|
||||||
Context context = view.getContext();
|
Context context = view.getContext();
|
||||||
if (mColumnCount <= 1) {
|
mList.setLayoutManager(new LinearLayoutManager(context));
|
||||||
mList.setLayoutManager(new LinearLayoutManager(context));
|
mAdapter = new AlarmsAdapter(mDatabaseManager.getAlarms(), mListener);
|
||||||
} else {
|
|
||||||
mList.setLayoutManager(new GridLayoutManager(context, mColumnCount));
|
|
||||||
}
|
|
||||||
mAdapter = new AlarmsAdapter(mRepo.getItems(), mListener);
|
|
||||||
mList.setAdapter(mAdapter);
|
mList.setAdapter(mAdapter);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@ -83,7 +75,15 @@ public class AlarmsFragment extends Fragment implements BaseRepository.DataObser
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
AlarmsRepository.getInstance(getActivity()).saveItems();
|
// TODO: Do we need to save anything?
|
||||||
|
// AlarmsRepository.getInstance(getActivity()).saveItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
// TODO: Need to refresh the list's adapter for any item changes. Consider doing this in
|
||||||
|
// onNewActivity().
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,16 +101,12 @@ public class AlarmsFragment extends Fragment implements BaseRepository.DataObser
|
|||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnAlarmInteractionListener");
|
+ " must implement OnAlarmInteractionListener");
|
||||||
}
|
}
|
||||||
mRepo = AlarmsRepository.getInstance(context);
|
|
||||||
mRepo.registerDataObserver(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
mListener = null;
|
mListener = null;
|
||||||
mRepo.unregisterDataObserver();
|
|
||||||
mRepo = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -79,9 +79,9 @@ public class EditAlarmActivity extends BaseActivity implements AlarmNumpad.KeyLi
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setWeekDaysText();
|
setWeekDaysText();
|
||||||
mNumpad.setKeyListener(this);
|
mNumpad.setKeyListener(this);
|
||||||
|
mDatabaseManager = DatabaseManager.getInstance(this); // MUST be before loading alarm
|
||||||
loadAlarm(getIntent().getLongExtra(EXTRA_ALARM_ID, -1));
|
loadAlarm(getIntent().getLongExtra(EXTRA_ALARM_ID, -1));
|
||||||
setTimeTextHint(); // TODO: private access
|
setTimeTextHint(); // TODO: private access
|
||||||
mDatabaseManager = DatabaseManager.getInstance(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -225,7 +225,7 @@ public class EditAlarmActivity extends BaseActivity implements AlarmNumpad.KeyLi
|
|||||||
Log.d(TAG, "Cancelling old alarm first");
|
Log.d(TAG, "Cancelling old alarm first");
|
||||||
cancelAlarm(mOldAlarm, false);
|
cancelAlarm(mOldAlarm, false);
|
||||||
}
|
}
|
||||||
mDatabaseManager.updateAlarm(mOldAlarm, alarm);
|
mDatabaseManager.updateAlarm(mOldAlarm.id(), alarm);
|
||||||
} else {
|
} else {
|
||||||
mDatabaseManager.insertAlarm(alarm);
|
mDatabaseManager.insertAlarm(alarm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import static com.philliphsu.clock2.DaysOfWeek.WEDNESDAY;
|
|||||||
* TODO: We can generalize this class to all data models, not just Alarms.
|
* TODO: We can generalize this class to all data models, not just Alarms.
|
||||||
*/
|
*/
|
||||||
public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
private static final String TAG = "AlarmDatabaseHelper";
|
||||||
private static final String DB_NAME = "alarms.db";
|
private static final String DB_NAME = "alarms.db";
|
||||||
private static final int VERSION_1 = 1;
|
private static final int VERSION_1 = 1;
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
// TODO: Consider creating an inner class that implements BaseColumns
|
// TODO: Consider creating an inner class that implements BaseColumns
|
||||||
// and defines all the columns.
|
// and defines all the columns.
|
||||||
private static final String TABLE_ALARM_RECURRING_DAYS = "alarm_recurring_days";
|
private static final String TABLE_ALARM_RECURRING_DAYS = "alarm_recurring_days";
|
||||||
|
// TODO: change value to _id if changing this to a primary auto-incrementing key
|
||||||
private static final String COLUMN_ALARM_ID = "alarm_id";
|
private static final String COLUMN_ALARM_ID = "alarm_id";
|
||||||
private static final String COLUMN_SUNDAY = "sunday";
|
private static final String COLUMN_SUNDAY = "sunday";
|
||||||
private static final String COLUMN_MONDAY = "monday";
|
private static final String COLUMN_MONDAY = "monday";
|
||||||
@ -77,6 +79,8 @@ public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
private static void createRecurringDaysTable(SQLiteDatabase db) {
|
private static void createRecurringDaysTable(SQLiteDatabase db) {
|
||||||
db.execSQL("CREATE TABLE " + TABLE_ALARM_RECURRING_DAYS + " ("
|
db.execSQL("CREATE TABLE " + TABLE_ALARM_RECURRING_DAYS + " ("
|
||||||
|
// TODO: The ID can instead be a primary auto-incrementing key, since a recurrence entry
|
||||||
|
// will always be made in conjunction with an alarm entry.
|
||||||
+ COLUMN_ALARM_ID + " INTEGER REFERENCES " + TABLE_ALARMS + "(" + COLUMN_ID + "), "
|
+ COLUMN_ALARM_ID + " INTEGER REFERENCES " + TABLE_ALARMS + "(" + COLUMN_ID + "), "
|
||||||
+ COLUMN_SUNDAY + " INTEGER NOT NULL DEFAULT 0, "
|
+ COLUMN_SUNDAY + " INTEGER NOT NULL DEFAULT 0, "
|
||||||
+ COLUMN_MONDAY + " INTEGER NOT NULL DEFAULT 0, "
|
+ COLUMN_MONDAY + " INTEGER NOT NULL DEFAULT 0, "
|
||||||
@ -117,16 +121,38 @@ public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #updateAlarm(long, Alarm)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public int updateAlarm(Alarm oldAlarm, Alarm newAlarm) {
|
public int updateAlarm(Alarm oldAlarm, Alarm newAlarm) {
|
||||||
newAlarm.setId(oldAlarm.getId());
|
newAlarm.setId(oldAlarm.id());
|
||||||
SQLiteDatabase db = getWritableDatabase();
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
int rowsUpdatedInAlarmsTable = db.update(TABLE_ALARMS,
|
int rowsUpdatedInAlarmsTable = db.update(TABLE_ALARMS,
|
||||||
toContentValues(newAlarm),
|
toContentValues(newAlarm),
|
||||||
COLUMN_ID + " = " + newAlarm.getId(),
|
COLUMN_ID + " = " + newAlarm.id(),
|
||||||
null);
|
null);
|
||||||
int rowsUpdatedInRecurrencesTable = db.update(TABLE_ALARM_RECURRING_DAYS,
|
int rowsUpdatedInRecurrencesTable = db.update(TABLE_ALARM_RECURRING_DAYS,
|
||||||
toRecurrenceContentValues(newAlarm.getId(), newAlarm),
|
toRecurrenceContentValues(newAlarm.id(), newAlarm),
|
||||||
COLUMN_ALARM_ID + " = " + newAlarm.getId(),
|
COLUMN_ALARM_ID + " = " + newAlarm.id(),
|
||||||
|
null);
|
||||||
|
if (rowsUpdatedInAlarmsTable == rowsUpdatedInRecurrencesTable && rowsUpdatedInAlarmsTable == 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("rows updated in TABLE_ALARMS = " + rowsUpdatedInAlarmsTable +
|
||||||
|
", rows updated in TABLE_ALARM_RECURRING_DAYS = " + rowsUpdatedInRecurrencesTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int updateAlarm(long id, Alarm newAlarm) {
|
||||||
|
newAlarm.setId(id);
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
int rowsUpdatedInAlarmsTable = db.update(TABLE_ALARMS,
|
||||||
|
toContentValues(newAlarm),
|
||||||
|
COLUMN_ID + " = " + id,
|
||||||
|
null);
|
||||||
|
int rowsUpdatedInRecurrencesTable = db.update(TABLE_ALARM_RECURRING_DAYS,
|
||||||
|
toRecurrenceContentValues(id, newAlarm),
|
||||||
|
COLUMN_ALARM_ID + " = " + id,
|
||||||
null);
|
null);
|
||||||
if (rowsUpdatedInAlarmsTable == rowsUpdatedInRecurrencesTable && rowsUpdatedInAlarmsTable == 1) {
|
if (rowsUpdatedInAlarmsTable == rowsUpdatedInRecurrencesTable && rowsUpdatedInAlarmsTable == 1) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -138,10 +164,10 @@ public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
public int deleteAlarm(Alarm alarm) {
|
public int deleteAlarm(Alarm alarm) {
|
||||||
SQLiteDatabase db = getWritableDatabase();
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
int rowsDeletedInAlarmsTable = db.delete(TABLE_ALARMS,
|
int rowsDeletedInAlarmsTable = db.delete(TABLE_ALARMS,
|
||||||
COLUMN_ID + " = " + alarm.getId(),
|
COLUMN_ID + " = " + alarm.id(),
|
||||||
null);
|
null);
|
||||||
int rowsDeletedInRecurrencesTable = db.delete(TABLE_ALARM_RECURRING_DAYS,
|
int rowsDeletedInRecurrencesTable = db.delete(TABLE_ALARM_RECURRING_DAYS,
|
||||||
COLUMN_ALARM_ID + " = " + alarm.getId(),
|
COLUMN_ALARM_ID + " = " + alarm.id(),
|
||||||
null);
|
null);
|
||||||
if (rowsDeletedInAlarmsTable == rowsDeletedInRecurrencesTable && rowsDeletedInAlarmsTable == 1) {
|
if (rowsDeletedInAlarmsTable == rowsDeletedInRecurrencesTable && rowsDeletedInAlarmsTable == 1) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -161,7 +187,7 @@ public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
"1"); // limit 1 row
|
"1"); // limit 1 row
|
||||||
Cursor recurrenceCursor = getReadableDatabase().query(TABLE_ALARM_RECURRING_DAYS,
|
Cursor recurrenceCursor = getReadableDatabase().query(TABLE_ALARM_RECURRING_DAYS,
|
||||||
null, // All columns
|
null, // All columns
|
||||||
COLUMN_ID + " = " + id, // selection
|
COLUMN_ALARM_ID + " = " + id, // selection
|
||||||
null, // selection args
|
null, // selection args
|
||||||
null, // group by
|
null, // group by
|
||||||
null, // order by
|
null, // order by
|
||||||
@ -232,13 +258,19 @@ public class AlarmDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
alarm.setId(getLong(getColumnIndex(COLUMN_ID)));
|
alarm.setId(getLong(getColumnIndex(COLUMN_ID)));
|
||||||
alarm.setEnabled(getInt(getColumnIndex(COLUMN_ENABLED)) == 1);
|
alarm.setEnabled(getInt(getColumnIndex(COLUMN_ENABLED)) == 1);
|
||||||
alarm.setSnoozing(getLong(getColumnIndex(COLUMN_SNOOZING_UNTIL_MILLIS)));
|
alarm.setSnoozing(getLong(getColumnIndex(COLUMN_SNOOZING_UNTIL_MILLIS)));
|
||||||
alarm.setRecurring(SUNDAY, isRecurring(INDEX_SUNDAY));
|
// DatabaseManager moves the primary cursor for you. However, you are responsible
|
||||||
alarm.setRecurring(MONDAY, isRecurring(INDEX_MONDAY));
|
// for moving the recurrence cursor yourself, because it is private to this class.
|
||||||
alarm.setRecurring(TUESDAY, isRecurring(INDEX_TUESDAY));
|
if (mRecurrenceCursor.moveToNext()) {
|
||||||
alarm.setRecurring(WEDNESDAY, isRecurring(INDEX_WEDNESDAY));
|
alarm.setRecurring(SUNDAY, isRecurring(INDEX_SUNDAY));
|
||||||
alarm.setRecurring(THURSDAY, isRecurring(INDEX_THURSDAY));
|
alarm.setRecurring(MONDAY, isRecurring(INDEX_MONDAY));
|
||||||
alarm.setRecurring(FRIDAY, isRecurring(INDEX_FRIDAY));
|
alarm.setRecurring(TUESDAY, isRecurring(INDEX_TUESDAY));
|
||||||
alarm.setRecurring(SATURDAY, isRecurring(INDEX_SATURDAY));
|
alarm.setRecurring(WEDNESDAY, isRecurring(INDEX_WEDNESDAY));
|
||||||
|
alarm.setRecurring(THURSDAY, isRecurring(INDEX_THURSDAY));
|
||||||
|
alarm.setRecurring(FRIDAY, isRecurring(INDEX_FRIDAY));
|
||||||
|
alarm.setRecurring(SATURDAY, isRecurring(INDEX_SATURDAY));
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("No entry in recurrence table for alarm: " + alarm);
|
||||||
|
}
|
||||||
return alarm;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,10 +33,18 @@ public class DatabaseManager {
|
|||||||
return alarm;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #updateAlarm(long, Alarm)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public int updateAlarm(Alarm oldAlarm, Alarm newAlarm) {
|
public int updateAlarm(Alarm oldAlarm, Alarm newAlarm) {
|
||||||
return mHelper.updateAlarm(oldAlarm, newAlarm);
|
return mHelper.updateAlarm(oldAlarm, newAlarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int updateAlarm(long id, Alarm newAlarm) {
|
||||||
|
return mHelper.updateAlarm(id, newAlarm);
|
||||||
|
}
|
||||||
|
|
||||||
public int deleteAlarm(Alarm alarm) {
|
public int deleteAlarm(Alarm alarm) {
|
||||||
return mHelper.deleteAlarm(alarm);
|
return mHelper.deleteAlarm(alarm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import android.widget.Button;
|
|||||||
|
|
||||||
import com.philliphsu.clock2.Alarm;
|
import com.philliphsu.clock2.Alarm;
|
||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
import com.philliphsu.clock2.util.AlarmUtils;
|
import com.philliphsu.clock2.util.AlarmUtils;
|
||||||
import com.philliphsu.clock2.util.LocalBroadcastHelper;
|
import com.philliphsu.clock2.util.LocalBroadcastHelper;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class RingtoneActivity extends AppCompatActivity {
|
|||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
throw new IllegalStateException("Cannot start RingtoneActivity without item's id");
|
throw new IllegalStateException("Cannot start RingtoneActivity without item's id");
|
||||||
}
|
}
|
||||||
mAlarm = checkNotNull(AlarmsRepository.getInstance(this).getItem(id));
|
mAlarm = checkNotNull(DatabaseManager.getInstance(this).getAlarm(id));
|
||||||
Log.d(TAG, "Ringing alarm " + mAlarm);
|
Log.d(TAG, "Ringing alarm " + mAlarm);
|
||||||
|
|
||||||
// TODO: If the upcoming alarm notification isn't present, verify other notifications aren't affected.
|
// TODO: If the upcoming alarm notification isn't present, verify other notifications aren't affected.
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.philliphsu.clock2.Alarm;
|
import com.philliphsu.clock2.Alarm;
|
||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
import com.philliphsu.clock2.util.AlarmUtils;
|
import com.philliphsu.clock2.util.AlarmUtils;
|
||||||
import com.philliphsu.clock2.util.LocalBroadcastHelper;
|
import com.philliphsu.clock2.util.LocalBroadcastHelper;
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
|||||||
long id = intent.getLongExtra(EXTRA_ITEM_ID, -1);
|
long id = intent.getLongExtra(EXTRA_ITEM_ID, -1);
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
throw new IllegalStateException("No item id set");
|
throw new IllegalStateException("No item id set");
|
||||||
Alarm alarm = checkNotNull(AlarmsRepository.getInstance(this).getItem(id));
|
Alarm alarm = checkNotNull(DatabaseManager.getInstance(this).getAlarm(id));
|
||||||
|
|
||||||
if (intent.getAction() == null) {
|
if (intent.getAction() == null) {
|
||||||
playRingtone(alarm);
|
playRingtone(alarm);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import com.philliphsu.clock2.Alarm;
|
|||||||
import com.philliphsu.clock2.PendingAlarmScheduler;
|
import com.philliphsu.clock2.PendingAlarmScheduler;
|
||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.DatabaseManager;
|
||||||
import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
||||||
import com.philliphsu.clock2.ringtone.RingtoneService;
|
import com.philliphsu.clock2.ringtone.RingtoneService;
|
||||||
|
|
||||||
@ -112,19 +112,16 @@ public final class AlarmUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save(c); // Save any changes
|
save(c, a);
|
||||||
|
|
||||||
// If service is not running, nothing happens
|
// If service is not running, nothing happens
|
||||||
// TODO: Since RingtoneService is a bound service, will this destroy the service after returning?
|
|
||||||
// Note that if a stopped service still has ServiceConnection objects bound to it with the
|
|
||||||
// BIND_AUTO_CREATE set, it will not be destroyed until all of these bindings are removed.
|
|
||||||
c.stopService(new Intent(c, RingtoneService.class));
|
c.stopService(new Intent(c, RingtoneService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void snoozeAlarm(Context c, Alarm a) {
|
public static void snoozeAlarm(Context c, Alarm a) {
|
||||||
a.snooze(snoozeDuration(c));
|
a.snooze(snoozeDuration(c));
|
||||||
scheduleAlarm(c, a, true);
|
scheduleAlarm(c, a, true);
|
||||||
save(c);
|
save(c, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeUpcomingAlarmNotification(Context c, Alarm a) {
|
public static void removeUpcomingAlarmNotification(Context c, Alarm a) {
|
||||||
@ -185,7 +182,9 @@ public final class AlarmUtils {
|
|||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void save(Context c) {
|
private static void save(Context c, Alarm alarm) {
|
||||||
AlarmsRepository.getInstance(c).saveItems();
|
// AlarmsRepository.getInstance(c).saveItems();
|
||||||
|
// Update the same alarm
|
||||||
|
DatabaseManager.getInstance(c).updateAlarm(alarm.id(), alarm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user