Skip to content

Commit d1e30fc

Browse files
committed
Move interruption and priority levels to InterruptionLevel enum
1 parent 22cb0a4 commit d1e30fc

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

firebase-appdistribution-api/api.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package com.google.firebase.appdistribution {
1818
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.appdistribution.AppDistributionRelease> checkForNewRelease();
1919
method @NonNull public static com.google.firebase.appdistribution.FirebaseAppDistribution getInstance();
2020
method public boolean isTesterSignedIn();
21-
method public void showFeedbackNotification(int, int);
22-
method public void showFeedbackNotification(@NonNull CharSequence, int);
21+
method public void showFeedbackNotification(int, com.google.firebase.appdistribution.InterruptionLevel);
22+
method public void showFeedbackNotification(@NonNull CharSequence, com.google.firebase.appdistribution.InterruptionLevel);
2323
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Void> signInTester();
2424
method public void signOutTester();
2525
method public void startFeedback(int);
@@ -49,6 +49,14 @@ package com.google.firebase.appdistribution {
4949
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status UPDATE_NOT_AVAILABLE;
5050
}
5151

52+
public enum InterruptionLevel {
53+
enum_constant public static final com.google.firebase.appdistribution.InterruptionLevel DEFAULT;
54+
enum_constant public static final com.google.firebase.appdistribution.InterruptionLevel HIGH;
55+
enum_constant public static final com.google.firebase.appdistribution.InterruptionLevel LOW;
56+
enum_constant public static final com.google.firebase.appdistribution.InterruptionLevel MAX;
57+
enum_constant public static final com.google.firebase.appdistribution.InterruptionLevel MIN;
58+
}
59+
5260
public interface OnProgressListener {
5361
method public void onProgressUpdate(@NonNull com.google.firebase.appdistribution.UpdateProgress);
5462
}

firebase-appdistribution-api/src/main/java/com/google/firebase/appdistribution/InterruptionLevel.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,56 @@ public enum InterruptionLevel {
2626
* <p>Translates to {@link NotificationManager#IMPORTANCE_MIN} on Android O+ and {@link
2727
* NotificationCompat#PRIORITY_MIN} on older platforms.
2828
*/
29-
MIN,
29+
MIN(NotificationManager.IMPORTANCE_MIN, NotificationCompat.PRIORITY_MIN),
3030

3131
/**
3232
* Low interruption level.
3333
*
3434
* <p>Translates to {@link NotificationManager#IMPORTANCE_LOW} on Android O+ and {@link
3535
* NotificationCompat#PRIORITY_LOW} on older platforms.
3636
*/
37-
LOW,
37+
LOW(NotificationManager.IMPORTANCE_LOW, NotificationCompat.PRIORITY_LOW),
3838

3939
/**
4040
* Default interruption level.
4141
*
4242
* <p>Translates to {@link NotificationManager#IMPORTANCE_DEFAULT} on Android O+ and {@link
4343
* NotificationCompat#PRIORITY_DEFAULT} on older platforms.
4444
*/
45-
DEFAULT,
45+
DEFAULT(NotificationManager.IMPORTANCE_DEFAULT, NotificationCompat.PRIORITY_DEFAULT),
4646

4747
/**
4848
* High interruption level.
4949
*
5050
* <p>Translates to {@link NotificationManager#IMPORTANCE_HIGH} on Android O+ and {@link
5151
* NotificationCompat#PRIORITY_HIGH} on older platforms.
5252
*/
53-
HIGH,
53+
HIGH(NotificationManager.IMPORTANCE_HIGH, NotificationCompat.PRIORITY_HIGH),
5454

5555
/**
5656
* Maximum interruption level.
5757
*
5858
* <p>Translates to {@link NotificationManager#IMPORTANCE_HIGH} on Android O+ and {@link
5959
* NotificationCompat#PRIORITY_MAX} on older platforms.
6060
*/
61-
MAX
61+
MAX(NotificationManager.IMPORTANCE_HIGH, NotificationCompat.PRIORITY_MAX);
62+
63+
/**
64+
* The notification channel importance corresponding to this interruption level on Android O+.
65+
*
66+
* @hide
67+
*/
68+
public final int channelImportance;
69+
70+
/**
71+
* The notification priority corresponding to this interruption level on older platforms.
72+
*
73+
* @hide
74+
*/
75+
public final int notificationPriority;
76+
77+
InterruptionLevel(int channelImportance, int notificationPriority) {
78+
this.channelImportance = channelImportance;
79+
this.notificationPriority = notificationPriority;
80+
}
6281
}

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionNotificationsManager.java

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void showFeedbackNotification(
162162
.setSmallIcon(appIconSource.getNonAdaptiveIconOrDefault(context))
163163
.setContentTitle(context.getString(R.string.feedback_notification_title))
164164
.setContentText(context.getString(R.string.feedback_notification_text, appLabel))
165-
.setPriority(getNotificationPriority(interruptionLevel))
165+
.setPriority(interruptionLevel.notificationPriority)
166166
.setOngoing(true)
167167
.setOnlyAlertOnce(true)
168168
.setAutoCancel(false)
@@ -178,46 +178,15 @@ public void cancelFeedbackNotification() {
178178
.cancel(Notification.FEEDBACK.tag, Notification.FEEDBACK.id);
179179
}
180180

181-
private int getNotificationPriority(InterruptionLevel interruptionLevel) {
182-
switch (interruptionLevel) {
183-
case MIN:
184-
return NotificationCompat.PRIORITY_MIN;
185-
case LOW:
186-
return NotificationCompat.PRIORITY_LOW;
187-
case HIGH:
188-
return NotificationCompat.PRIORITY_HIGH;
189-
case MAX:
190-
return NotificationCompat.PRIORITY_MAX;
191-
case DEFAULT:
192-
default:
193-
return NotificationCompat.PRIORITY_DEFAULT;
194-
}
195-
}
196-
197-
private int getChannelImportance(InterruptionLevel interruptionLevel) {
198-
switch (interruptionLevel) {
199-
case MIN:
200-
return NotificationManagerCompat.IMPORTANCE_MIN;
201-
case LOW:
202-
return NotificationManagerCompat.IMPORTANCE_LOW;
203-
case HIGH:
204-
case MAX: // IMPORTANCE_MAX exists but is so far unused
205-
return NotificationManagerCompat.IMPORTANCE_HIGH;
206-
case DEFAULT:
207-
default:
208-
return NotificationManagerCompat.IMPORTANCE_DEFAULT;
209-
}
210-
}
211-
212181
@RequiresApi(Build.VERSION_CODES.O)
213182
private void createChannel(
214183
Notification notification, int name, int description, InterruptionLevel interruptionLevel) {
215184
notificationManager.createNotificationChannelGroup(
216185
new NotificationChannelGroup(
217186
CHANNEL_GROUP_ID, context.getString(R.string.notifications_group_name)));
218-
int importance = getChannelImportance(interruptionLevel);
219187
NotificationChannel channel =
220-
new NotificationChannel(notification.channelId, context.getString(name), importance);
188+
new NotificationChannel(
189+
notification.channelId, context.getString(name), interruptionLevel.channelImportance);
221190
channel.setDescription(context.getString(description));
222191
channel.setGroup(CHANNEL_GROUP_ID);
223192
// Register the channel with the system; you can't change the importance

0 commit comments

Comments
 (0)