-
Notifications
You must be signed in to change notification settings - Fork 35
SDK-324 - Updated way of handling notifications to not use AsyncTask #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
03fe92d
Updated way of handling notifications to not use AsyncTask
franco-zalamena-iterable d085489
fix checkstyle
franco-zalamena-iterable 2a1037a
Compatibility with versions prior to Android 12
franco-zalamena-iterable b6ece27
Removing unnecessary code related to ghost pushes
franco-zalamena-iterable cec31e6
update changelog
franco-zalamena-iterable 10c199b
Handling instant notifications directly if possible
franco-zalamena-iterable 3f28552
Not using Expedited for scheduled notifications
franco-zalamena-iterable ec72a3e
Remove failure handling for the enqueueing since expedited has been r…
franco-zalamena-iterable 62fc953
Handling every notification as high priority
franco-zalamena-iterable 3b65f0d
Making push notification thread safe on handleNow (fallback case)
franco-zalamena-iterable bc5ecaf
Merge origin/master into SDK-324-push-async-fix
franco-zalamena-iterable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
iterableapi/src/main/java/com/iterable/iterableapi/IterableNotificationWorkScheduler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| import android.content.Context; | ||
| import android.os.Bundle; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.annotation.VisibleForTesting; | ||
| import androidx.work.Data; | ||
| import androidx.work.OneTimeWorkRequest; | ||
| import androidx.work.OutOfQuotaPolicy; | ||
| import androidx.work.WorkManager; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| class IterableNotificationWorkScheduler { | ||
|
|
||
| private static final String TAG = "IterableNotificationWorkScheduler"; | ||
|
|
||
| private final Context context; | ||
| private final WorkManager workManager; | ||
|
|
||
| interface SchedulerCallback { | ||
| void onScheduleSuccess(UUID workId); | ||
| void onScheduleFailure(Exception exception, Bundle notificationData); | ||
| } | ||
|
|
||
| IterableNotificationWorkScheduler(@NonNull Context context) { | ||
| this(context, WorkManager.getInstance(context)); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| IterableNotificationWorkScheduler(@NonNull Context context, @NonNull WorkManager workManager) { | ||
| this.context = context.getApplicationContext(); | ||
| this.workManager = workManager; | ||
| } | ||
|
|
||
| void scheduleNotificationWork( | ||
| @NonNull Bundle notificationData, | ||
| @Nullable SchedulerCallback callback | ||
| ) { | ||
|
|
||
| try { | ||
| Data inputData = IterableNotificationWorker.createInputData( | ||
| notificationData | ||
| ); | ||
|
|
||
| OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(IterableNotificationWorker.class) | ||
| .setInputData(inputData) | ||
| .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) | ||
| .build(); | ||
|
|
||
| workManager.enqueue(workRequest); | ||
|
|
||
| UUID workId = workRequest.getId(); | ||
| IterableLogger.d(TAG, "Notification work scheduled: " + workId); | ||
|
|
||
| if (callback != null) { | ||
| callback.onScheduleSuccess(workId); | ||
| } | ||
|
|
||
| } catch (Exception e) { | ||
| IterableLogger.e(TAG, "Failed to schedule notification work", e); | ||
|
|
||
| if (callback != null) { | ||
| callback.onScheduleFailure(e, notificationData); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Context getContext() { | ||
| return context; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| WorkManager getWorkManager() { | ||
| return workManager; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.