From c03a5ae4cb985dfba8c832adf477b50dbbe96a70 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 24 Nov 2013 22:59:06 -0800 Subject: Moved SyncUtil to util folder... --- .../dsub/fragments/SelectPlaylistFragment.java | 4 +- .../dsub/fragments/SelectPodcastsFragment.java | 5 +- src/github/daneren2005/dsub/service/SyncUtil.java | 138 --------------------- .../dsub/service/sync/PlaylistSyncAdapter.java | 2 +- .../dsub/service/sync/PodcastSyncAdapter.java | 4 +- src/github/daneren2005/dsub/util/SyncUtil.java | 134 ++++++++++++++++++++ src/github/daneren2005/dsub/view/PlaylistView.java | 2 +- .../daneren2005/dsub/view/PodcastChannelView.java | 3 +- 8 files changed, 141 insertions(+), 151 deletions(-) delete mode 100644 src/github/daneren2005/dsub/service/SyncUtil.java create mode 100644 src/github/daneren2005/dsub/util/SyncUtil.java (limited to 'src') diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 3f84a4f6..e6a49db1 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -2,10 +2,8 @@ package github.daneren2005.dsub.fragments; import android.app.AlertDialog; import android.content.DialogInterface; -import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; -import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -23,7 +21,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.OfflineException; import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.service.SyncUtil; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.CacheCleaner; import github.daneren2005.dsub.util.Constants; diff --git a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 461a613c..8b83a0c5 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -21,9 +21,6 @@ package github.daneren2005.dsub.fragments; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; -import android.text.SpannableString; -import android.text.method.LinkMovementMethod; -import android.text.util.Linkify; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -42,7 +39,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.OfflineException; import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.service.SyncUtil; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.LoadingTask; diff --git a/src/github/daneren2005/dsub/service/SyncUtil.java b/src/github/daneren2005/dsub/service/SyncUtil.java deleted file mode 100644 index 40da78c1..00000000 --- a/src/github/daneren2005/dsub/service/SyncUtil.java +++ /dev/null @@ -1,138 +0,0 @@ -package github.daneren2005.dsub.service; - -import android.content.Context; -import android.util.Log; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import github.daneren2005.dsub.util.FileUtil; -import github.daneren2005.dsub.util.Util; - -/** - * Created by Scott on 11/24/13. - */ -public final class SyncUtil { - private static String TAG = SyncUtil.class.getSimpleName(); - private static ArrayList syncedPlaylists; - private static ArrayList syncedPodcasts; - - // Playlist sync - public static boolean isSyncedPlaylist(Context context, String playlistId) { - if(syncedPlaylists == null) { - syncedPlaylists = getSyncedPlaylists(context); - } - return syncedPlaylists.contains(playlistId); - } - public static ArrayList getSyncedPlaylists(Context context) { - return getSyncedPlaylists(context, Util.getActiveServer(context)); - } - public static ArrayList getSyncedPlaylists(Context context, int instance) { - ArrayList playlists = FileUtil.deserialize(context, getPlaylistSyncFile(context, instance), ArrayList.class); - if(playlists == null) { - playlists = new ArrayList(); - } - return playlists; - } - public static void addSyncedPlaylist(Context context, String playlistId) { - String playlistFile = getPlaylistSyncFile(context); - ArrayList playlists = getSyncedPlaylists(context); - if(!playlists.contains(playlistId)) { - playlists.add(playlistId); - } - FileUtil.serialize(context, playlists, playlistFile); - syncedPlaylists = playlists; - } - public static void removeSyncedPlaylist(Context context, String playlistId) { - String playlistFile = getPlaylistSyncFile(context); - ArrayList playlists = getSyncedPlaylists(context); - if(playlists.contains(playlistId)) { - playlists.remove(playlistId); - FileUtil.serialize(context, playlists, playlistFile); - syncedPlaylists = playlists; - } - } - public static String getPlaylistSyncFile(Context context) { - int instance = Util.getActiveServer(context); - return getPlaylistSyncFile(context, instance); - } - public static String getPlaylistSyncFile(Context context, int instance) { - return "sync-playlist-" + (Util.getRestUrl(context, null, instance)).hashCode() + ".ser"; - } - - // Podcast sync - public static boolean isSyncedPodcast(Context context, String podcastId) { - if(syncedPodcasts == null) { - syncedPodcasts = getSyncedPodcasts(context); - } - return syncedPodcasts.contains(new SyncSet(podcastId)); - } - public static ArrayList getSyncedPodcasts(Context context) { - return getSyncedPodcasts(context, Util.getActiveServer(context)); - } - public static ArrayList getSyncedPodcasts(Context context, int instance) { - ArrayList podcasts = FileUtil.deserialize(context, getPodcastSyncFile(context, instance), ArrayList.class); - if(podcasts == null) { - podcasts = new ArrayList(); - } - return podcasts; - } - public static void addSyncedPodcast(Context context, String podcastId, List synced) { - String podcastFile = getPodcastSyncFile(context); - ArrayList podcasts = getSyncedPodcasts(context); - SyncSet set = new SyncSet(podcastId, synced); - if(!podcasts.contains(set)) { - podcasts.add(set); - } - FileUtil.serialize(context, podcasts, podcastFile); - syncedPodcasts = podcasts; - } - public static void removeSyncedPodcast(Context context, String podcastId) { - String podcastFile = getPodcastSyncFile(context); - ArrayList podcasts = getSyncedPodcasts(context); - SyncSet set = new SyncSet(podcastId); - if(podcasts.contains(set)) { - podcasts.remove(set); - FileUtil.serialize(context, podcasts, podcastFile); - syncedPodcasts = podcasts; - } - } - public static String getPodcastSyncFile(Context context) { - int instance = Util.getActiveServer(context); - return getPodcastSyncFile(context, instance); - } - public static String getPodcastSyncFile(Context context, int instance) { - return "sync-podcast-" + (Util.getRestUrl(context, null, instance)).hashCode() + ".ser"; - } - - public static class SyncSet implements Serializable { - public String id; - public List synced; - - protected SyncSet() { - - } - public SyncSet(String id) { - this.id = id; - } - public SyncSet(String id, List synced) { - this.id = id; - this.synced = synced; - } - - @Override - public boolean equals(Object obj) { - if(obj instanceof SyncSet) { - return this.id.equals(((SyncSet)obj).id); - } else { - return false; - } - } - - @Override - public int hashCode() { - return id.hashCode(); - } - } -} diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java index 48bc9161..a709384b 100644 --- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java @@ -27,7 +27,7 @@ import java.util.List; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; -import github.daneren2005.dsub.service.SyncUtil; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.Util; /** diff --git a/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java index b5807e92..3d9b8168 100644 --- a/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java @@ -30,8 +30,8 @@ import java.util.List; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PodcastEpisode; import github.daneren2005.dsub.service.DownloadFile; -import github.daneren2005.dsub.service.SyncUtil; -import github.daneren2005.dsub.service.SyncUtil.SyncSet; +import github.daneren2005.dsub.util.SyncUtil; +import github.daneren2005.dsub.util.SyncUtil.SyncSet; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.Util; diff --git a/src/github/daneren2005/dsub/util/SyncUtil.java b/src/github/daneren2005/dsub/util/SyncUtil.java new file mode 100644 index 00000000..463baf9e --- /dev/null +++ b/src/github/daneren2005/dsub/util/SyncUtil.java @@ -0,0 +1,134 @@ +package github.daneren2005.dsub.util; + +import android.content.Context; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Scott on 11/24/13. + */ +public final class SyncUtil { + private static String TAG = SyncUtil.class.getSimpleName(); + private static ArrayList syncedPlaylists; + private static ArrayList syncedPodcasts; + + // Playlist sync + public static boolean isSyncedPlaylist(Context context, String playlistId) { + if(syncedPlaylists == null) { + syncedPlaylists = getSyncedPlaylists(context); + } + return syncedPlaylists.contains(playlistId); + } + public static ArrayList getSyncedPlaylists(Context context) { + return getSyncedPlaylists(context, Util.getActiveServer(context)); + } + public static ArrayList getSyncedPlaylists(Context context, int instance) { + ArrayList playlists = FileUtil.deserialize(context, getPlaylistSyncFile(context, instance), ArrayList.class); + if(playlists == null) { + playlists = new ArrayList(); + } + return playlists; + } + public static void addSyncedPlaylist(Context context, String playlistId) { + String playlistFile = getPlaylistSyncFile(context); + ArrayList playlists = getSyncedPlaylists(context); + if(!playlists.contains(playlistId)) { + playlists.add(playlistId); + } + FileUtil.serialize(context, playlists, playlistFile); + syncedPlaylists = playlists; + } + public static void removeSyncedPlaylist(Context context, String playlistId) { + String playlistFile = getPlaylistSyncFile(context); + ArrayList playlists = getSyncedPlaylists(context); + if(playlists.contains(playlistId)) { + playlists.remove(playlistId); + FileUtil.serialize(context, playlists, playlistFile); + syncedPlaylists = playlists; + } + } + public static String getPlaylistSyncFile(Context context) { + int instance = Util.getActiveServer(context); + return getPlaylistSyncFile(context, instance); + } + public static String getPlaylistSyncFile(Context context, int instance) { + return "sync-playlist-" + (Util.getRestUrl(context, null, instance)).hashCode() + ".ser"; + } + + // Podcast sync + public static boolean isSyncedPodcast(Context context, String podcastId) { + if(syncedPodcasts == null) { + syncedPodcasts = getSyncedPodcasts(context); + } + return syncedPodcasts.contains(new SyncSet(podcastId)); + } + public static ArrayList getSyncedPodcasts(Context context) { + return getSyncedPodcasts(context, Util.getActiveServer(context)); + } + public static ArrayList getSyncedPodcasts(Context context, int instance) { + ArrayList podcasts = FileUtil.deserialize(context, getPodcastSyncFile(context, instance), ArrayList.class); + if(podcasts == null) { + podcasts = new ArrayList(); + } + return podcasts; + } + public static void addSyncedPodcast(Context context, String podcastId, List synced) { + String podcastFile = getPodcastSyncFile(context); + ArrayList podcasts = getSyncedPodcasts(context); + SyncSet set = new SyncSet(podcastId, synced); + if(!podcasts.contains(set)) { + podcasts.add(set); + } + FileUtil.serialize(context, podcasts, podcastFile); + syncedPodcasts = podcasts; + } + public static void removeSyncedPodcast(Context context, String podcastId) { + String podcastFile = getPodcastSyncFile(context); + ArrayList podcasts = getSyncedPodcasts(context); + SyncSet set = new SyncSet(podcastId); + if(podcasts.contains(set)) { + podcasts.remove(set); + FileUtil.serialize(context, podcasts, podcastFile); + syncedPodcasts = podcasts; + } + } + public static String getPodcastSyncFile(Context context) { + int instance = Util.getActiveServer(context); + return getPodcastSyncFile(context, instance); + } + public static String getPodcastSyncFile(Context context, int instance) { + return "sync-podcast-" + (Util.getRestUrl(context, null, instance)).hashCode() + ".ser"; + } + + public static class SyncSet implements Serializable { + public String id; + public List synced; + + protected SyncSet() { + + } + public SyncSet(String id) { + this.id = id; + } + public SyncSet(String id, List synced) { + this.id = id; + this.synced = synced; + } + + @Override + public boolean equals(Object obj) { + if(obj instanceof SyncSet) { + return this.id.equals(((SyncSet)obj).id); + } else { + return false; + } + } + + @Override + public int hashCode() { + return id.hashCode(); + } + } +} diff --git a/src/github/daneren2005/dsub/view/PlaylistView.java b/src/github/daneren2005/dsub/view/PlaylistView.java index 63ba4f5c..8b5e8ca9 100644 --- a/src/github/daneren2005/dsub/view/PlaylistView.java +++ b/src/github/daneren2005/dsub/view/PlaylistView.java @@ -26,7 +26,7 @@ import android.widget.ImageView; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Playlist; -import github.daneren2005.dsub.service.SyncUtil; +import github.daneren2005.dsub.util.SyncUtil; /** * Used to display albums in a {@code ListView}. diff --git a/src/github/daneren2005/dsub/view/PodcastChannelView.java b/src/github/daneren2005/dsub/view/PodcastChannelView.java index 8b0f4b84..aff97524 100644 --- a/src/github/daneren2005/dsub/view/PodcastChannelView.java +++ b/src/github/daneren2005/dsub/view/PodcastChannelView.java @@ -19,7 +19,6 @@ package github.daneren2005.dsub.view; import android.content.Context; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; @@ -27,7 +26,7 @@ import android.widget.ImageView; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.PodcastChannel; -import github.daneren2005.dsub.service.SyncUtil; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.FileUtil; import java.io.File; -- cgit v1.2.3