diff options
Diffstat (limited to 'src/de/danoeh/antennapod/fragment')
3 files changed, 0 insertions, 885 deletions
diff --git a/src/de/danoeh/antennapod/fragment/EpisodesFragment.java b/src/de/danoeh/antennapod/fragment/EpisodesFragment.java deleted file mode 100644 index 3c79a8c10..000000000 --- a/src/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ /dev/null @@ -1,327 +0,0 @@ -package de.danoeh.antennapod.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.*; -import android.view.ContextMenu.ContextMenuInfo; -import android.widget.ExpandableListView; -import android.widget.ExpandableListView.OnChildClickListener; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.ItemviewActivity; -import de.danoeh.antennapod.activity.OrganizeQueueActivity; -import de.danoeh.antennapod.adapter.ActionButtonCallback; -import de.danoeh.antennapod.adapter.ExternalEpisodesListAdapter; -import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; -import de.danoeh.antennapod.feed.EventDistributor; -import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.storage.DBReader; -import de.danoeh.antennapod.storage.DBTasks; -import de.danoeh.antennapod.storage.DBWriter; -import de.danoeh.antennapod.storage.DownloadRequestException; -import de.danoeh.antennapod.util.QueueAccess; -import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler; - -import java.util.List; - -public class EpisodesFragment extends Fragment { - private static final String TAG = "EpisodesFragment"; - - private static final int EVENTS = EventDistributor.QUEUE_UPDATE - | EventDistributor.UNREAD_ITEMS_UPDATE - | EventDistributor.FEED_LIST_UPDATE - | EventDistributor.DOWNLOAD_HANDLED - | EventDistributor.DOWNLOAD_QUEUED; - - private ExpandableListView listView; - private ExternalEpisodesListAdapter adapter; - - private List<FeedItem> queue; - private List<FeedItem> unreadItems; - - protected FeedItem selectedItem = null; - protected long selectedGroupId = -1; - protected boolean contextMenuClosed = true; - - @Override - public void onDestroy() { - super.onDestroy(); - EventDistributor.getInstance().unregister(contentUpdate); - } - - @Override - public void onResume() { - super.onResume(); - - EventDistributor.getInstance().register(contentUpdate); - if (adapter != null) { - adapter.notifyDataSetChanged(); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.episodes_fragment, null); - listView = (ExpandableListView) v.findViewById(android.R.id.list); - return v; - } - - protected ActionButtonCallback adapterCallback = new ActionButtonCallback() { - - @Override - public void onActionButtonPressed(FeedItem item) { - resetContextMenuSelection(); - selectedItem = item; - listView.showContextMenu(); - } - }; - - protected ExternalEpisodesListAdapter.OnGroupActionClicked groupActionCallback = new ExternalEpisodesListAdapter.OnGroupActionClicked() { - - @Override - public void onClick(long groupId) { - resetContextMenuSelection(); - selectedGroupId = groupId; - listView.showContextMenu(); - } - }; - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - adapter = new ExternalEpisodesListAdapter(getActivity(), - adapterCallback, groupActionCallback, itemAccess); - listView.setAdapter(adapter); - listView.expandGroup(ExternalEpisodesListAdapter.GROUP_POS_QUEUE); - listView.expandGroup(ExternalEpisodesListAdapter.GROUP_POS_UNREAD); - listView.setOnChildClickListener(new OnChildClickListener() { - - @Override - public boolean onChildClick(ExpandableListView parent, View v, - int groupPosition, int childPosition, long id) { - FeedItem selection = adapter.getChild(groupPosition, - childPosition); - if (selection != null) { - Intent showItem = new Intent(getActivity(), - ItemviewActivity.class); - showItem.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED, - selection.getFeed().getId()); - showItem.putExtra(ItemlistFragment.EXTRA_SELECTED_FEEDITEM, - selection.getId()); - - startActivity(showItem); - return true; - } - return true; - } - }); - loadData(); - registerForContextMenu(listView); - - } - - ExternalEpisodesListAdapter.ItemAccess itemAccess = new ExternalEpisodesListAdapter.ItemAccess() { - - @Override - public int getQueueSize() { - return (queue != null) ? queue.size() : 0; - } - - @Override - public int getUnreadItemsSize() { - return (unreadItems != null) ? unreadItems.size() : 0; - } - - @Override - public FeedItem getQueueItemAt(int position) { - return (queue != null) ? queue.get(position) : null; - } - - @Override - public FeedItem getUnreadItemAt(int position) { - return (unreadItems != null) ? unreadItems.get(position) : null; - } - }; - - private void loadData() { - AsyncTask<Void, Void, Void> loadTask = new AsyncTask<Void, Void, Void>() { - private volatile List<FeedItem> queueRef; - private volatile List<FeedItem> unreadItemsRef; - - @Override - protected Void doInBackground(Void... voids) { - if (BuildConfig.DEBUG) Log.d(TAG, "Starting to load list data"); - Context context = EpisodesFragment.this.getActivity(); - if (context != null) { - queueRef = DBReader.getQueue(context); - unreadItemsRef = DBReader.getUnreadItemsList(context); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (queueRef != null && unreadItemsRef != null) { - if (BuildConfig.DEBUG) Log.d(TAG, "Done loading list data"); - queue = queueRef; - unreadItems = unreadItemsRef; - if (adapter != null) { - adapter.notifyDataSetChanged(); - } - } else { - if (queueRef == null) { - Log.e(TAG, "Could not load queue"); - } - if (unreadItemsRef == null) { - Log.e(TAG, "Could not load unread items"); - } - } - } - }; - loadTask.execute(); - } - - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EVENTS & arg) != 0) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Received contentUpdate Intent."); - loadData(); - } - } - }; - - @Override - public void onCreateContextMenu(final ContextMenu menu, View v, - ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); - if (!contextMenuClosed) { // true if context menu was cancelled before - resetContextMenuSelection(); - } - contextMenuClosed = false; - listView.setOnItemLongClickListener(null); - if (selectedItem != null) { - new MenuInflater(getActivity()).inflate(R.menu.feeditem, menu); - - menu.setHeaderTitle(selectedItem.getTitle()); - FeedItemMenuHandler.onPrepareMenu( - new FeedItemMenuHandler.MenuInterface() { - - @Override - public void setItemVisibility(int id, boolean visible) { - menu.findItem(id).setVisible(visible); - } - }, selectedItem, false, QueueAccess.ItemListAccess(queue)); - - // check to see if the item is in the queue, if so add queue menu items - int itemIndex = queue.indexOf(selectedItem); - if (itemIndex != -1) { - addQueueOnlyMenus(menu, itemIndex); - } - - } else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_QUEUE) { - menu.add(Menu.NONE, R.id.organize_queue_item, Menu.NONE, - R.string.organize_queue_label); - menu.add(Menu.NONE, R.id.clear_queue_item, Menu.NONE, getActivity() - .getString(R.string.clear_queue_label)); - menu.add(Menu.NONE, R.id.download_all_item, Menu.NONE, - getActivity().getString(R.string.download_all)); - } else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_UNREAD) { - menu.add(Menu.NONE, R.id.mark_all_read_item, Menu.NONE, - getActivity().getString(R.string.mark_all_read_label)); - menu.add(Menu.NONE, R.id.enqueue_all_item, Menu.NONE, getActivity() - .getString(R.string.enqueue_all_new)); - } - } - - /** - * Adds submenus to the ContextMenu if the item selected is in the queue. - * @param menu the ContextMenu to add the submenus to - * @param itemIndex the index of the selected item within the queue. - */ - private void addQueueOnlyMenus(ContextMenu menu, int itemIndex) { - if (itemIndex != 0) { - // don't add move to top if this item is already on the top - menu.add(Menu.NONE, R.id.move_to_top_item, Menu.NONE, getActivity() - .getString(R.string.move_to_top_label)); - } - if (itemIndex != queue.size() - 1) { - // don't add move to bottom if this item is already on the bottom - menu.add(Menu.NONE, R.id.move_to_bottom_item, Menu.NONE, getActivity() - .getString(R.string.move_to_bottom_label)); - } - } - - @Override - public boolean onContextItemSelected(android.view.MenuItem item) { - boolean handled = false; - if (selectedItem != null) { - try { - handled = FeedItemMenuHandler.onMenuItemClicked( - getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DownloadRequestErrorDialogCreator.newRequestErrorDialog( - getActivity(), e.getMessage()); - } - if (!handled) { - // if it wasn't handled by the FeedItemMenuHandler it might be one of ours - switch (item.getItemId()) { - case R.id.move_to_top_item: - DBWriter.moveQueueItemToTop(getActivity(), selectedItem.getId(), true); - handled = true; - break; - case R.id.move_to_bottom_item: - DBWriter.moveQueueItemToBottom(getActivity(), selectedItem.getId(), true); - handled = true; - break; - } - } - } else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_QUEUE) { - handled = true; - switch (item.getItemId()) { - case R.id.organize_queue_item: - startActivity(new Intent(getActivity(), - OrganizeQueueActivity.class)); - break; - case R.id.clear_queue_item: - DBWriter.clearQueue(getActivity()); - break; - case R.id.download_all_item: - DBTasks.downloadAllItemsInQueue(getActivity()); - break; - default: - handled = false; - } - } else if (selectedGroupId == ExternalEpisodesListAdapter.GROUP_POS_UNREAD) { - handled = true; - switch (item.getItemId()) { - case R.id.mark_all_read_item: - DBWriter.markAllItemsRead(getActivity()); - break; - case R.id.enqueue_all_item: - DBTasks.enqueueAllNewItems(getActivity()); - break; - default: - handled = false; - } - } - - resetContextMenuSelection(); - return handled; - } - - private void resetContextMenuSelection() { - selectedItem = null; - selectedGroupId = -1; - contextMenuClosed = true; - } -} diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java deleted file mode 100644 index 0d2f0d079..000000000 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ /dev/null @@ -1,292 +0,0 @@ -package de.danoeh.antennapod.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v7.app.ActionBarActivity; -import android.support.v7.view.ActionMode; -import android.util.Log; -import android.view.*; -import android.widget.*; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.FeedItemlistActivity; -import de.danoeh.antennapod.adapter.FeedlistAdapter; -import de.danoeh.antennapod.asynctask.FeedRemover; -import de.danoeh.antennapod.dialog.ConfirmationDialog; -import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; -import de.danoeh.antennapod.feed.EventDistributor; -import de.danoeh.antennapod.feed.Feed; -import de.danoeh.antennapod.storage.DBReader; -import de.danoeh.antennapod.storage.DownloadRequestException; -import de.danoeh.antennapod.storage.FeedItemStatistics; -import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; - -import java.util.List; - -public class FeedlistFragment extends Fragment implements - ActionMode.Callback, AdapterView.OnItemClickListener, - AdapterView.OnItemLongClickListener { - private static final String TAG = "FeedlistFragment"; - - private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED - | EventDistributor.DOWNLOAD_QUEUED - | EventDistributor.FEED_LIST_UPDATE - | EventDistributor.UNREAD_ITEMS_UPDATE; - - public static final String EXTRA_SELECTED_FEED = "extra.de.danoeh.antennapod.activity.selected_feed"; - - private FeedlistAdapter fla; - private List<Feed> feeds; - private List<FeedItemStatistics> feedItemStatistics; - - private Feed selectedFeed; - private ActionMode mActionMode; - - private GridView gridView; - private ListView listView; - private TextView emptyView; - - private FeedlistAdapter.ItemAccess itemAccess = new FeedlistAdapter.ItemAccess() { - - @Override - public Feed getItem(int position) { - if (feeds != null) { - return feeds.get(position); - } else { - return null; - } - } - - @Override - public FeedItemStatistics getFeedItemStatistics(int position) { - if (feedItemStatistics != null && position < feedItemStatistics.size()) { - return feedItemStatistics.get(position); - } else { - return null; - } - } - - @Override - public int getCount() { - if (feeds != null) { - return feeds.size(); - } else { - return 0; - } - } - }; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (BuildConfig.DEBUG) - Log.d(TAG, "Creating"); - fla = new FeedlistAdapter(getActivity(), itemAccess); - loadFeeds(); - } - - private void loadFeeds() { - AsyncTask<Void, Void, List[]> loadTask = new AsyncTask<Void, Void, List[]>() { - @Override - protected List[] doInBackground(Void... params) { - Context context = getActivity(); - if (context != null) { - return new List[]{DBReader.getFeedList(context), - DBReader.getFeedStatisticsList(context)}; - } else { - return null; - } - } - - - @Override - protected void onPostExecute(List[] result) { - super.onPostExecute(result); - if (result != null) { - feeds = result[0]; - feedItemStatistics = result[1]; - setEmptyViewIfListIsEmpty(); - if (fla != null) { - fla.notifyDataSetChanged(); - } - } else { - Log.e(TAG, "Failed to load feeds"); - } - } - }; - loadTask.execute(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View result = inflater.inflate(R.layout.feedlist, container, false); - listView = (ListView) result.findViewById(android.R.id.list); - gridView = (GridView) result.findViewById(R.id.grid); - emptyView = (TextView) result.findViewById(android.R.id.empty); - - return result; - - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - if (listView != null) { - listView.setOnItemClickListener(this); - listView.setOnItemLongClickListener(this); - listView.setAdapter(fla); - listView.setEmptyView(emptyView); - if (BuildConfig.DEBUG) - Log.d(TAG, "Using ListView"); - } else { - gridView.setOnItemClickListener(this); - gridView.setOnItemLongClickListener(this); - gridView.setAdapter(fla); - gridView.setEmptyView(emptyView); - if (BuildConfig.DEBUG) - Log.d(TAG, "Using GridView"); - } - setEmptyViewIfListIsEmpty(); - } - - @Override - public void onResume() { - super.onResume(); - if (BuildConfig.DEBUG) - Log.d(TAG, "Resuming"); - EventDistributor.getInstance().register(contentUpdate); - } - - @Override - public void onDestroy() { - super.onDestroy(); - EventDistributor.getInstance().unregister(contentUpdate); - } - - @Override - public void onPause() { - super.onPause(); - if (mActionMode != null) { - mActionMode.finish(); - } - } - - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EVENTS & arg) != 0) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Received contentUpdate Intent."); - loadFeeds(); - } - } - }; - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu); - mode.setTitle(selectedFeed.getTitle()); - return true; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed); - } - - @SuppressLint("NewApi") - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - try { - if (FeedMenuHandler.onOptionsItemClicked(getActivity(), - item, selectedFeed)) { - loadFeeds(); - } else { - switch (item.getItemId()) { - case R.id.remove_item: - final FeedRemover remover = new FeedRemover( - getActivity(), selectedFeed) { - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - loadFeeds(); - } - }; - ConfirmationDialog conDialog = new ConfirmationDialog( - getActivity(), R.string.remove_feed_label, - R.string.feed_delete_confirmation_msg) { - - @Override - public void onConfirmButtonPressed( - DialogInterface dialog) { - dialog.dismiss(); - remover.executeAsync(); - } - }; - conDialog.createNewDialog().show(); - break; - } - } - } catch (DownloadRequestException e) { - e.printStackTrace(); - DownloadRequestErrorDialogCreator.newRequestErrorDialog( - getActivity(), e.getMessage()); - } - mode.finish(); - return true; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - mActionMode = null; - selectedFeed = null; - fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE); - } - - @Override - public void onItemClick(AdapterView<?> arg0, View arg1, int position, - long id) { - Feed selection = fla.getItem(position); - Intent showFeed = new Intent(getActivity(), FeedItemlistActivity.class); - showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId()); - - getActivity().startActivity(showFeed); - } - - @Override - public boolean onItemLongClick(AdapterView<?> parent, View view, - int position, long id) { - Feed selection = fla.getItem(position); - if (selection != null) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Selected Feed with title " + selection.getTitle()); - if (mActionMode != null) { - mActionMode.finish(); - } - fla.setSelectedItemIndex(position); - selectedFeed = selection; - mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(FeedlistFragment.this); - - } - return true; - } - - private AbsListView getMainView() { - return (listView != null) ? listView : gridView; - } - - private void setEmptyViewIfListIsEmpty() { - if (getMainView() != null && emptyView != null && feeds != null) { - if (feeds.isEmpty()) { - emptyView.setText(R.string.no_feeds_label); - } - } - } -} diff --git a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java deleted file mode 100644 index 53910b673..000000000 --- a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java +++ /dev/null @@ -1,266 +0,0 @@ -package de.danoeh.antennapod.fragment; - -import android.annotation.SuppressLint; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.ListFragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.AbsListView; -import android.widget.AbsListView.OnScrollListener; -import android.widget.ListView; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MiroGuideChannelViewActivity; -import de.danoeh.antennapod.adapter.MiroGuideChannelListAdapter; -import de.danoeh.antennapod.miroguide.conn.MiroGuideException; -import de.danoeh.antennapod.miroguide.conn.MiroGuideService; -import de.danoeh.antennapod.miroguide.model.MiroGuideChannel; - -import java.util.ArrayList; -import java.util.List; - -/** - * Displays a list of MiroGuideChannel objects that were results of a certain - * MiroGuideService query. If the user reaches the bottom of the list, more - * entries will be loaded until all entries have been loaded or the maximum - * number of channels has been reached. - * */ -public class MiroGuideChannellistFragment extends ListFragment { - private static final String TAG = "MiroGuideChannellistFragment"; - - private static final String ARG_FILTER = "filter"; - private static final String ARG_FILTER_VALUE = "filter_value"; - private static final String ARG_SORT = "sort"; - - private static final int MAX_CHANNELS = 200; - private static final int CHANNELS_PER_QUERY = MiroGuideService.DEFAULT_CHANNEL_LIMIT; - - private ArrayList<MiroGuideChannel> channels; - private MiroGuideChannelListAdapter listAdapter; - private int offset; - - private boolean isLoadingChannels; - /** - * True if there are no more entries to load or if the maximum number of - * channels in the channellist has been reached - */ - private boolean stopLoading; - - private View footer; - - private String filter; - private String filterValue; - private String sort; - - private AsyncTask<Void, Void, List<MiroGuideChannel>> channelLoader; - - /** - * Creates a new instance of Channellist fragment. - * - * @throws IllegalArgumentException - * if filter, filterValue or sort is null - * */ - public static MiroGuideChannellistFragment newInstance(String filter, - String filterValue, String sort) { - if (filter == null) { - throw new IllegalArgumentException("filter cannot be null"); - } - if (filterValue == null) { - throw new IllegalArgumentException("filter value cannot be null"); - } - if (sort == null) { - throw new IllegalArgumentException("sort cannot be null"); - } - MiroGuideChannellistFragment cf = new MiroGuideChannellistFragment(); - Bundle args = new Bundle(); - args.putString(ARG_FILTER, filter); - args.putString(ARG_FILTER_VALUE, filterValue); - args.putString(ARG_SORT, sort); - cf.setArguments(args); - return cf; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - offset = 0; - channels = new ArrayList<MiroGuideChannel>(); - - Bundle args = getArguments(); - filter = args.getString(ARG_FILTER); - filterValue = args.getString(ARG_FILTER_VALUE); - sort = args.getString(ARG_SORT); - - LayoutInflater inflater = (LayoutInflater) getActivity() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - footer = inflater.inflate(R.layout.loading_footer, null); - listAdapter = new MiroGuideChannelListAdapter(getActivity(), 0, - channels); - } - - @Override - public void onResume() { - super.onResume(); - if (channels.isEmpty()) { - setListShown(false); - loadChannels(); - } - } - - @Override - public void onPause() { - super.onPause(); - if (channelLoader != null) { - channelLoader.cancel(true); - } - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - getListView().addFooterView(footer); // footer has to be added before - // the adapter has been set - getListView().setAdapter(listAdapter); - getListView().removeFooterView(footer); - - getListView().setOnScrollListener(new OnScrollListener() { - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, - int visibleItemCount, int totalItemCount) { - int lastVisibleItem = firstVisibleItem + visibleItemCount; - if (lastVisibleItem == totalItemCount) { - if (BuildConfig.DEBUG) - loadChannels(); - } - } - - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - } - }); - } - - @Override - public void onListItemClick(ListView l, View v, int position, long id) { - super.onListItemClick(l, v, position, id); - if (listAdapter != null) { - MiroGuideChannel selection = listAdapter.getItem(position); - Intent launchIntent = new Intent(getActivity(), - MiroGuideChannelViewActivity.class); - launchIntent.putExtra( - MiroGuideChannelViewActivity.EXTRA_CHANNEL_ID, - selection.getId()); - launchIntent.putExtra( - MiroGuideChannelViewActivity.EXTRA_CHANNEL_URL, - selection.getDownloadUrl()); - startActivity(launchIntent); - } - } - - @SuppressLint("NewApi") - private void loadChannels() { - if (!isLoadingChannels) { - if (!stopLoading) { - isLoadingChannels = true; - channelLoader = new AsyncTask<Void, Void, List<MiroGuideChannel>>() { - private MiroGuideException exception; - - @Override - protected void onCancelled() { - if (BuildConfig.DEBUG) - Log.d(TAG, "Channel loader was cancelled"); - } - - @Override - protected void onPostExecute(List<MiroGuideChannel> result) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Channel loading finished"); - if (exception == null) { - getListView().removeFooterView(footer); - for (MiroGuideChannel channel : result) { - channels.add(channel); - } - listAdapter.notifyDataSetChanged(); - offset += CHANNELS_PER_QUERY; - // check if fragment should not send any more - // queries - if (result.size() < CHANNELS_PER_QUERY) { - if (BuildConfig.DEBUG) - Log.d(TAG, - "Query result was less than requested number of channels. Stopping to send any more queries"); - stopLoading = true; - } - if (offset >= MAX_CHANNELS) { - if (BuildConfig.DEBUG) - Log.d(TAG, - "Maximum number of feeds has been reached. Stopping to send any more queries"); - stopLoading = true; - } - - setListShown(true); - } else { - AlertDialog.Builder dialog = new AlertDialog.Builder( - getActivity()); - dialog.setTitle(R.string.error_label); - dialog.setMessage(exception.getMessage()); - dialog.setNeutralButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - - @Override - public void onClick( - DialogInterface dialog, - int which) { - dialog.dismiss(); - } - }); - dialog.create().show(); - } - isLoadingChannels = false; - } - - @Override - protected void onPreExecute() { - getListView().addFooterView(footer); - } - - @Override - protected List<MiroGuideChannel> doInBackground( - Void... params) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Background channel loader started"); - MiroGuideService service = new MiroGuideService(); - try { - return service.getChannelList(filter, filterValue, - sort, CHANNELS_PER_QUERY, offset); - } catch (MiroGuideException e) { - exception = e; - e.printStackTrace(); - } finally { - // service.close(); - } - return null; - } - }; - - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - channelLoader - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - channelLoader.execute(); - } - } - } else { - if (BuildConfig.DEBUG) - Log.d(TAG, "Channels are already being loaded"); - } - } -} |