Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 java.io.BufferedReader; | 20 import java.io.BufferedReader; |
21 import java.io.InputStreamReader; | 21 import java.io.InputStreamReader; |
22 | 22 |
23 import org.adblockplus.android.updater.UpdaterActivity; | |
24 import org.adblockplus.libadblockplus.JsValue; | 23 import org.adblockplus.libadblockplus.JsValue; |
25 import org.adblockplus.libadblockplus.Subscription; | 24 import org.adblockplus.libadblockplus.Subscription; |
26 import org.apache.commons.lang.StringUtils; | 25 import org.apache.commons.lang.StringUtils; |
27 | 26 |
28 import android.app.Notification; | 27 import android.app.Notification; |
29 import android.app.NotificationManager; | 28 import android.app.NotificationManager; |
30 import android.app.PendingIntent; | 29 import android.app.PendingIntent; |
31 import android.content.Context; | 30 import android.content.Context; |
32 import android.content.Intent; | 31 import android.content.Intent; |
33 import android.support.v4.app.NotificationCompat; | |
34 | 32 |
35 public final class Utils | 33 public final class Utils |
36 { | 34 { |
37 private Utils() | 35 private Utils() |
38 { | 36 { |
39 // | 37 // |
40 } | 38 } |
41 | 39 |
42 public static String getTag(final Class<?> clazz) | 40 public static String getTag(final Class<?> clazz) |
43 { | 41 { |
44 return clazz.getSimpleName(); | 42 return clazz.getSimpleName(); |
45 } | 43 } |
46 | 44 |
47 public static String capitalizeString(final String s) | 45 public static String capitalizeString(final String s) |
diegocarloslima
2016/09/06 01:05:49
Why this method is kept here? It isn't called anyw
anton
2016/09/06 05:56:23
The original task was to split the sources and don
diegocarloslima
2016/09/06 14:08:58
It doesn't make much sense to me, since some chang
anton
2016/09/08 13:43:48
In general you are right. But this method is gener
| |
48 { | 46 { |
49 if (s == null || s.length() == 0) | 47 if (s == null || s.length() == 0) |
50 { | 48 { |
51 return ""; | 49 return ""; |
52 } | 50 } |
53 | 51 |
54 final char first = s.charAt(0); | 52 final char first = s.charAt(0); |
55 | 53 |
56 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1); | 54 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1); |
57 } | 55 } |
58 | 56 |
59 protected static void showUpdateNotification(final Context context, final Stri ng url, | |
60 final String error) | |
61 { | |
62 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext); | |
63 builder.setContentTitle(context.getText(R.string.app_name)); | |
64 builder.setSmallIcon(R.drawable.ic_stat_warning); | |
65 builder.setAutoCancel(true); | |
66 builder.setOnlyAlertOnce(true); | |
67 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); | |
68 builder.setContentIntent(emptyIntent); | |
69 | |
70 if (StringUtils.isNotEmpty(error)) | |
71 { | |
72 builder.setContentText(context.getString(R.string.msg_update_fail)); | |
73 } | |
74 else if (StringUtils.isNotEmpty(url)) | |
75 { | |
76 builder.setSmallIcon(R.drawable.ic_stat_download); | |
77 final Intent intent = new Intent(context, UpdaterActivity.class) | |
78 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
79 intent.setAction("download"); | |
80 intent.putExtra("url", url); | |
81 final PendingIntent updateIntent = | |
82 PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDAT E_CURRENT); | |
83 builder.setContentIntent(updateIntent); | |
84 builder.setContentText(context.getString(R.string.msg_update_available)); | |
85 } | |
86 else | |
87 { | |
88 builder.setContentText(context.getString(R.string.msg_update_missing)); | |
89 } | |
90 | |
91 final Notification notification = builder.getNotification(); | |
92 final NotificationManager notificationManager = | |
93 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE); | |
94 notificationManager.notify(AdblockPlus.UPDATE_NOTIFICATION_ID, notification) ; | |
95 } | |
96 | |
97 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub) | |
98 { | |
99 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus"); | |
100 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString(); | |
101 final long lastDownload = sub.getProperty("lastDownload").asLong(); | |
102 | |
103 String status = "synchronize_never"; | |
104 long time = 0; | |
105 | |
106 if (sub.isUpdating()) | |
107 { | |
108 status = "synchronize_in_progress"; | |
109 } | |
110 else if (StringUtils.isNotEmpty(downloadStatus) && !downloadStatus.equals("s ynchronize_ok")) | |
111 { | |
112 status = downloadStatus; | |
113 } | |
114 else if (lastDownload > 0) | |
115 { | |
116 time = lastDownload; | |
117 status = "synchronize_last_at"; | |
118 } | |
119 | |
120 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS) | |
121 .putExtra("url", sub.getProperty("url").toString()) | |
122 .putExtra("status", status) | |
123 .putExtra("time", time * 1000L)); | |
124 } | |
125 | |
126 public static void appendRawTextFile(final Context context, final StringBuilde r text, final int id) | 57 public static void appendRawTextFile(final Context context, final StringBuilde r text, final int id) |
diegocarloslima
2016/09/06 01:05:50
This method isn't called by the lib and is redunda
anton
2016/09/06 05:56:23
Same reason: don't do any modifications for the so
| |
127 { | 58 { |
128 try | 59 try |
129 { | 60 { |
130 final BufferedReader buf = new BufferedReader(new InputStreamReader(contex t.getResources().openRawResource(id))); | 61 final BufferedReader buf = new BufferedReader(new InputStreamReader(contex t.getResources().openRawResource(id))); |
131 | 62 |
132 try | 63 try |
133 { | 64 { |
134 String line; | 65 String line; |
135 while ((line = buf.readLine()) != null) | 66 while ((line = buf.readLine()) != null) |
136 { | 67 { |
137 text.append(line); | 68 text.append(line); |
138 text.append('\n'); | 69 text.append('\n'); |
139 } | 70 } |
140 } | 71 } |
141 finally | 72 finally |
142 { | 73 { |
143 buf.close(); | 74 buf.close(); |
144 } | 75 } |
145 | 76 |
146 } | 77 } |
147 catch (final Exception e) | 78 catch (final Exception e) |
148 { | 79 { |
149 // Ignored for now | 80 // Ignored for now |
150 } | 81 } |
151 } | 82 } |
152 } | 83 } |
OLD | NEW |