diff options
7 files changed, 104 insertions, 384 deletions
diff --git a/res/menu/select_genres.xml b/res/menu/select_genres.xml deleted file mode 100644 index 837b3534..00000000 --- a/res/menu/select_genres.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<menu xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:compat="http://schemas.android.com/apk/res-auto"> - <item - android:id="@+id/menu_refresh" - android:icon="?attr/refresh" - android:title="@string/menu.refresh" - compat:showAsAction="always|withText"/> -</menu>
\ No newline at end of file diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index 9ea43395..c91c005c 100644 --- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -19,17 +19,13 @@ package github.daneren2005.dsub.fragments; import android.content.DialogInterface; -import android.os.Bundle; import android.util.Log; import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.ListView; +import android.widget.ArrayAdapter; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.domain.Bookmark; @@ -39,72 +35,17 @@ 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.util.BackgroundTask; -import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.LoadingTask; +import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SilentBackgroundTask; -import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.BookmarkAdapter; -import java.io.Serializable; import java.text.Format; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.List; -public class SelectBookmarkFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { +public class SelectBookmarkFragment extends SelectListFragment<Bookmark> { private static final String TAG = SelectBookmarkFragment.class.getSimpleName(); - private ListView bookmarkListView; - private View emptyView; - private List<Bookmark> bookmarks; - private BookmarkAdapter bookmarkAdapter; - - @Override - public void onCreate(Bundle bundle) { - super.onCreate(bundle); - - if(bundle != null) { - bookmarks = (List<Bookmark>) bundle.getSerializable(Constants.FRAGMENT_LIST); - } - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) bookmarks); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false); - - bookmarkListView = (ListView)rootView.findViewById(R.id.fragment_list); - bookmarkListView.setOnItemClickListener(this); - registerForContextMenu(bookmarkListView); - emptyView = rootView.findViewById(R.id.fragment_list_empty); - - if(bookmarks == null) { - refresh(); - } else { - bookmarkListView.setAdapter(new BookmarkAdapter(context, bookmarks)); - } - - return rootView; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { - menuInflater.inflate(R.menu.abstract_top_menu, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if(super.onOptionsItemSelected(item)) { - return true; - } - - return false; - } @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { @@ -117,7 +58,7 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV @Override public boolean onContextItemSelected(MenuItem menuItem) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Bookmark bookmark = bookmarks.get(info.position); + Bookmark bookmark = objects.get(info.position); switch(menuItem.getItemId()) { case R.id.bookmark_menu_info: @@ -134,39 +75,25 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV return true; } - + @Override - protected void refresh(final boolean refresh) { - setTitle(R.string.button_bar_bookmarks); - bookmarkListView.setVisibility(View.INVISIBLE); - - BackgroundTask<List<Bookmark>> task = new TabBackgroundTask<List<Bookmark>>(this) { - @Override - protected List<Bookmark> doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - - bookmarks = new ArrayList<Bookmark>(); - - try { - bookmarks = musicService.getBookmarks(refresh, context, this); - } catch (Exception x) { - Log.e(TAG, "Failed to load bookmarks", x); - } - - return bookmarks; - } - - @Override - protected void done(List<Bookmark> result) { - emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE); - - if (result != null) { - bookmarkListView.setAdapter(bookmarkAdapter = new BookmarkAdapter(context, result)); - bookmarkListView.setVisibility(View.VISIBLE); - } - } - }; - task.execute(); + public int getOptionsMenu() { + return R.menu.abstract_top_menu; + } + + @Override + public ArrayAdapter getAdapter(List<Bookmark> bookmarks) { + return new BookmarkAdapter(context, bookmarks); + } + + @Override + public List<Bookmark> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + return musicService.getBookmarks(refresh, context, listener); + } + + @Override + public int getTitleResource() { + return R.string.button_bar_bookmarks; } @Override @@ -219,8 +146,8 @@ public class SelectBookmarkFragment extends SubsonicFragment implements AdapterV @Override protected void done(Void result) { - bookmarkAdapter.remove(bookmark); - bookmarkAdapter.notifyDataSetChanged(); + adapter.remove(bookmark); + adapter.notifyDataSetChanged(); Util.toast(context, context.getResources().getString(R.string.bookmark_deleted, entry.getTitle())); } diff --git a/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java b/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java index 4f0b8a03..fd0bbf4a 100644 --- a/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java @@ -20,119 +20,39 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle;
import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.AdapterView;
-import android.widget.ListView;
+import android.widget.ArrayAdapter;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
-import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.TabBackgroundTask;
+import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.view.GenreAdapter;
-import java.io.Serializable;
-import java.util.ArrayList;
import java.util.List;
-public class SelectGenreFragment extends SubsonicFragment implements AdapterView.OnItemClickListener {
+public class SelectGenreFragment extends SelectListFragment<Genre> {
private static final String TAG = SelectGenreFragment.class.getSimpleName();
- private ListView genreListView;
- private View emptyView;
- private List<Genre> genres;
@Override
- public void onCreate(Bundle bundle) {
- super.onCreate(bundle);
-
- if(bundle != null) {
- genres = (List<Genre>) bundle.getSerializable(Constants.FRAGMENT_LIST);
- }
+ public int getOptionsMenu() {
+ return R.menu.empty;
}
@Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) genres);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
- rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
-
- genreListView = (ListView)rootView.findViewById(R.id.fragment_list);
- genreListView.setOnItemClickListener(this);
- emptyView = rootView.findViewById(R.id.fragment_list_empty);
-
- if(genres == null) {
- refresh();
- } else {
- genreListView.setAdapter(new GenreAdapter(context, genres));
- }
-
- return rootView;
+ public ArrayAdapter getAdapter(List<Genre> objs) {
+ return new GenreAdapter(context, objs);
}
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
- if(!primaryFragment) {
- return;
- }
- menuInflater.inflate(R.menu.select_genres, menu);
- }
-
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
-
- return false;
+ public List<Genre> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
+ return musicService.getGenres(refresh, context, listener);
}
@Override
- protected void refresh(boolean refresh) {
- load(refresh);
- }
-
- private void load(final boolean refresh) {
- setTitle(R.string.main_albums_genres);
- genreListView.setVisibility(View.INVISIBLE);
-
- BackgroundTask<List<Genre>> task = new TabBackgroundTask<List<Genre>>(this) {
- @Override
- protected List<Genre> doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
-
- genres = new ArrayList<Genre>();
-
- try {
- genres = musicService.getGenres(refresh, context, this);
- } catch (Exception x) {
- Log.e(TAG, "Failed to load genres", x);
- }
-
- return genres;
- }
-
- @Override
- protected void done(List<Genre> result) {
- emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE);
-
- if (result != null) {
- genreListView.setAdapter(new GenreAdapter(context, result));
- genreListView.setVisibility(View.VISIBLE);
- }
- }
- };
- task.execute();
+ public int getTitleResource() {
+ return R.string.main_albums_genres;
}
@Override
diff --git a/src/github/daneren2005/dsub/fragments/SelectListFragment.java b/src/github/daneren2005/dsub/fragments/SelectListFragment.java index e6f78928..b4288e28 100644 --- a/src/github/daneren2005/dsub/fragments/SelectListFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectListFragment.java @@ -28,6 +28,7 @@ import android.view.View; import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
@@ -41,14 +42,16 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.TabBackgroundTask;
import github.daneren2005.dsub.view.GenreAdapter;
public abstract class SelectListFragment<T> extends SubsonicFragment implements AdapterView.OnItemClickListener {
private static final String TAG = SelectListFragment.class.getSimpleName();
- private ListView listView;
- private View emptyView;
- private List<T> objects;
+ protected ListView listView;
+ protected ArrayAdapter adapter;
+ protected View emptyView;
+ protected List<T> objects;
@Override
public void onCreate(Bundle bundle) {
@@ -71,6 +74,7 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements listView = (ListView)rootView.findViewById(R.id.fragment_list);
listView.setOnItemClickListener(this);
+ registerForContextMenu(listView);
emptyView = rootView.findViewById(R.id.fragment_list_empty);
if(objects == null) {
@@ -101,7 +105,7 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements }
@Override
- protected void refresh(boolean refresh) {
+ protected void refresh(final boolean refresh) {
setTitle(getTitleResource());
listView.setVisibility(View.INVISIBLE);
@@ -113,7 +117,7 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements objects = new ArrayList<T>();
try {
- objects = getObjects(musicService);
+ objects = getObjects(musicService, refresh, this);
} catch (Exception x) {
Log.e(TAG, "Failed to load", x);
}
@@ -126,8 +130,7 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE);
if (result != null) {
- // TODO:
- listView.setAdapter(getAdapter(result));
+ listView.setAdapter(adapter = getAdapter(result));
listView.setVisibility(View.VISIBLE);
}
}
@@ -136,7 +139,7 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements }
public abstract int getOptionsMenu();
- public abstract ListAdapter getAdapter(List<T> objs);
- public abstract List<T> getObjects(MusicService musicService);
+ public abstract ArrayAdapter getAdapter(List<T> objs);
+ public abstract List<T> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception;
public abstract int getTitleResource();
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 93e54ce4..615bbe71 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -12,6 +12,7 @@ import android.view.MenuItem; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
@@ -21,6 +22,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.util.ProgressListener;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.CacheCleaner;
@@ -33,65 +35,9 @@ import github.daneren2005.dsub.view.PlaylistAdapter; import java.io.Serializable;
import java.util.List;
-public class SelectPlaylistFragment extends SubsonicFragment implements AdapterView.OnItemClickListener {
+public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
private static final String TAG = SelectPlaylistFragment.class.getSimpleName();
- private ListView list;
- private View emptyTextView;
- private PlaylistAdapter playlistAdapter;
- private List<Playlist> playlists;
-
- @Override
- public void onCreate(Bundle bundle) {
- super.onCreate(bundle);
-
- if(bundle != null) {
- playlists = (List<Playlist>) bundle.getSerializable(Constants.FRAGMENT_LIST);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) playlists);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
- rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
-
- list = (ListView) rootView.findViewById(R.id.fragment_list);
- emptyTextView = rootView.findViewById(R.id.fragment_list_empty);
- list.setOnItemClickListener(this);
- registerForContextMenu(list);
-
- if(playlists == null) {
- if(!primaryFragment) {
- invalidated = true;
- } else {
- refresh(false);
- }
- } else {
- list.setAdapter(playlistAdapter = new PlaylistAdapter(context, playlists));
- }
-
- return rootView;
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
- menuInflater.inflate(R.menu.abstract_top_menu, menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
-
- return false;
- }
-
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
@@ -104,7 +50,7 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV inflater.inflate(R.menu.select_playlist_context, menu);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- Playlist playlist = (Playlist) list.getItemAtPosition(info.position);
+ Playlist playlist = (Playlist) listView.getItemAtPosition(info.position);
if(SyncUtil.isSyncedPlaylist(context, playlist.getId())) {
menu.removeItem(R.id.playlist_menu_sync);
} else {
@@ -122,7 +68,7 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV }
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
- Playlist playlist = (Playlist) list.getItemAtPosition(info.position);
+ Playlist playlist = (Playlist) listView.getItemAtPosition(info.position);
SubsonicFragment fragment;
Bundle args;
@@ -174,6 +120,30 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV }
@Override
+ public int getOptionsMenu() {
+ return R.menu.abstract_top_menu;
+ }
+
+ @Override
+ public ArrayAdapter getAdapter(List<Playlist> playlists) {
+ return new PlaylistAdapter(context, playlists);
+ }
+
+ @Override
+ public List<Playlist> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
+ List<Playlist> playlists = musicService.getPlaylists(refresh, context, listener);
+ if(!Util.isOffline(context) && refresh) {
+ new CacheCleaner(context, getDownloadService()).cleanPlaylists(playlists);
+ }
+ return playlists;
+ }
+
+ @Override
+ public int getTitleResource() {
+ return R.string.playlist_label;
+ }
+
+ @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Playlist playlist = (Playlist) parent.getItemAtPosition(position);
@@ -186,37 +156,6 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV replaceFragment(fragment, R.id.fragment_list_layout);
}
- @Override
- protected void refresh(boolean refresh) {
- load(refresh);
- }
-
- private void load(final boolean refresh) {
- setTitle(R.string.playlist_label);
- list.setVisibility(View.INVISIBLE);
- emptyTextView.setVisibility(View.GONE);
-
- BackgroundTask<List<Playlist>> task = new TabBackgroundTask<List<Playlist>>(this) {
- @Override
- protected List<Playlist> doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- playlists = musicService.getPlaylists(refresh, context, this);
- if(!Util.isOffline(context) && refresh) {
- new CacheCleaner(context, getDownloadService()).cleanPlaylists(playlists);
- }
- return playlists;
- }
-
- @Override
- protected void done(List<Playlist> result) {
- list.setAdapter(playlistAdapter = new PlaylistAdapter(context, result));
- emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
- list.setVisibility(View.VISIBLE);
- }
- };
- task.execute();
- }
-
private void deletePlaylist(final Playlist playlist) {
Util.confirmDialog(context, R.string.common_delete, playlist.getName(), new DialogInterface.OnClickListener() {
@Override
@@ -232,8 +171,8 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV @Override
protected void done(Void result) {
- playlistAdapter.remove(playlist);
- playlistAdapter.notifyDataSetChanged();
+ adapter.remove(playlist);
+ adapter.notifyDataSetChanged();
Util.toast(context, context.getResources().getString(R.string.menu_deleted_playlist, playlist.getName()));
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 1ff51813..fde45b0f 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -30,6 +30,7 @@ import android.view.MenuItem; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
@@ -39,6 +40,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.util.ProgressListener;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
@@ -56,54 +58,8 @@ import java.util.List; *
* @author Scott
*/
-public class SelectPodcastsFragment extends SubsonicFragment implements AdapterView.OnItemClickListener {
+public class SelectPodcastsFragment extends SelectListFragment<PodcastChannel> {
private static final String TAG = SelectPodcastsFragment.class.getSimpleName();
- private ListView podcastListView;
- private PodcastChannelAdapter podcastAdapter;
- private View emptyView;
- private List<PodcastChannel> channels;
-
- @Override
- public void onCreate(Bundle bundle) {
- super.onCreate(bundle);
-
- if(bundle != null) {
- channels = (List<PodcastChannel>) bundle.getSerializable(Constants.FRAGMENT_LIST);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) channels);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
- rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
-
- podcastListView = (ListView)rootView.findViewById(R.id.fragment_list);
- podcastListView.setOnItemClickListener(this);
- registerForContextMenu(podcastListView);
- emptyView = rootView.findViewById(R.id.fragment_list_empty);
-
- if(channels == null) {
- if(!primaryFragment) {
- invalidated = true;
- } else {
- refresh(false);
- }
- } else {
- podcastListView.setAdapter(podcastAdapter = new PodcastChannelAdapter(context, channels));
- }
-
- return rootView;
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
- menuInflater.inflate(R.menu.select_podcasts, menu);
- }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@@ -132,7 +88,7 @@ public class SelectPodcastsFragment extends SubsonicFragment implements AdapterV inflater.inflate(R.menu.select_podcasts_context, menu);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- PodcastChannel podcast = (PodcastChannel) podcastListView.getItemAtPosition(info.position);
+ PodcastChannel podcast = (PodcastChannel) listView.getItemAtPosition(info.position);
if(SyncUtil.isSyncedPodcast(context, podcast.getId())) {
menu.removeItem(R.id.podcast_menu_sync);
} else {
@@ -150,7 +106,7 @@ public class SelectPodcastsFragment extends SubsonicFragment implements AdapterV }
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
- PodcastChannel channel = (PodcastChannel) podcastListView.getItemAtPosition(info.position);
+ PodcastChannel channel = (PodcastChannel) listView.getItemAtPosition(info.position);
switch (menuItem.getItemId()) {
case R.id.podcast_menu_sync:
@@ -169,42 +125,27 @@ public class SelectPodcastsFragment extends SubsonicFragment implements AdapterV return true;
}
-
- @Override
- protected void refresh(final boolean refresh) {
- setTitle(R.string.button_bar_podcasts);
- podcastListView.setVisibility(View.INVISIBLE);
- emptyView.setVisibility(View.GONE);
-
- BackgroundTask<List<PodcastChannel>> task = new TabBackgroundTask<List<PodcastChannel>>(this) {
- @Override
- protected List<PodcastChannel> doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- channels = new ArrayList<PodcastChannel>();
-
- try {
- channels = musicService.getPodcastChannels(refresh, context, this);
- } catch (Exception x) {
- Log.e(TAG, "Failed to load podcasts", x);
- }
+ @Override
+ public int getOptionsMenu() {
+ return R.menu.select_podcasts;
+ }
- return channels;
- }
+ @Override
+ public ArrayAdapter getAdapter(List<PodcastChannel> channels) {
+ return new PodcastChannelAdapter(context, channels);
+ }
- @Override
- protected void done(List<PodcastChannel> result) {
- emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE);
+ @Override
+ public List<PodcastChannel> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
+ return musicService.getPodcastChannels(refresh, context, listener);
+ }
- if (result != null) {
- podcastListView.setAdapter(podcastAdapter = new PodcastChannelAdapter(context, result));
- podcastListView.setVisibility(View.VISIBLE);
- }
- }
- };
- task.execute();
+ @Override
+ public int getTitleResource() {
+ return R.string.button_bar_podcasts;
}
-
+
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PodcastChannel channel = (PodcastChannel) parent.getItemAtPosition(position);
@@ -323,8 +264,8 @@ public class SelectPodcastsFragment extends SubsonicFragment implements AdapterV @Override
protected void done(Void result) {
- podcastAdapter.remove(channel);
- podcastAdapter.notifyDataSetChanged();
+ adapter.remove(channel);
+ adapter.notifyDataSetChanged();
Util.toast(context, context.getResources().getString(R.string.select_podcasts_deleted, channel.getName()));
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectYearFragment.java b/src/github/daneren2005/dsub/fragments/SelectYearFragment.java index acd3154a..ee60bf69 100644 --- a/src/github/daneren2005/dsub/fragments/SelectYearFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectYearFragment.java @@ -22,15 +22,14 @@ import android.os.Bundle; import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
-import android.widget.ListAdapter;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.ProgressListener;
/**
* Created by Scott on 12/23/13.
@@ -43,12 +42,12 @@ public class SelectYearFragment extends SelectListFragment<Integer> { }
@Override
- public ListAdapter getAdapter(List<Integer> objs) {
+ public ArrayAdapter getAdapter(List<Integer> objs) {
return new ArrayAdapter<Integer>(context, android.R.layout.simple_list_item_1, objs);
}
@Override
- public List<Integer> getObjects(MusicService musicService) {
+ public List<Integer> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
List<Integer> decades = new ArrayList<Integer>();
for(int i = 2010; i >= 1920; i -= 10) {
decades.add(i);
|