Added snoozing field to JSON, changed RingtoneActivity launch mode in manifest
This commit is contained in:
parent
6064f4975a
commit
1ea774f21b
@ -22,7 +22,11 @@
|
||||
<activity
|
||||
android:name=".ringtone.RingtoneActivity"
|
||||
android:label="@string/title_activity_ringtone"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:excludeFromRecents="true"
|
||||
android:finishOnTaskLaunch="true"
|
||||
android:launchMode="singleTask"
|
||||
android:taskAffinity="com.philliphsu.clock2.RingtoneActivity">
|
||||
</activity>
|
||||
|
||||
<service
|
||||
|
||||
@ -23,6 +23,7 @@ public abstract class Alarm implements JsonSerializable {
|
||||
private static final int MAX_MINUTES_CAN_SNOOZE = 30; // TODO: Delete this along with all snooze stuff.
|
||||
|
||||
// JSON property names
|
||||
private static final String KEY_SNOOZING_UNTIL_MILLIS = "snoozing_until_millis";
|
||||
private static final String KEY_ENABLED = "enabled";
|
||||
//private static final String KEY_ID = "id"; // Defined in JsonSerializable
|
||||
private static final String KEY_HOUR = "hour";
|
||||
@ -66,6 +67,7 @@ public abstract class Alarm implements JsonSerializable {
|
||||
.vibrates(jsonObject.getBoolean(KEY_VIBRATES))
|
||||
.rebuild();
|
||||
alarm.setEnabled(jsonObject.getBoolean(KEY_ENABLED));
|
||||
alarm.snoozingUntilMillis = jsonObject.getLong(KEY_SNOOZING_UNTIL_MILLIS);
|
||||
return alarm;
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -185,6 +187,7 @@ public abstract class Alarm implements JsonSerializable {
|
||||
public JSONObject toJsonObject() {
|
||||
try {
|
||||
return new JSONObject()
|
||||
.put(KEY_SNOOZING_UNTIL_MILLIS, snoozingUntilMillis)
|
||||
.put(KEY_ENABLED, enabled)
|
||||
.put(KEY_ID, id())
|
||||
.put(KEY_HOUR, hour())
|
||||
|
||||
@ -8,6 +8,7 @@ import android.content.Intent;
|
||||
import com.philliphsu.clock2.Alarm;
|
||||
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
||||
import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
||||
import com.philliphsu.clock2.ringtone.RingtoneService;
|
||||
|
||||
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
|
||||
import static android.app.PendingIntent.FLAG_NO_CREATE;
|
||||
@ -57,6 +58,9 @@ public final class AlarmUtils {
|
||||
pi.cancel();
|
||||
|
||||
removeUpcomingAlarmNotification(c, a);
|
||||
|
||||
// If service is not running, nothing happens
|
||||
c.stopService(new Intent(c, RingtoneService.class));
|
||||
}
|
||||
|
||||
public static void removeUpcomingAlarmNotification(Context c, Alarm a) {
|
||||
|
||||
@ -100,7 +100,8 @@ public class EditAlarmPresenter implements EditAlarmContract.Presenter {
|
||||
@Override
|
||||
public void stopSnoozing() {
|
||||
dismissNow(); // MUST be first, see AlarmUtils.notifyUpcomingAlarmIntent()
|
||||
mAlarm.stopSnoozing(); // TOneverDO: move this from last line
|
||||
mAlarm.stopSnoozing(); // TOneverDO: before dismissNow()
|
||||
mRepository.saveItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -85,18 +85,9 @@ public class RingtoneActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void snooze() {
|
||||
mAlarm.snooze(1); // TODO: Read snooze duration from prefs
|
||||
AlarmUtils.scheduleAlarm(this, mAlarm);
|
||||
/*
|
||||
Intent intent = new Intent(this, RingtoneActivity.class)
|
||||
.setData(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
|
||||
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
|
||||
am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pi);
|
||||
// Post snoozing notif right away
|
||||
Intent intent2 = new Intent(this, UpcomingAlarmReceiver.class)
|
||||
.setAction(UpcomingAlarmReceiver.ACTION_SHOW_SNOOZING);
|
||||
sendBroadcast(intent2);
|
||||
*/
|
||||
AlarmsRepository.getInstance(this).saveItems();
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
||||
@ -110,7 +110,6 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
||||
.setContentTitle(getString(R.string.missed_alarm))
|
||||
.setContentText(mNormalRingTime)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
//.setShowWhen(true) // TODO: Is it shown by default?
|
||||
.build();
|
||||
// A tag with the name of the subclass is used in addition to the item's id to prevent
|
||||
// conflicting notifications for items of different class types. Items of any class type
|
||||
|
||||
Loading…
Reference in New Issue
Block a user