Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.android; | 18 package org.adblockplus.android; |
19 | 19 |
20 import org.adblockplus.android.updater.UpdaterActivity; | 20 import org.adblockplus.android.updater.UpdaterActivity; |
21 import org.adblockplus.libadblockplus.JsValue; | 21 import org.adblockplus.libadblockplus.JsValue; |
22 import org.adblockplus.libadblockplus.Subscription; | 22 import org.adblockplus.libadblockplus.Subscription; |
23 import org.apache.commons.lang.StringUtils; | 23 import org.apache.commons.lang.StringUtils; |
24 | 24 |
25 import android.app.Notification; | 25 import android.app.Notification; |
26 import android.app.NotificationManager; | |
26 import android.app.PendingIntent; | 27 import android.app.PendingIntent; |
27 import android.content.Context; | 28 import android.content.Context; |
28 import android.content.Intent; | 29 import android.content.Intent; |
29 import android.support.v4.app.NotificationCompat; | 30 import android.support.v4.app.NotificationCompat; |
31 import android.util.Log; | |
30 | 32 |
31 public final class Utils | 33 public final class Utils |
32 { | 34 { |
35 private static final int UPDATE_NOTIFICATION_ID = R.string.app_name + 1; | |
René Jeschke
2014/09/26 10:24:05
I'm not happy with having the ID here. This is a u
Felix Dahlke
2014/09/26 11:20:24
It's a local constant - why make it a global one i
René Jeschke
2014/09/26 11:31:50
Well, then you have to move it into the method its
Felix Dahlke
2014/09/26 11:39:05
Yeah, I was pondering that, but a local final inst
René Jeschke
2014/09/26 11:59:17
Would make more sense than declaring it class-wide
Felix Dahlke
2014/09/26 13:05:13
Alright, made it a local constant. I disagree abou
René Jeschke
2014/09/26 13:10:52
Righty right, thanks.
| |
36 | |
33 private Utils() | 37 private Utils() |
34 { | 38 { |
35 // | 39 // |
36 } | 40 } |
37 | 41 |
38 public static String getTag(final Class<?> clazz) | 42 public static String getTag(final Class<?> clazz) |
39 { | 43 { |
40 return clazz.getSimpleName(); | 44 return clazz.getSimpleName(); |
41 } | 45 } |
42 | 46 |
43 public static String capitalizeString(final String s) | 47 public static String capitalizeString(final String s) |
44 { | 48 { |
45 if (s == null || s.length() == 0) | 49 if (s == null || s.length() == 0) |
46 { | 50 { |
47 return ""; | 51 return ""; |
48 } | 52 } |
49 | 53 |
50 final char first = s.charAt(0); | 54 final char first = s.charAt(0); |
51 | 55 |
52 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1); | 56 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1); |
53 } | 57 } |
54 | 58 |
55 protected static Notification createUpdateNotification(final Context context, final String url, final String error) | 59 protected static void showUpdateNotification(final Context context, final Stri ng url, |
60 final String error) | |
56 { | 61 { |
57 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); | |
58 | |
59 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext); | 62 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext); |
60 builder.setContentTitle(context.getText(R.string.app_name)); | 63 builder.setContentTitle(context.getText(R.string.app_name)); |
61 builder.setSmallIcon(R.drawable.ic_stat_warning); | 64 builder.setSmallIcon(R.drawable.ic_stat_warning); |
62 builder.setWhen(System.currentTimeMillis()); | |
63 builder.setAutoCancel(true); | 65 builder.setAutoCancel(true); |
64 builder.setOnlyAlertOnce(true); | 66 builder.setOnlyAlertOnce(true); |
67 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); | |
65 builder.setContentIntent(emptyIntent); | 68 builder.setContentIntent(emptyIntent); |
66 | 69 |
67 if (url != null) | 70 if (StringUtils.isNotEmpty(error)) |
71 { | |
72 Log.e(getTag(Utils.class), "Failed to check for updates: " + error); | |
René Jeschke
2014/09/26 10:24:05
1. Please define this as a static variable as this
Felix Dahlke
2014/09/26 11:20:24
How else would we debug this in practice? The alte
René Jeschke
2014/09/26 11:31:50
Point is: the tag does not match the functionality
Felix Dahlke
2014/09/26 11:39:05
I would really like to be able to debug network pr
René Jeschke
2014/09/26 11:59:17
Yes, that would make more sense IMO. And I will ne
Felix Dahlke
2014/09/26 13:05:13
Done.
| |
73 builder.setContentText(context.getString(R.string.msg_update_fail)); | |
74 } | |
75 else if (StringUtils.isNotEmpty(url)) | |
68 { | 76 { |
69 builder.setSmallIcon(R.drawable.ic_stat_download); | 77 builder.setSmallIcon(R.drawable.ic_stat_download); |
70 | 78 final Intent intent = new Intent(context, UpdaterActivity.class) |
71 final Intent intent = new Intent(context, UpdaterActivity.class).addFlags( Intent.FLAG_ACTIVITY_NEW_TASK); | 79 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
72 intent.setAction("download"); | 80 intent.setAction("download"); |
73 intent.putExtra("url", url); | 81 intent.putExtra("url", url); |
74 final PendingIntent updateIntent = PendingIntent.getActivity(context, 0, i ntent, PendingIntent.FLAG_UPDATE_CURRENT); | 82 final PendingIntent updateIntent = |
83 PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDAT E_CURRENT); | |
75 builder.setContentIntent(updateIntent); | 84 builder.setContentIntent(updateIntent); |
76 builder.setContentText(context.getString(R.string.msg_update_available)); | 85 builder.setContentText(context.getString(R.string.msg_update_available)); |
77 } | 86 } |
78 else if (error != null) | |
79 { | |
80 // TODO Should we show error message to the user? | |
81 builder.setContentText(context.getString(R.string.msg_update_fail)); | |
82 } | |
83 else | 87 else |
84 { | 88 { |
85 builder.setContentText(context.getString(R.string.msg_update_missing)); | 89 builder.setContentText(context.getString(R.string.msg_update_missing)); |
86 } | 90 } |
87 | 91 |
88 final Notification notification = builder.getNotification(); | 92 final Notification notification = builder.getNotification(); |
89 return notification; | 93 final NotificationManager notificationManager = |
94 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE); | |
95 notificationManager.notify(UPDATE_NOTIFICATION_ID, notification); | |
90 } | 96 } |
91 | 97 |
92 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub) | 98 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub) |
93 { | 99 { |
94 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus"); | 100 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus"); |
95 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString(); | 101 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString(); |
96 final long lastDownload = sub.getProperty("lastDownload").asLong(); | 102 final long lastDownload = sub.getProperty("lastDownload").asLong(); |
97 | 103 |
98 String status = "synchronize_never"; | 104 String status = "synchronize_never"; |
99 long time = 0; | 105 long time = 0; |
(...skipping 11 matching lines...) Expand all Loading... | |
111 time = lastDownload; | 117 time = lastDownload; |
112 status = "synchronize_last_at"; | 118 status = "synchronize_last_at"; |
113 } | 119 } |
114 | 120 |
115 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS) | 121 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS) |
116 .putExtra("url", sub.getProperty("url").toString()) | 122 .putExtra("url", sub.getProperty("url").toString()) |
117 .putExtra("status", status) | 123 .putExtra("status", status) |
118 .putExtra("time", time * 1000L)); | 124 .putExtra("time", time * 1000L)); |
119 } | 125 } |
120 } | 126 } |
OLD | NEW |