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
|
<activity
|
||||||
android:name=".ringtone.RingtoneActivity"
|
android:name=".ringtone.RingtoneActivity"
|
||||||
android:label="@string/title_activity_ringtone"
|
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>
|
</activity>
|
||||||
|
|
||||||
<service
|
<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.
|
private static final int MAX_MINUTES_CAN_SNOOZE = 30; // TODO: Delete this along with all snooze stuff.
|
||||||
|
|
||||||
// JSON property names
|
// 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_ENABLED = "enabled";
|
||||||
//private static final String KEY_ID = "id"; // Defined in JsonSerializable
|
//private static final String KEY_ID = "id"; // Defined in JsonSerializable
|
||||||
private static final String KEY_HOUR = "hour";
|
private static final String KEY_HOUR = "hour";
|
||||||
@ -66,6 +67,7 @@ public abstract class Alarm implements JsonSerializable {
|
|||||||
.vibrates(jsonObject.getBoolean(KEY_VIBRATES))
|
.vibrates(jsonObject.getBoolean(KEY_VIBRATES))
|
||||||
.rebuild();
|
.rebuild();
|
||||||
alarm.setEnabled(jsonObject.getBoolean(KEY_ENABLED));
|
alarm.setEnabled(jsonObject.getBoolean(KEY_ENABLED));
|
||||||
|
alarm.snoozingUntilMillis = jsonObject.getLong(KEY_SNOOZING_UNTIL_MILLIS);
|
||||||
return alarm;
|
return alarm;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -185,6 +187,7 @@ public abstract class Alarm implements JsonSerializable {
|
|||||||
public JSONObject toJsonObject() {
|
public JSONObject toJsonObject() {
|
||||||
try {
|
try {
|
||||||
return new JSONObject()
|
return new JSONObject()
|
||||||
|
.put(KEY_SNOOZING_UNTIL_MILLIS, snoozingUntilMillis)
|
||||||
.put(KEY_ENABLED, enabled)
|
.put(KEY_ENABLED, enabled)
|
||||||
.put(KEY_ID, id())
|
.put(KEY_ID, id())
|
||||||
.put(KEY_HOUR, hour())
|
.put(KEY_HOUR, hour())
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import android.content.Intent;
|
|||||||
import com.philliphsu.clock2.Alarm;
|
import com.philliphsu.clock2.Alarm;
|
||||||
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
import com.philliphsu.clock2.UpcomingAlarmReceiver;
|
||||||
import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
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_CANCEL_CURRENT;
|
||||||
import static android.app.PendingIntent.FLAG_NO_CREATE;
|
import static android.app.PendingIntent.FLAG_NO_CREATE;
|
||||||
@ -57,6 +58,9 @@ public final class AlarmUtils {
|
|||||||
pi.cancel();
|
pi.cancel();
|
||||||
|
|
||||||
removeUpcomingAlarmNotification(c, a);
|
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) {
|
public static void removeUpcomingAlarmNotification(Context c, Alarm a) {
|
||||||
|
|||||||
@ -100,7 +100,8 @@ public class EditAlarmPresenter implements EditAlarmContract.Presenter {
|
|||||||
@Override
|
@Override
|
||||||
public void stopSnoozing() {
|
public void stopSnoozing() {
|
||||||
dismissNow(); // MUST be first, see AlarmUtils.notifyUpcomingAlarmIntent()
|
dismissNow(); // MUST be first, see AlarmUtils.notifyUpcomingAlarmIntent()
|
||||||
mAlarm.stopSnoozing(); // TOneverDO: move this from last line
|
mAlarm.stopSnoozing(); // TOneverDO: before dismissNow()
|
||||||
|
mRepository.saveItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -85,18 +85,9 @@ public class RingtoneActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void snooze() {
|
private void snooze() {
|
||||||
|
mAlarm.snooze(1); // TODO: Read snooze duration from prefs
|
||||||
AlarmUtils.scheduleAlarm(this, mAlarm);
|
AlarmUtils.scheduleAlarm(this, mAlarm);
|
||||||
/*
|
AlarmsRepository.getInstance(this).saveItems();
|
||||||
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);
|
|
||||||
*/
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -110,7 +110,6 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
|
|||||||
.setContentTitle(getString(R.string.missed_alarm))
|
.setContentTitle(getString(R.string.missed_alarm))
|
||||||
.setContentText(mNormalRingTime)
|
.setContentText(mNormalRingTime)
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
//.setShowWhen(true) // TODO: Is it shown by default?
|
|
||||||
.build();
|
.build();
|
||||||
// A tag with the name of the subclass is used in addition to the item's id to prevent
|
// 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
|
// conflicting notifications for items of different class types. Items of any class type
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user