diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-10-29 17:17:26 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-10-29 17:17:26 -0700 |
commit | 049501f0f1aa5bace4af1ff90cb076fc220ba0f4 (patch) | |
tree | 4acc2343d4fcfa606533cc2535b274696607a59b /app/src/main/java | |
parent | 60176f016fc8814ea2f57f6bacc14c8e1cc31c76 (diff) | |
download | dsub-049501f0f1aa5bace4af1ff90cb076fc220ba0f4.tar.gz dsub-049501f0f1aa5bace4af1ff90cb076fc220ba0f4.tar.bz2 dsub-049501f0f1aa5bace4af1ff90cb076fc220ba0f4.zip |
Fix Podcasts missing cover art in offline mode
Diffstat (limited to 'app/src/main/java')
4 files changed, 25 insertions, 9 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 82c36333..b77d6746 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -53,12 +53,14 @@ import java.util.List; public class SelectPodcastsFragment extends SelectRecyclerFragment<Serializable> { private static final String TAG = SelectPodcastsFragment.class.getSimpleName(); + private boolean hasCoverArt; private MusicDirectory newestEpisodes; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); - if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_LARGE_ALBUM_ART, true) && ServerInfo.checkServerVersion(context, "1.13")) { + hasCoverArt = ServerInfo.checkServerVersion(context, "1.13") || Util.isOffline(context); + if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_LARGE_ALBUM_ART, true) && hasCoverArt) { largeAlbums = true; } } @@ -137,7 +139,7 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment<Serializable> @Override public SectionAdapter getAdapter(List<Serializable> channels) { if(newestEpisodes == null || newestEpisodes.getChildrenSize() == 0) { - return new PodcastChannelAdapter(context, channels, ServerInfo.checkServerVersion(context, "1.13") ? getImageLoader() : null, this, largeAlbums); + return new PodcastChannelAdapter(context, channels, hasCoverArt ? getImageLoader() : null, this, largeAlbums); } else { Resources res = context.getResources(); List<String> headers = Arrays.asList(res.getString(R.string.main_albums_newest), res.getString(R.string.select_podcasts_channels)); @@ -221,7 +223,7 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment<Serializable> SectionAdapter adapter = getCurrentAdapter(); if(adapter != null) { int viewType = getCurrentAdapter().getItemViewType(position); - if (viewType == SectionAdapter.VIEW_TYPE_HEADER || viewType == PodcastChannelAdapter.VIEW_TYPE_PODCAST_EPISODE) { + if (viewType == SectionAdapter.VIEW_TYPE_HEADER || viewType == PodcastChannelAdapter.VIEW_TYPE_PODCAST_EPISODE || viewType == PodcastChannelAdapter.VIEW_TYPE_PODCAST_LEGACY) { return columns; } else { return 1; diff --git a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java index 156ffa71..c8253c91 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java @@ -737,6 +737,10 @@ public class OfflineMusicService implements MusicService { channel.setId(parts[0]); channel.setName(parts[0]); channel.setStatus("completed"); + File albumArt = FileUtil.getAlbumArtFile(context, channel); + if (albumArt.exists()) { + channel.setCoverArt(albumArt.getPath()); + } if(parts.length > 1) { channel.setUrl(parts[1]); diff --git a/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java b/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java index 946dffcc..71366e60 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java +++ b/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java @@ -186,8 +186,21 @@ public class FileUtil { return playlistDir; } + public static File getAlbumArtFile(Context context, PodcastChannel channel) { + MusicDirectory.Entry entry = new MusicDirectory.Entry(); + entry.setId(channel.getId()); + entry.setTitle(channel.getName()); + return getAlbumArtFile(context, entry); + } public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) { - if(entry.getId().indexOf("pl-") == -1) { + if(entry.getId().indexOf(ImageLoader.PLAYLIST_PREFIX) != -1) { + File dir = getAlbumArtDirectory(context); + return new File(dir, Util.md5Hex(ImageLoader.PLAYLIST_PREFIX + entry.getTitle()) + ".jpeg"); + } else if(entry.getId().indexOf(ImageLoader.PODCAST_PREFIX) != -1) { + File dir = getAlbumArtDirectory(context); + Log.d(TAG, ImageLoader.PODCAST_PREFIX + entry.getTitle()); + return new File(dir, Util.md5Hex(ImageLoader.PODCAST_PREFIX + entry.getTitle()) + ".jpeg"); + } else { File albumDir = getAlbumDirectory(context, entry); File artFile; File albumFile = getAlbumArtFile(albumDir); @@ -201,9 +214,6 @@ public class FileUtil { artFile = hexFile; } return artFile; - } else { - File playlistDir = getAlbumArtDirectory(context); - return new File(playlistDir, Util.md5Hex("pl-" + entry.getTitle()) + ".jpeg"); } } diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java index d4bd63ed..06295382 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java +++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java @@ -57,8 +57,8 @@ import github.daneren2005.dsub.util.compat.RemoteControlClientBase; */ public class ImageLoader { private static final String TAG = ImageLoader.class.getSimpleName(); - private static final String PLAYLIST_PREFIX = "pl-"; - private static final String PODCAST_PREFIX = "pc-"; + public static final String PLAYLIST_PREFIX = "pl-"; + public static final String PODCAST_PREFIX = "pc-"; private Context context; private LruCache<String, Bitmap> cache; |