diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-02-25 15:13:51 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-02-25 15:13:51 -0800 |
commit | 0de2db96e3fef9db95ee74d2e63f602db6024d3f (patch) | |
tree | 130c46809553ce09fdb406f88b5441980042ca15 | |
parent | 80af800600401fc25651a93e919f82967fb6a0bc (diff) | |
download | dsub-0de2db96e3fef9db95ee74d2e63f602db6024d3f.tar.gz dsub-0de2db96e3fef9db95ee74d2e63f602db6024d3f.tar.bz2 dsub-0de2db96e3fef9db95ee74d2e63f602db6024d3f.zip |
#294 Move to use specific sdcard dir like required by 4.4+
7 files changed, 34 insertions, 30 deletions
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index 87719e5b..f26b9347 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -476,7 +476,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer } private void setHideMedia(boolean hide) { - File nomediaDir = new File(FileUtil.getSubsonicDirectory(), ".nomedia"); + File nomediaDir = new File(FileUtil.getSubsonicDirectory(this), ".nomedia"); if (hide && !nomediaDir.exists()) { try { if (!nomediaDir.createNewFile()) { @@ -507,7 +507,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer Util.toast(this, R.string.settings_cache_location_error, false); // Reset it to the default. - String defaultPath = FileUtil.getDefaultMusicDirectory().getPath(); + String defaultPath = FileUtil.getDefaultMusicDirectory(this).getPath(); if (!defaultPath.equals(path)) { SharedPreferences prefs = Util.getPreferences(this); SharedPreferences.Editor editor = prefs.edit(); diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 982c7f80..7444229b 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -435,7 +435,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { SharedPreferences prefs = Util.getPreferences(this);
if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) {
SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath());
+ editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory(this).getPath());
editor.commit();
}
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index 296dbfb7..6ae7e491 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -344,7 +344,7 @@ public class MainFragment extends SubsonicFragment { @Override
protected File doInBackground() throws Throwable {
updateProgress("Gathering Logs");
- File logcat = new File(FileUtil.getSubsonicDirectory(), "logcat.txt");
+ File logcat = new File(FileUtil.getSubsonicDirectory(context), "logcat.txt");
Process logcatProc = null;
try {
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 6b23730f..06dd70f8 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -197,7 +197,7 @@ public class CachedMusicService implements MusicService { FileUtil.serialize(context, dir, getCacheName(context, "playlist", id)); if(cachedPlaylist == null || !cachedPlaylist.getChildren().equals(dir.getChildren())) { - File playlistFile = FileUtil.getPlaylistFile(Util.getServerName(context, musicService.getInstance(context)), name); + File playlistFile = FileUtil.getPlaylistFile(context, Util.getServerName(context, musicService.getInstance(context)), name); FileUtil.writePlaylistFile(context, playlistFile, dir); } } diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index b054eaad..2ac19ebd 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -362,7 +362,7 @@ public class OfflineMusicService extends RESTMusicService { @Override public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception { List<Playlist> playlists = new ArrayList<Playlist>(); - File root = FileUtil.getPlaylistDirectory(); + File root = FileUtil.getPlaylistDirectory(context); String lastServer = null; boolean removeServer = true; for (File folder : FileUtil.listFiles(root)) { @@ -417,7 +417,7 @@ public class OfflineMusicService extends RESTMusicService { name = name.substring(id.length() + 2); } - File playlistFile = FileUtil.getPlaylistFile(id, name); + File playlistFile = FileUtil.getPlaylistFile(context, id, name); reader = new FileReader(playlistFile); buffer = new BufferedReader(reader); diff --git a/src/github/daneren2005/dsub/util/CacheCleaner.java b/src/github/daneren2005/dsub/util/CacheCleaner.java index b83dfc02..e94d4a17 100644 --- a/src/github/daneren2005/dsub/util/CacheCleaner.java +++ b/src/github/daneren2005/dsub/util/CacheCleaner.java @@ -52,7 +52,7 @@ public class CacheCleaner { File[] children = dir.listFiles(); // No songs left in the folder - if(children.length == 1 && children[0].getPath().equals(FileUtil.getAlbumArtFile(dir).getPath())) { + if(children.length == 1 && children[0].getPath().equals(FileUtil.getAlbumArtFile(context, dir).getPath())) { Util.delete(children[0]); children = dir.listFiles(); } @@ -241,9 +241,9 @@ public class CacheCleaner { protected Void doInBackground() { try { String server = Util.getServerName(context); - SortedSet<File> playlistFiles = FileUtil.listFiles(FileUtil.getPlaylistDirectory(server)); + SortedSet<File> playlistFiles = FileUtil.listFiles(FileUtil.getPlaylistDirectory(context, server)); for (Playlist playlist : playlists) { - playlistFiles.remove(FileUtil.getPlaylistFile(server, playlist.getName())); + playlistFiles.remove(FileUtil.getPlaylistFile(context, server, playlist.getName())); } for(File playlist : playlistFiles) { diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index 3356456d..572ef639 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -70,7 +70,7 @@ public class FileUtil { private static final List<String> MUSIC_FILE_EXTENSIONS = Arrays.asList("mp3", "ogg", "aac", "flac", "m4a", "wav", "wma"); private static final List<String> VIDEO_FILE_EXTENSIONS = Arrays.asList("flv", "mp4", "m4v", "wmv", "avi", "mov", "mpg", "mkv"); private static final List<String> PLAYLIST_FILE_EXTENSIONS = Arrays.asList("m3u"); - private static final File DEFAULT_MUSIC_DIR = createDirectory("music"); + private static File DEFAULT_MUSIC_DIR; private static final Kryo kryo = new Kryo(); static { @@ -124,9 +124,9 @@ public class FileUtil { return new File(dir, fileName.toString()); } - - public static File getPlaylistFile(String server, String name) { - File playlistDir = getPlaylistDirectory(server); + + public static File getPlaylistFile(Context context, String server, String name) { + File playlistDir = getPlaylistDirectory(context, server); return new File(playlistDir, fileSystemSafe(name) + ".m3u"); } public static void writePlaylistFile(Context context, File file, MusicDirectory playlist) throws IOException { @@ -150,13 +150,13 @@ public class FileUtil { fw.close(); } } - public static File getPlaylistDirectory() { - File playlistDir = new File(getSubsonicDirectory(), "playlists"); + public static File getPlaylistDirectory(Context context) { + File playlistDir = new File(getSubsonicDirectory(context), "playlists"); ensureDirectoryExistsAndIsReadWritable(playlistDir); return playlistDir; } - public static File getPlaylistDirectory(String server) { - File playlistDir = new File(getPlaylistDirectory(), server); + public static File getPlaylistDirectory(Context context, String server) { + File playlistDir = new File(getPlaylistDirectory(context), server); ensureDirectoryExistsAndIsReadWritable(playlistDir); return playlistDir; } @@ -165,7 +165,7 @@ public class FileUtil { File albumDir = getAlbumDirectory(context, entry); File artFile; File albumFile = getAlbumArtFile(albumDir); - File hexFile = getHexAlbumArtFile(albumDir); + File hexFile = getHexAlbumArtFile(context, albumDir); if(albumDir.exists()) { if(hexFile.exists()) { hexFile.renameTo(albumFile); @@ -180,8 +180,8 @@ public class FileUtil { public static File getAlbumArtFile(File albumDir) { return new File(albumDir, Constants.ALBUM_ART_FILE); } - public static File getHexAlbumArtFile(File albumDir) { - return new File(getAlbumArtDirectory(), Util.md5Hex(albumDir.getPath()) + ".jpeg"); + public static File getHexAlbumArtFile(Context context, File albumDir) { + return new File(getAlbumArtDirectory(context), Util.md5Hex(albumDir.getPath()) + ".jpeg"); } public static Bitmap getAlbumArtBitmap(Context context, MusicDirectory.Entry entry, int size) { @@ -213,13 +213,13 @@ public class FileUtil { return Bitmap.createScaledBitmap(bitmap, size, Util.getScaledHeight(bitmap, size), true); } - public static File getAlbumArtDirectory() { - File albumArtDir = new File(getSubsonicDirectory(), "artwork"); + public static File getAlbumArtDirectory(Context context) { + File albumArtDir = new File(getSubsonicDirectory(context), "artwork"); ensureDirectoryExistsAndIsReadWritable(albumArtDir); ensureDirectoryExistsAndIsReadWritable(new File(albumArtDir, ".nomedia")); return albumArtDir; } - + public static File getArtistDirectory(Context context, Artist artist) { File dir = new File(getMusicDirectory(context).getPath() + "/" + fileSystemSafe(artist.getName())); return dir; @@ -291,24 +291,28 @@ public class FileUtil { } } - private static File createDirectory(String name) { - File dir = new File(getSubsonicDirectory(), name); + private static File createDirectory(Context context, String name) { + File dir = new File(getSubsonicDirectory(context), name); if (!dir.exists() && !dir.mkdirs()) { Log.e(TAG, "Failed to create " + name); } return dir; } - public static File getSubsonicDirectory() { - return new File(Environment.getExternalStorageDirectory(), "subsonic"); + public static File getSubsonicDirectory(Context context) { + return context.getExternalFilesDir(null); } - public static File getDefaultMusicDirectory() { + public static File getDefaultMusicDirectory(Context context) { + if(DEFAULT_MUSIC_DIR == null) { + DEFAULT_MUSIC_DIR = createDirectory(context, "music"); + } + return DEFAULT_MUSIC_DIR; } public static File getMusicDirectory(Context context) { - String path = Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, DEFAULT_MUSIC_DIR.getPath()); + String path = Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, getDefaultMusicDirectory(context).getPath()); File dir = new File(path); return ensureDirectoryExistsAndIsReadWritable(dir) ? dir : getDefaultMusicDirectory(); } |