diff --git a/app/src/main/java/com/philliphsu/clock2/MainActivity.java b/app/src/main/java/com/philliphsu/clock2/MainActivity.java index 8991b66..81ca684 100644 --- a/app/src/main/java/com/philliphsu/clock2/MainActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/MainActivity.java @@ -237,8 +237,7 @@ public class MainActivity extends BaseActivity { mAddItemDrawable = ContextCompat.getDrawable(this, R.drawable.ic_add_24dp); final int initialPage = getIntent().getIntExtra(EXTRA_SHOW_PAGE, -1); - if (initialPage > 0/*0 is already the default page*/ - && initialPage <= mSectionsPagerAdapter.getCount() - 1) { + if (initialPage >= 0 && initialPage <= mSectionsPagerAdapter.getCount() - 1) { // Run this only after the ViewPager is finished drawing mViewPager.post(new Runnable() { @Override diff --git a/app/src/main/java/com/philliphsu/clock2/UpcomingAlarmReceiver.java b/app/src/main/java/com/philliphsu/clock2/UpcomingAlarmReceiver.java index 3aef4d5..2aa9fd6 100644 --- a/app/src/main/java/com/philliphsu/clock2/UpcomingAlarmReceiver.java +++ b/app/src/main/java/com/philliphsu/clock2/UpcomingAlarmReceiver.java @@ -8,8 +8,10 @@ import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; +import com.philliphsu.clock2.alarms.AlarmsFragment; import com.philliphsu.clock2.util.AlarmController; +import static android.app.PendingIntent.FLAG_CANCEL_CURRENT; import static android.app.PendingIntent.FLAG_ONE_SHOT; import static com.philliphsu.clock2.util.DateFormatUtils.formatTime; @@ -62,16 +64,27 @@ public class UpcomingAlarmReceiver extends BroadcastReceiver { } } - Intent in = new Intent(context, UpcomingAlarmReceiver.class) - .putExtra(EXTRA_ALARM, alarm) - .setAction(ACTION_DISMISS_NOW); - PendingIntent pi = PendingIntent.getBroadcast(context, (int) id, in, FLAG_ONE_SHOT); + Intent dismissIntent = new Intent(context, UpcomingAlarmReceiver.class) + .setAction(ACTION_DISMISS_NOW) + .putExtra(EXTRA_ALARM, alarm); + PendingIntent piDismiss = PendingIntent.getBroadcast(context, (int) id, dismissIntent, FLAG_ONE_SHOT); + Intent contentIntent = new Intent(context, MainActivity.class) + // http://stackoverflow.com/a/3128418/5055032 + // "For some unspecified reason, extras will be delivered only if you've set some action" + // This ONLY applies to PendingIntents... + // And for another unspecified reason, this dummy action must NOT be the same value + // as another PendingIntent's dummy action. + .setAction("abc") + .putExtra(MainActivity.EXTRA_SHOW_PAGE, MainActivity.PAGE_ALARMS) + .putExtra(AlarmsFragment.EXTRA_SCROLL_TO_ALARM_ID, id); + PendingIntent piContent = PendingIntent.getActivity(context, (int) id, contentIntent, FLAG_CANCEL_CURRENT); Notification note = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alarm_24dp) .setContentTitle(title) .setContentText(text) + .setContentIntent(piContent) .setOngoing(true) - .addAction(R.drawable.ic_dismiss_alarm_24dp, context.getString(R.string.dismiss_now), pi) + .addAction(R.drawable.ic_dismiss_alarm_24dp, context.getString(R.string.dismiss_now), piDismiss) .build(); nm.notify(TAG, (int) id, note); } diff --git a/app/src/main/java/com/philliphsu/clock2/alarms/AlarmsFragment.java b/app/src/main/java/com/philliphsu/clock2/alarms/AlarmsFragment.java index 3f1c357..1ace642 100644 --- a/app/src/main/java/com/philliphsu/clock2/alarms/AlarmsFragment.java +++ b/app/src/main/java/com/philliphsu/clock2/alarms/AlarmsFragment.java @@ -25,13 +25,8 @@ import com.philliphsu.clock2.util.DelayedSnackbarHandler; import static com.philliphsu.clock2.util.FragmentTagUtils.makeTag; -public class AlarmsFragment extends RecyclerViewFragment< - Alarm, - BaseAlarmViewHolder, - AlarmCursor, - AlarmsCursorAdapter> - implements ScrollHandler, // TODO: Move interface to base class - BaseTimePickerDialog.OnTimeSetListener { +public class AlarmsFragment extends RecyclerViewFragment implements BaseTimePickerDialog.OnTimeSetListener { private static final String TAG = "AlarmsFragment"; private static final String KEY_EXPANDED_POSITION = "expanded_position"; @@ -46,6 +41,7 @@ public class AlarmsFragment extends RecyclerViewFragment< // TODO: Delete this. We no longer use the system's ringtone picker. public static final int REQUEST_PICK_RINGTONE = 1; + public static final String EXTRA_SCROLL_TO_ALARM_ID = "com.philliphsu.clock2.alarms.extra.SCROLL_TO_ALARM_ID"; private AsyncAlarmsTableUpdateHandler mAsyncUpdateHandler; private AlarmController mAlarmController; @@ -96,6 +92,11 @@ public class AlarmsFragment extends RecyclerViewFragment< mTimePickerDialogController = new TimePickerDialogController( getFragmentManager(), getActivity(), this); mTimePickerDialogController.tryRestoreCallback(makeTimePickerDialogTag()); + + long scrollToStableId = getActivity().getIntent().getLongExtra(EXTRA_SCROLL_TO_ALARM_ID, -1); + if (scrollToStableId != -1) { + setScrollToStableId(scrollToStableId); + } } @Override diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java b/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java index 6248d00..1b363e9 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java @@ -25,11 +25,7 @@ import com.philliphsu.clock2.model.TimersListCursorLoader; import static butterknife.ButterKnife.findById; import static com.philliphsu.clock2.util.ConfigurationUtils.getOrientation; -public class TimersFragment extends RecyclerViewFragment< - Timer, - TimerViewHolder, - TimerCursor, - TimersCursorAdapter> { +public class TimersFragment extends RecyclerViewFragment { // TODO: Different number of columns for different display densities, instead of landscape. // Use smallest width qualifiers. I can imagine 3 or 4 columns for a large enough tablet in landscape. private static final int LANDSCAPE_LAYOUT_COLUMNS = 2; @@ -44,8 +40,6 @@ public class TimersFragment extends RecyclerViewFragment< super.onCreate(savedInstanceState); mAsyncTimersTableUpdateHandler = new AsyncTimersTableUpdateHandler(getActivity(), this); - // TimerNotificationService was supposed to put this extra in its content intent. - // Currently, it does not implement this feature. May be left for a future release? long scrollToStableId = getActivity().getIntent().getLongExtra(EXTRA_SCROLL_TO_TIMER_ID, -1); if (scrollToStableId != -1) { setScrollToStableId(scrollToStableId);