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

Unified Diff: src/org/adblockplus/android/Utils.java

Issue 5153282527854592: Issue 98 - Use the libadblockplus update mechanism (Closed)
Patch Set: Created Sept. 25, 2014, 3:57 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/org/adblockplus/android/Utils.java
===================================================================
--- a/src/org/adblockplus/android/Utils.java
+++ b/src/org/adblockplus/android/Utils.java
@@ -23,13 +23,17 @@
import org.apache.commons.lang.StringUtils;
import android.app.Notification;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
+import android.util.Log;
public final class Utils
{
+ 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.
+
private Utils()
{
//
@@ -52,41 +56,43 @@
return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.substring(1);
}
- protected static Notification createUpdateNotification(final Context context, final String url, final String error)
+ protected static void showUpdateNotification(final Context context, final String url,
+ final String error)
{
- final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
-
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(context.getText(R.string.app_name));
builder.setSmallIcon(R.drawable.ic_stat_warning);
- builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(true);
builder.setOnlyAlertOnce(true);
+ final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
builder.setContentIntent(emptyIntent);
- if (url != null)
+ if (StringUtils.isNotEmpty(error))
+ {
+ 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.
+ builder.setContentText(context.getString(R.string.msg_update_fail));
+ }
+ else if (StringUtils.isNotEmpty(url))
{
builder.setSmallIcon(R.drawable.ic_stat_download);
-
- final Intent intent = new Intent(context, UpdaterActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ final Intent intent = new Intent(context, UpdaterActivity.class)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("download");
intent.putExtra("url", url);
- final PendingIntent updateIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ final PendingIntent updateIntent =
+ PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(updateIntent);
builder.setContentText(context.getString(R.string.msg_update_available));
}
- else if (error != null)
- {
- // TODO Should we show error message to the user?
- builder.setContentText(context.getString(R.string.msg_update_fail));
- }
else
{
builder.setContentText(context.getString(R.string.msg_update_missing));
}
final Notification notification = builder.getNotification();
- return notification;
+ final NotificationManager notificationManager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ notificationManager.notify(UPDATE_NOTIFICATION_ID, notification);
}
protected static void updateSubscriptionStatus(final Context context, final Subscription sub)

Powered by Google App Engine
This is Rietveld