From cc7f871520dbe03009748436759ed7987dc9e0df Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 18 Dec 2013 06:53:50 -0800 Subject: #214 Add a option to not display notification --- src/github/daneren2005/dsub/util/Constants.java | 1 + src/github/daneren2005/dsub/util/SyncUtil.java | 26 +++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index a720d21f..c539b45a 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -122,6 +122,7 @@ public final class Constants { public static final String PREFERENCES_KEY_SYNC_ENABLED = "syncEnabled"; public static final String PREFERENCES_KEY_SYNC_INTERVAL = "syncInterval"; public static final String PREFERENCES_KEY_SYNC_WIFI = "syncWifi"; + public static final String PREFERENCES_KEY_SYNC_NOTIFICATION = "syncNotification"; public static final String PREFERENCES_KEY_SYNC_STARRED = "syncStarred"; public static final String PREFERENCES_KEY_SYNC_MOST_RECENT = "syncMostRecent"; public static final String PREFERENCES_KEY_PAUSE_DISCONNECT = "pauseOnDisconnect"; diff --git a/src/github/daneren2005/dsub/util/SyncUtil.java b/src/github/daneren2005/dsub/util/SyncUtil.java index 4fb639a5..f595ff27 100644 --- a/src/github/daneren2005/dsub/util/SyncUtil.java +++ b/src/github/daneren2005/dsub/util/SyncUtil.java @@ -142,21 +142,23 @@ public final class SyncUtil { } public static void showSyncNotification(final Context context, int stringId, String extra) { - String content = (extra != null) ? context.getResources().getString(stringId, extra) : context.getResources().getString(stringId); + if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION, true)) { + String content = (extra != null) ? context.getResources().getString(stringId, extra) : context.getResources().getString(stringId); - NotificationCompat.Builder builder; - builder = new NotificationCompat.Builder(context) - .setSmallIcon(R.drawable.stat_notify_download) - .setContentTitle(context.getResources().getString(R.string.sync_title)) - .setContentText(content) - .setOngoing(false); + NotificationCompat.Builder builder; + builder = new NotificationCompat.Builder(context) + .setSmallIcon(R.drawable.stat_notify_download) + .setContentTitle(context.getResources().getString(R.string.sync_title)) + .setContentText(content) + .setOngoing(false); - Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); - notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - builder.setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0)); + Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); + notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + builder.setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0)); - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.notify(stringId, builder.build()); + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(stringId, builder.build()); + } } public static String joinNames(List names) { -- cgit v1.2.3