Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/android/Utils.java

Issue 5153282527854592: Issue 98 - Use the libadblockplus update mechanism (Closed)
Left Patch Set: Created Sept. 25, 2014, 3:57 p.m.
Right Patch Set: Only append the revision to the version for devbuilds Created Sept. 26, 2014, 2:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/android/Preferences.java ('k') | src/org/adblockplus/android/updater/AlarmReceiver.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 10 matching lines...) Expand all
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.NotificationManager;
27 import android.app.PendingIntent; 27 import android.app.PendingIntent;
28 import android.content.Context; 28 import android.content.Context;
29 import android.content.Intent; 29 import android.content.Intent;
30 import android.support.v4.app.NotificationCompat; 30 import android.support.v4.app.NotificationCompat;
31 import android.util.Log;
32 31
33 public final class Utils 32 public final class Utils
34 { 33 {
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
37 private Utils() 34 private Utils()
38 { 35 {
39 // 36 //
40 } 37 }
41 38
42 public static String getTag(final Class<?> clazz) 39 public static String getTag(final Class<?> clazz)
43 { 40 {
44 return clazz.getSimpleName(); 41 return clazz.getSimpleName();
45 } 42 }
46 43
(...skipping 15 matching lines...) Expand all
62 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext); 59 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext);
63 builder.setContentTitle(context.getText(R.string.app_name)); 60 builder.setContentTitle(context.getText(R.string.app_name));
64 builder.setSmallIcon(R.drawable.ic_stat_warning); 61 builder.setSmallIcon(R.drawable.ic_stat_warning);
65 builder.setAutoCancel(true); 62 builder.setAutoCancel(true);
66 builder.setOnlyAlertOnce(true); 63 builder.setOnlyAlertOnce(true);
67 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); 64 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
68 builder.setContentIntent(emptyIntent); 65 builder.setContentIntent(emptyIntent);
69 66
70 if (StringUtils.isNotEmpty(error)) 67 if (StringUtils.isNotEmpty(error))
71 { 68 {
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)); 69 builder.setContentText(context.getString(R.string.msg_update_fail));
74 } 70 }
75 else if (StringUtils.isNotEmpty(url)) 71 else if (StringUtils.isNotEmpty(url))
76 { 72 {
77 builder.setSmallIcon(R.drawable.ic_stat_download); 73 builder.setSmallIcon(R.drawable.ic_stat_download);
78 final Intent intent = new Intent(context, UpdaterActivity.class) 74 final Intent intent = new Intent(context, UpdaterActivity.class)
79 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 75 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
80 intent.setAction("download"); 76 intent.setAction("download");
81 intent.putExtra("url", url); 77 intent.putExtra("url", url);
82 final PendingIntent updateIntent = 78 final PendingIntent updateIntent =
83 PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDAT E_CURRENT); 79 PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDAT E_CURRENT);
84 builder.setContentIntent(updateIntent); 80 builder.setContentIntent(updateIntent);
85 builder.setContentText(context.getString(R.string.msg_update_available)); 81 builder.setContentText(context.getString(R.string.msg_update_available));
86 } 82 }
87 else 83 else
88 { 84 {
89 builder.setContentText(context.getString(R.string.msg_update_missing)); 85 builder.setContentText(context.getString(R.string.msg_update_missing));
90 } 86 }
91 87
92 final Notification notification = builder.getNotification(); 88 final Notification notification = builder.getNotification();
93 final NotificationManager notificationManager = 89 final NotificationManager notificationManager =
94 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE); 90 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE);
95 notificationManager.notify(UPDATE_NOTIFICATION_ID, notification); 91 final int updateNotificationId = R.string.app_name + 1;
92 notificationManager.notify(updateNotificationId, notification);
96 } 93 }
97 94
98 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub) 95 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub)
99 { 96 {
100 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus"); 97 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus");
101 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString(); 98 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString();
102 final long lastDownload = sub.getProperty("lastDownload").asLong(); 99 final long lastDownload = sub.getProperty("lastDownload").asLong();
103 100
104 String status = "synchronize_never"; 101 String status = "synchronize_never";
105 long time = 0; 102 long time = 0;
(...skipping 11 matching lines...) Expand all
117 time = lastDownload; 114 time = lastDownload;
118 status = "synchronize_last_at"; 115 status = "synchronize_last_at";
119 } 116 }
120 117
121 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS) 118 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)
122 .putExtra("url", sub.getProperty("url").toString()) 119 .putExtra("url", sub.getProperty("url").toString())
123 .putExtra("status", status) 120 .putExtra("status", status)
124 .putExtra("time", time * 1000L)); 121 .putExtra("time", time * 1000L));
125 } 122 }
126 } 123 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld