@Override public List<Serializable> getObjects( MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { List<PodcastChannel> channels = musicService.getPodcastChannels(refresh, context, listener); if (!Util.isOffline(context) && ServerInfo.hasNewestPodcastEpisodes(context)) { try { newestEpisodes = musicService.getNewestPodcastEpisodes(10, context, listener); for (MusicDirectory.Entry entry : newestEpisodes.getChildren()) { for (PodcastChannel channel : channels) { if (channel.getId().equals(entry.getParent())) { PodcastEpisode episode = (PodcastEpisode) entry; // Update with information normally done in PodcastEntryParser episode.setArtist(channel.getName()); episode.setCoverArt(channel.getCoverArt()); episode.setPath(FileUtil.getPodcastPath(context, episode)); break; } } } } catch (Exception e) { Log.e(TAG, "Failed to download newest episodes", e); newestEpisodes = null; } } else { newestEpisodes = null; } List<Serializable> serializableList = new ArrayList<>(); serializableList.addAll(channels); return serializableList; }
@Override public SectionAdapter getAdapter(List<Serializable> channels) { if (newestEpisodes == null || newestEpisodes.getChildrenSize() == 0) { return new PodcastChannelAdapter( context, channels, hasCoverArt ? getImageLoader() : null, this, largeAlbums); } else { List<String> headers = Arrays.asList(PodcastChannelAdapter.EPISODE_HEADER, PodcastChannelAdapter.CHANNEL_HEADER); List<MusicDirectory.Entry> episodes = newestEpisodes.getChildren(false, true); List<Serializable> serializableEpisodes = new ArrayList<>(); // Put 3 in current list while (serializableEpisodes.size() < 3 && !episodes.isEmpty()) { serializableEpisodes.add(episodes.remove(0)); } // Put rest in extra set List<Serializable> extraEpisodes = new ArrayList<>(); extraEpisodes.addAll(episodes); List<List<Serializable>> sections = new ArrayList<>(); sections.add(serializableEpisodes); sections.add(channels); return new PodcastChannelAdapter( context, headers, sections, extraEpisodes, ServerInfo.checkServerVersion(context, "1.13") ? getImageLoader() : null, this, largeAlbums); } }
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); hasCoverArt = ServerInfo.checkServerVersion(context, "1.13") || Util.isOffline(context); if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_LARGE_ALBUM_ART, true) && hasCoverArt) { largeAlbums = true; } if (bundle != null && serialize) { newestEpisodes = (MusicDirectory) bundle.getSerializable(Constants.FRAGMENT_LIST2); } }
private void populateTabs() { drawerList.getMenu().clear(); drawerList.inflateMenu(R.menu.drawer_navigation); SharedPreferences prefs = Util.getPreferences(this); boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true); boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true) && !Util.isOffline(this) && ServerInfo.canBookmark(this); boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this); boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true) && !Util.isOffline(this); boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true) && !Util.isOffline(this); MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline); if (Util.isOffline(this)) { setDrawerItemVisible(R.id.drawer_home, false); if (lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_home) { String newFragment = Util.openToTab(this); if (newFragment == null || "Home".equals(newFragment)) { newFragment = "Artist"; } lastSelectedPosition = getDrawerItemId(newFragment); drawerItemSelected(newFragment); } offlineMenuItem.setTitle(R.string.main_online); } else { offlineMenuItem.setTitle(R.string.main_offline); } if (!podcastsEnabled) { setDrawerItemVisible(R.id.drawer_podcasts, false); } if (!bookmarksEnabled) { setDrawerItemVisible(R.id.drawer_bookmarks, false); } if (!sharedEnabled) { setDrawerItemVisible(R.id.drawer_shares, false); } if (!chatEnabled) { setDrawerItemVisible(R.id.drawer_chat, false); } if (!adminEnabled) { setDrawerItemVisible(R.id.drawer_admin, false); } if (lastSelectedPosition != 0) { MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition); if (item != null) { item.setChecked(true); } } drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark); showingTabs = true; }