From 474068bd5e22925a90f08a4ff4aecd9a60a9d197 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Wed, 28 Sep 2016 18:20:50 -0700 Subject: [PATCH] Create ContentIntentUtils --- .../clock2/util/ContentIntentUtils.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/src/main/java/com/philliphsu/clock2/util/ContentIntentUtils.java diff --git a/app/src/main/java/com/philliphsu/clock2/util/ContentIntentUtils.java b/app/src/main/java/com/philliphsu/clock2/util/ContentIntentUtils.java new file mode 100644 index 0000000..1e59f9b --- /dev/null +++ b/app/src/main/java/com/philliphsu/clock2/util/ContentIntentUtils.java @@ -0,0 +1,31 @@ +package com.philliphsu.clock2.util; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.support.annotation.NonNull; + +import com.philliphsu.clock2.MainActivity; +import com.philliphsu.clock2.alarms.ui.AlarmsFragment; + +import static android.app.PendingIntent.FLAG_CANCEL_CURRENT; + +/** + * Created by Phillip Hsu on 9/28/2016. + * + * Helper to create content intents for e.g. notifications that should + * open the app, scroll to the specified page, and then scroll to the + * item with the specified stable id. + */ +public final class ContentIntentUtils { + + public static PendingIntent create(@NonNull Context context, int targetPage, long stableId) { + Intent intent = new Intent(context, MainActivity.class) + .setAction(AlarmsFragment.ACTION_SCROLL_TO_STABLE_ID) + .putExtra(MainActivity.EXTRA_SHOW_PAGE, targetPage) + .putExtra(AlarmsFragment.EXTRA_SCROLL_TO_STABLE_ID, stableId); + return PendingIntent.getActivity(context, (int) stableId, intent, FLAG_CANCEL_CURRENT); + } + + private ContentIntentUtils() {} +}