From fa7631c85f6672773a2a07b0c921f29eddc1897a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 25 Dec 2013 13:03:38 -0800 Subject: Added a function for unpinning a song --- .../daneren2005/dsub/service/sync/PlaylistSyncAdapter.java | 10 +--------- .../daneren2005/dsub/service/sync/StarredSyncAdapter.java | 9 +-------- src/github/daneren2005/dsub/util/FileUtil.java | 10 ++++++++++ 3 files changed, 12 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java index b3f605e5..a1b20f73 100644 --- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java @@ -103,15 +103,7 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { if(origPathList.size() > 0) { for(String path: origPathList) { File saveFile = new File(path); - - // Unpin file, rename to .complete - File completeFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) + - ".complete." + FileUtil.getExtension(saveFile.getName())); - - if(!saveFile.renameTo(completeFile)) { - Log.w(TAG, "Failed to rename " + path + " to " + completeFile.getPath()); - } - + FileUtil.unpinSong(saveFile); cachedPlaylist.synced.remove(path); } diff --git a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java index a363a470..a23fa63f 100644 --- a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java @@ -65,14 +65,7 @@ public class StarredSyncAdapter extends SubsonicSyncAdapter { for(String path: oldSyncedList) { File saveFile = new File(path); - - // Unpin file, rename to .complete - File completeFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) + - ".complete." + FileUtil.getExtension(saveFile.getName())); - - if(!saveFile.renameTo(completeFile)) { - Log.w(TAG, "Failed to rename " + path + " to " + completeFile.getPath()); - } + FileUtil.unpinSong(saveFile); } SyncUtil.setSyncedStarred(syncedList, context, instance); diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index 3adf3ad4..57c21e98 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -242,6 +242,16 @@ public class FileUtil { } } + public static void unpinSong(File saveFile) { + // Unpin file, rename to .complete + File completeFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) + + ".complete." + FileUtil.getExtension(saveFile.getName())); + + if(!saveFile.renameTo(completeFile)) { + Log.w(TAG, "Failed to rename " + saveFile + " to " + completeFile); + } + } + public static boolean ensureDirectoryExistsAndIsReadWritable(File dir) { if (dir == null) { return false; -- cgit v1.2.3