From cfda4d70ed52147ff639103b380c47463b246eb4 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 26 Jun 2014 22:30:33 -0700 Subject: Move sync notifications into central util as well --- .../dsub/service/sync/MostRecentSyncAdapter.java | 3 ++- .../dsub/service/sync/PlaylistSyncAdapter.java | 3 ++- .../dsub/service/sync/PodcastSyncAdapter.java | 3 ++- .../dsub/service/sync/StarredSyncAdapter.java | 4 +++- src/github/daneren2005/dsub/util/Notifications.java | 21 +++++++++++++++++++++ src/github/daneren2005/dsub/util/SyncUtil.java | 21 --------------------- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java index 0801bf7c..6dfbbbe4 100644 --- a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java @@ -32,6 +32,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PodcastEpisode; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.Notifications; import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.SyncUtil.SyncSet; import github.daneren2005.dsub.util.Util; @@ -89,7 +90,7 @@ public class MostRecentSyncAdapter extends SubsonicSyncAdapter { musicService.getIndexes(Util.getSelectedMusicFolderId(context), true, context, null); } - SyncUtil.showSyncNotification(context, R.string.sync_new_albums, SyncUtil.joinNames(updated)); + Notifications.showSyncNotification(context, R.string.sync_new_albums, SyncUtil.joinNames(updated)); } else if(firstRun) { FileUtil.serialize(context, syncedList, SyncUtil.getMostRecentSyncFile(context, instance)); } diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java index f680becf..68bfdcb6 100644 --- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java @@ -32,6 +32,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.parser.SubsonicRESTException; import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.Notifications; import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.SyncUtil.SyncSet; import github.daneren2005.dsub.util.Util; @@ -122,7 +123,7 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { } if(updated.size() > 0) { - SyncUtil.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated)); + Notifications.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated)); } } } diff --git a/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java index bd9f26c7..a1878cad 100644 --- a/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java @@ -32,6 +32,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PodcastEpisode; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.parser.SubsonicRESTException; +import github.daneren2005.dsub.util.Notifications; import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.SyncUtil.SyncSet; import github.daneren2005.dsub.util.FileUtil; @@ -104,7 +105,7 @@ public class PodcastSyncAdapter extends SubsonicSyncAdapter { // Make sure there are is at least one change before re-syncing if(updated.size() > 0) { FileUtil.serialize(context, podcastList, SyncUtil.getPodcastSyncFile(context, instance)); - SyncUtil.showSyncNotification(context, R.string.sync_new_podcasts, SyncUtil.joinNames(updated)); + Notifications.showSyncNotification(context, R.string.sync_new_podcasts, SyncUtil.joinNames(updated)); } } catch(Exception e) { Log.w(TAG, "Failed to get podcasts for " + Util.getServerName(context, instance)); diff --git a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java index 54c10f41..b99c501d 100644 --- a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.service.sync; import android.annotation.TargetApi; +import android.app.Notification; import android.content.Context; import android.util.Log; @@ -29,6 +30,7 @@ import java.util.ArrayList; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.Notifications; import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.Util; @@ -69,7 +71,7 @@ public class StarredSyncAdapter extends SubsonicSyncAdapter { SyncUtil.setSyncedStarred(syncedList, context, instance); if(updated) { - SyncUtil.showSyncNotification(context, R.string.sync_new_starred, null); + Notifications.showSyncNotification(context, R.string.sync_new_starred, null); } } catch(Exception e) { Log.e(TAG, "Failed to get starred list for " + Util.getServerName(context, instance)); diff --git a/src/github/daneren2005/dsub/util/Notifications.java b/src/github/daneren2005/dsub/util/Notifications.java index 3eec7517..c6e9b14f 100644 --- a/src/github/daneren2005/dsub/util/Notifications.java +++ b/src/github/daneren2005/dsub/util/Notifications.java @@ -286,6 +286,27 @@ public final class Notifications { } } + public static void showSyncNotification(final Context context, int stringId, String extra) { + 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_sync) + .setContentTitle(context.getResources().getString(R.string.sync_title)) + .setContentText(content) + .setStyle(new NotificationCompat.BigTextStyle().bigText(content.replace(", ", "\n"))) + .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, 2, notificationIntent, 0)); + + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(stringId, builder.build()); + } + } + /** * Resolves the default text color for notifications. * diff --git a/src/github/daneren2005/dsub/util/SyncUtil.java b/src/github/daneren2005/dsub/util/SyncUtil.java index 0c567681..15fa2d47 100644 --- a/src/github/daneren2005/dsub/util/SyncUtil.java +++ b/src/github/daneren2005/dsub/util/SyncUtil.java @@ -181,27 +181,6 @@ public final class SyncUtil { return "sync-most_recent-" + (Util.getRestUrl(context, null, instance, false)).hashCode() + ".ser"; } - public static void showSyncNotification(final Context context, int stringId, String extra) { - 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_sync) - .setContentTitle(context.getResources().getString(R.string.sync_title)) - .setContentText(content) - .setStyle(new NotificationCompat.BigTextStyle().bigText(content.replace(", ", "\n"))) - .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, 2, notificationIntent, 0)); - - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.notify(stringId, builder.build()); - } - } - public static String joinNames(List names) { StringBuilder builder = new StringBuilder(); for (String val : names) { -- cgit v1.2.3