From 71a47c0a5bf99a734081d217eb3e14d75f017a7a Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 1 Jun 2013 18:29:04 +0200 Subject: Ported several classes from FeedManager to DB*-classes --- .../antennapod/fragment/FeedlistFragment.java | 72 ++++++++++++++++------ 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'src/de/danoeh/antennapod/fragment/FeedlistFragment.java') diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index c3034c2af..80deee47e 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -1,9 +1,11 @@ package de.danoeh.antennapod.fragment; +import java.util.List; + import android.annotation.SuppressLint; -import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; +import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -28,7 +30,7 @@ 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.feed.FeedManager; +import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler; @@ -41,11 +43,11 @@ public class FeedlistFragment extends SherlockFragment implements | 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 FeedManager manager; private FeedlistAdapter fla; + private List feeds; private Feed selectedFeed; private ActionMode mActionMode; @@ -54,24 +56,57 @@ public class FeedlistFragment extends SherlockFragment implements private ListView listView; private TextView txtvEmpty; - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - } + private FeedlistAdapter.ItemAccess itemAccess = new FeedlistAdapter.ItemAccess() { - @Override - public void onDetach() { - super.onDetach(); - } + @Override + public Feed getItem(int position) { + if (feeds != null) { + return feeds.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 (AppConfig.DEBUG) Log.d(TAG, "Creating"); - manager = FeedManager.getInstance(); - fla = new FeedlistAdapter(getActivity()); + fla = new FeedlistAdapter(getActivity(), itemAccess); + loadFeeds(); + } + private void loadFeeds() { + AsyncTask> loadTask = new AsyncTask>() { + @Override + protected List doInBackground(Void... params) { + return DBReader.getFeedList(getActivity()); + } + + @Override + protected void onPostExecute(List result) { + super.onPostExecute(result); + if (result != null) { + feeds = result; + if (fla != null) { + fla.notifyDataSetChanged(); + } + } else { + Log.e(TAG, "Failed to load feeds"); + } + } + }; + loadTask.execute(); } @Override @@ -112,7 +147,6 @@ public class FeedlistFragment extends SherlockFragment implements if (AppConfig.DEBUG) Log.d(TAG, "Resuming"); EventDistributor.getInstance().register(contentUpdate); - fla.notifyDataSetChanged(); } @Override @@ -125,13 +159,13 @@ public class FeedlistFragment extends SherlockFragment implements } private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - + @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((EVENTS & arg) != 0) { if (AppConfig.DEBUG) Log.d(TAG, "Received contentUpdate Intent."); - fla.notifyDataSetChanged(); + loadFeeds(); } } }; @@ -154,7 +188,7 @@ public class FeedlistFragment extends SherlockFragment implements try { if (FeedMenuHandler.onOptionsItemClicked(getSherlockActivity(), item, selectedFeed)) { - fla.notifyDataSetChanged(); + loadFeeds(); } else { switch (item.getItemId()) { case R.id.remove_item: @@ -163,7 +197,7 @@ public class FeedlistFragment extends SherlockFragment implements @Override protected void onPostExecute(Void result) { super.onPostExecute(result); - fla.notifyDataSetChanged(); + loadFeeds(); } }; ConfirmationDialog conDialog = new ConfirmationDialog( -- cgit v1.2.3 From 6d1a8535f5dbf9bcdd552ad382f2944f7b0d31ad Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 5 Aug 2013 01:27:38 +0200 Subject: Added FeedItemStatistics. Makes it possible to get number of (new, in progress) episodes of a feed without loading the whole list of items --- .../antennapod/fragment/FeedlistFragment.java | 461 +++++++++++---------- 1 file changed, 237 insertions(+), 224 deletions(-) (limited to 'src/de/danoeh/antennapod/fragment/FeedlistFragment.java') diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index 80deee47e..ef9994649 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -32,231 +32,244 @@ 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; public class FeedlistFragment extends SherlockFragment 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 feeds; - - private Feed selectedFeed; - private ActionMode mActionMode; - - private GridView gridView; - private ListView listView; - private TextView txtvEmpty; - - 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 int getCount() { - if (feeds != null) { - return feeds.size(); - } else { - return 0; - } - } - }; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (AppConfig.DEBUG) - Log.d(TAG, "Creating"); - fla = new FeedlistAdapter(getActivity(), itemAccess); - loadFeeds(); - } - - private void loadFeeds() { - AsyncTask> loadTask = new AsyncTask>() { - @Override - protected List doInBackground(Void... params) { - return DBReader.getFeedList(getActivity()); - } - - @Override - protected void onPostExecute(List result) { - super.onPostExecute(result); - if (result != null) { - feeds = result; - 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); - txtvEmpty = (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(txtvEmpty); - if (AppConfig.DEBUG) - Log.d(TAG, "Using ListView"); - } else { - gridView.setOnItemClickListener(this); - gridView.setOnItemLongClickListener(this); - gridView.setAdapter(fla); - gridView.setEmptyView(txtvEmpty); - if (AppConfig.DEBUG) - Log.d(TAG, "Using GridView"); - } - } - - @Override - public void onResume() { - super.onResume(); - if (AppConfig.DEBUG) - Log.d(TAG, "Resuming"); - EventDistributor.getInstance().register(contentUpdate); - } - - @Override - public void onPause() { - super.onPause(); - EventDistributor.getInstance().unregister(contentUpdate); - 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 (AppConfig.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(getSherlockActivity(), - item, selectedFeed)) { - loadFeeds(); - } else { - switch (item.getItemId()) { - case R.id.remove_item: - final FeedRemover remover = new FeedRemover( - getSherlockActivity(), 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 (AppConfig.DEBUG) - Log.d(TAG, "Selected Feed with title " + selection.getTitle()); - if (selection != null) { - if (mActionMode != null) { - mActionMode.finish(); - } - fla.setSelectedItemIndex(position); - selectedFeed = selection; - mActionMode = getSherlockActivity().startActionMode( - FeedlistFragment.this); - - } - return true; - } + 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 feeds; + private List feedItemStatistics; + + private Feed selectedFeed; + private ActionMode mActionMode; + + private GridView gridView; + private ListView listView; + private TextView txtvEmpty; + + 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 (AppConfig.DEBUG) + Log.d(TAG, "Creating"); + fla = new FeedlistAdapter(getActivity(), itemAccess); + loadFeeds(); + } + + private void loadFeeds() { + AsyncTask loadTask = new AsyncTask() { + @Override + protected List[] doInBackground(Void... params) { + return new List[]{DBReader.getFeedList(getActivity()), + DBReader.getFeedStatisticsList(getActivity())}; + } + + @Override + protected void onPostExecute(List[] result) { + super.onPostExecute(result); + if (result != null) { + feeds = result[0]; + feedItemStatistics = result[1]; + 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); + txtvEmpty = (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(txtvEmpty); + if (AppConfig.DEBUG) + Log.d(TAG, "Using ListView"); + } else { + gridView.setOnItemClickListener(this); + gridView.setOnItemLongClickListener(this); + gridView.setAdapter(fla); + gridView.setEmptyView(txtvEmpty); + if (AppConfig.DEBUG) + Log.d(TAG, "Using GridView"); + } + } + + @Override + public void onResume() { + super.onResume(); + if (AppConfig.DEBUG) + Log.d(TAG, "Resuming"); + EventDistributor.getInstance().register(contentUpdate); + } + + @Override + public void onPause() { + super.onPause(); + EventDistributor.getInstance().unregister(contentUpdate); + 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 (AppConfig.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(getSherlockActivity(), + item, selectedFeed)) { + loadFeeds(); + } else { + switch (item.getItemId()) { + case R.id.remove_item: + final FeedRemover remover = new FeedRemover( + getSherlockActivity(), 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 (AppConfig.DEBUG) + Log.d(TAG, "Selected Feed with title " + selection.getTitle()); + if (selection != null) { + if (mActionMode != null) { + mActionMode.finish(); + } + fla.setSelectedItemIndex(position); + selectedFeed = selection; + mActionMode = getSherlockActivity().startActionMode( + FeedlistFragment.this); + + } + return true; + } } -- cgit v1.2.3 From 3f5e2faff941f220c7a882bfba4f86e85219d7ba Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 5 Aug 2013 10:45:17 +0200 Subject: Do not display empty listview message while loading --- .../antennapod/fragment/FeedlistFragment.java | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/de/danoeh/antennapod/fragment/FeedlistFragment.java') diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index ef9994649..95fdc92da 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment; import java.util.List; import android.annotation.SuppressLint; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; @@ -11,10 +12,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.GridView; -import android.widget.ListView; -import android.widget.TextView; +import android.widget.*; import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.ActionMode; @@ -56,7 +54,7 @@ public class FeedlistFragment extends SherlockFragment implements private GridView gridView; private ListView listView; - private TextView txtvEmpty; + private TextView emptyView; private FeedlistAdapter.ItemAccess itemAccess = new FeedlistAdapter.ItemAccess() { @@ -105,12 +103,15 @@ public class FeedlistFragment extends SherlockFragment implements DBReader.getFeedStatisticsList(getActivity())}; } + + @Override protected void onPostExecute(List[] result) { super.onPostExecute(result); if (result != null) { feeds = result[0]; feedItemStatistics = result[1]; + setEmptyViewIfListIsEmpty(); if (fla != null) { fla.notifyDataSetChanged(); } @@ -128,7 +129,7 @@ public class FeedlistFragment extends SherlockFragment implements View result = inflater.inflate(R.layout.feedlist, container, false); listView = (ListView) result.findViewById(android.R.id.list); gridView = (GridView) result.findViewById(R.id.grid); - txtvEmpty = (TextView) result.findViewById(android.R.id.empty); + emptyView = (TextView) result.findViewById(android.R.id.empty); return result; @@ -141,17 +142,18 @@ public class FeedlistFragment extends SherlockFragment implements listView.setOnItemClickListener(this); listView.setOnItemLongClickListener(this); listView.setAdapter(fla); - listView.setEmptyView(txtvEmpty); + listView.setEmptyView(emptyView); if (AppConfig.DEBUG) Log.d(TAG, "Using ListView"); } else { gridView.setOnItemClickListener(this); gridView.setOnItemLongClickListener(this); gridView.setAdapter(fla); - gridView.setEmptyView(txtvEmpty); + gridView.setEmptyView(emptyView); if (AppConfig.DEBUG) Log.d(TAG, "Using GridView"); } + setEmptyViewIfListIsEmpty(); } @Override @@ -272,4 +274,16 @@ public class FeedlistFragment extends SherlockFragment implements } 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); + } + } + } } -- cgit v1.2.3