Skip to content

Commit 025e290

Browse files
committed
Merge branch 'patch-1' of git://github.com/iontech/glide
2 parents 3a8490a + 8bf4f7a commit 025e290

File tree

2 files changed

+60
-27
lines changed

2 files changed

+60
-27
lines changed

library/src/main/java/com/bumptech/glide/request/target/NotificationTarget.java

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class NotificationTarget extends SimpleTarget<Bitmap> {
2121
private final RemoteViews remoteViews;
2222
private final Context context;
2323
private final int notificationId;
24+
private final String notificationTag;
2425
private final Notification notification;
2526
private final int viewId;
2627

@@ -29,35 +30,58 @@ public class NotificationTarget extends SimpleTarget<Bitmap> {
2930
* Notification in order to update it that uses {@link #SIZE_ORIGINAL} as the target width and
3031
* height.
3132
*
32-
* @param context Context to use in the AppWidgetManager initialization.
33-
* @param viewId The id of the ImageView view that will load the image.
34-
* @param remoteViews RemoteViews object which contains the ImageView that will load the
35-
* bitmap.
36-
* @param notification The Notification object that we want to update.
37-
* @param notificationId The notificationId of the Notification that we want to load the Bitmap.
33+
* @param context Context to use in the AppWidgetManager initialization.
34+
* @param viewId The id of the ImageView view that will load the image.
35+
* @param remoteViews RemoteViews object which contains the ImageView that will load the
36+
* bitmap.
37+
* @param notification The Notification object that we want to update.
38+
* @param notificationId The notificationId of the Notification that we want to load the Bitmap.
3839
*/
3940
public NotificationTarget(Context context,
4041
int viewId, RemoteViews remoteViews, Notification notification, int notificationId) {
41-
this(context, SIZE_ORIGINAL, SIZE_ORIGINAL, viewId, remoteViews, notification, notificationId);
42+
this(context, viewId, remoteViews, notification, notificationId, null);
4243
}
4344

4445
/**
45-
* Constructor using a Notification object and a notificationId to get a handle on the
46-
* Notification in order to update it.
46+
* Constructor using a Notification object, a notificationId, and a notificationTag to get a
47+
* handle on the Notification in order to update it that uses {@link #SIZE_ORIGINAL} as the
48+
* target width and height.
4749
*
48-
* @param context Context to use in the AppWidgetManager initialization.
49-
* @param width Desired width of the bitmap that will be loaded.(Need to be manually put
50-
* because of RemoteViews limitations.)
51-
* @param height Desired height of the bitmap that will be loaded. (Need to be manually
52-
* put because of RemoteViews limitations.)
53-
* @param viewId The id of the ImageView view that will load the image.
54-
* @param remoteViews RemoteViews object which contains the ImageView that will load the
55-
* bitmap.
56-
* @param notification The Notification object that we want to update.
57-
* @param notificationId The notificationId of the Notification that we want to load the Bitmap.
50+
* @param context Context to use in the AppWidgetManager initialization.
51+
* @param viewId The id of the ImageView view that will load the image.
52+
* @param remoteViews RemoteViews object which contains the ImageView that will load the
53+
* bitmap.
54+
* @param notification The Notification object that we want to update.
55+
* @param notificationId The notificationId of the Notification that we want to load the Bitmap.
56+
* @param notificationTag The notificationTag of the Notification that we want to load the Bitmap.
57+
* May be {@code null}.
5858
*/
59-
public NotificationTarget(Context context, int width, int height,
60-
int viewId, RemoteViews remoteViews, Notification notification, int notificationId) {
59+
public NotificationTarget(Context context, int viewId, RemoteViews remoteViews,
60+
Notification notification, int notificationId, String notificationTag) {
61+
this(context, SIZE_ORIGINAL, SIZE_ORIGINAL, viewId, remoteViews, notification, notificationId,
62+
notificationTag);
63+
}
64+
65+
/**
66+
* Constructor using a Notification object, a notificationId, and a notificationTag to get a
67+
* handle on the Notification in order to update it.
68+
*
69+
* @param context Context to use in the AppWidgetManager initialization.
70+
* @param width Desired width of the bitmap that will be loaded.(Need to be manually put
71+
* because of RemoteViews limitations.)
72+
* @param height Desired height of the bitmap that will be loaded. (Need to be manually
73+
* put because of RemoteViews limitations.)
74+
* @param viewId The id of the ImageView view that will load the image.
75+
* @param remoteViews RemoteViews object which contains the ImageView that will load the
76+
* bitmap.
77+
* @param notification The Notification object that we want to update.
78+
* @param notificationId The notificationId of the Notification that we want to load the Bitmap.
79+
* @param notificationTag The notificationTag of the Notification that we want to load the
80+
* Bitmap. May be {@code null}.
81+
*/
82+
public NotificationTarget(Context context, int width, int height, int viewId,
83+
RemoteViews remoteViews, Notification notification, int notificationId,
84+
String notificationTag) {
6185
super(width, height);
6286
this.context = Preconditions.checkNotNull(context, "Context must not be null!");
6387
this.notification =
@@ -66,6 +90,7 @@ public NotificationTarget(Context context, int width, int height,
6690
Preconditions.checkNotNull(remoteViews, "RemoteViews object can not be null!");
6791
this.viewId = viewId;
6892
this.notificationId = notificationId;
93+
this.notificationTag = notificationTag;
6994
}
7095

7196
/**
@@ -74,7 +99,7 @@ public NotificationTarget(Context context, int width, int height,
7499
private void update() {
75100
NotificationManager manager =
76101
(NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE);
77-
manager.notify(this.notificationId, this.notification);
102+
manager.notify(this.notificationTag, this.notificationId, this.notification);
78103
}
79104

80105
@Override

library/src/test/java/com/bumptech/glide/request/target/NotificationTargetTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class NotificationTargetTest {
3131
private int viewId;
3232
private Notification notification;
3333
private int notificationId;
34+
private String notificationTag;
3435
private NotificationTarget target;
3536

3637
@Before
@@ -43,11 +44,12 @@ public void setUp() {
4344
viewId = 123;
4445
notification = mock(Notification.class);
4546
notificationId = 456;
47+
notificationTag = "tag";
4648

4749

4850
target =
4951
new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
50-
viewId, remoteViews, notification, notificationId);
52+
viewId, remoteViews, notification, notificationId, notificationTag);
5153
}
5254

5355
@Test
@@ -63,35 +65,41 @@ public void updatesNotificationManagerWithNotificationIdAndNotificationOnResourc
6365
/*glideAnimation*/);
6466

6567
assertEquals(notificationId, shadowManager.updatedNotificationId);
68+
assertEquals(notificationTag, shadowManager.updatedNotificationTag);
6669
assertEquals(notification, shadowManager.updatedNotification);
6770
}
6871

6972
@Test(expected = NullPointerException.class)
7073
public void testThrowsIfContextIsNull() {
7174
new NotificationTarget(null /*context*/, 100 /*width*/, 100 /*height*/,
72-
123 /*viewId*/, mock(RemoteViews.class), mock(Notification.class), 456 /*notificationId*/);
75+
123 /*viewId*/, mock(RemoteViews.class), mock(Notification.class), 456 /*notificationId*/,
76+
"tag" /*notificationTag*/);
7377
}
7478

7579

7680
@Test(expected = NullPointerException.class)
7781
public void testThrowsIfNotificationIsNull() {
7882
new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
79-
123 /*viewId*/, mock(RemoteViews.class), null /*notification*/, 456 /*notificationId*/);
83+
123 /*viewId*/, mock(RemoteViews.class), null /*notification*/, 456 /*notificationId*/,
84+
"tag" /*notificationTag*/);
8085
}
8186

8287
@Test(expected = NullPointerException.class)
8388
public void testThrowsIfRemoteViewsIsNull() {
8489
new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
85-
123 /*viewId*/, null /*remoteViews*/, mock(Notification.class), 456 /*notificationId*/);
90+
123 /*viewId*/, null /*remoteViews*/, mock(Notification.class), 456 /*notificationId*/,
91+
"tag" /*notificationTag*/);
8692
}
8793

8894
@Implements(NotificationManager.class)
8995
public static class UpdateShadowNotificationManager extends ShadowNotificationManager {
9096
int updatedNotificationId;
97+
String updatedNotificationTag;
9198
Notification updatedNotification;
9299

93100
@Implementation
94-
public void notify(int notificationId, Notification notification) {
101+
public void notify(String notificationTag, int notificationId, Notification notification) {
102+
updatedNotificationTag = notificationTag;
95103
updatedNotificationId = notificationId;
96104
updatedNotification = notification;
97105
}

0 commit comments

Comments
 (0)