summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/fragment
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2014-04-18 17:46:13 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2014-04-18 17:46:13 +0200
commit9a86c6651a2335f3385777c99a3943ac52d555f0 (patch)
tree8d9b206f0b3029c1e98703a5e4f3d85576e0b519 /src/de/danoeh/antennapod/fragment
parenta03b076a32bc8df94345daa5a00a5ad4e3b35a13 (diff)
downloadAntennaPod-9a86c6651a2335f3385777c99a3943ac52d555f0.zip
Added action button functionality
Diffstat (limited to 'src/de/danoeh/antennapod/fragment')
-rw-r--r--src/de/danoeh/antennapod/fragment/ItemlistFragment.java55
-rw-r--r--src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java9
-rw-r--r--src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java57
-rw-r--r--src/de/danoeh/antennapod/fragment/QueueFragment.java8
4 files changed, 99 insertions, 30 deletions
diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java
index 8072d219b..dce64aa5e 100644
--- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java
+++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java
@@ -6,30 +6,34 @@ import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBarActivity;
import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.ItemviewActivity;
-import de.danoeh.antennapod.adapter.ActionButtonCallback;
+import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter;
+import de.danoeh.antennapod.asynctask.DownloadObserver;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem;
+import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.service.download.DownloadService;
+import de.danoeh.antennapod.service.download.Downloader;
import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.QueueAccess;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -58,6 +62,9 @@ public class ItemlistFragment extends ListFragment {
private AtomicReference<Activity> activity = new AtomicReference<Activity>();
+ private DownloadObserver downloadObserver;
+ private List<Downloader> downloaderList;
+
/**
* Creates new ItemlistFragment which shows the Feeditems of a specific
@@ -112,12 +119,19 @@ public class ItemlistFragment extends ListFragment {
adapter = null;
viewsCreated = false;
activity.set(null);
+ if (downloadObserver != null) {
+ downloadObserver.onPause();
+ }
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity.set(activity);
+ if (downloadObserver != null) {
+ downloadObserver.setActivity(activity);
+ downloadObserver.onResume();
+ }
if (viewsCreated && itemsLoaded) {
onFragmentLoaded();
}
@@ -176,15 +190,35 @@ public class ItemlistFragment extends ListFragment {
private void onFragmentLoaded() {
if (adapter == null) {
+ getListView().setAdapter(null);
setupHeaderView();
- adapter = new InternalFeedItemlistAdapter(getActivity(), itemAccess, actionButtonCallback, false);
+ adapter = new InternalFeedItemlistAdapter(getActivity(), itemAccess, new DefaultActionButtonCallback(activity.get()), false);
setListAdapter(adapter);
+ downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback);
+ downloadObserver.onResume();
}
setListShown(true);
adapter.notifyDataSetChanged();
}
+ private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() {
+ @Override
+ public void onContentChanged() {
+ if (adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public void onDownloadDataAvailable(List<Downloader> downloaderList) {
+ ItemlistFragment.this.downloaderList = downloaderList;
+ if (adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
+ }
+ };
+
private void setupHeaderView() {
if (getListView() == null || feed == null) {
Log.e(TAG, "Unable to setup listview: listView = null or feed = null");
@@ -224,16 +258,21 @@ public class ItemlistFragment extends ListFragment {
public boolean isInQueue(FeedItem item) {
return (queue != null) && queue.contains(item.getId());
}
- };
- private ActionButtonCallback actionButtonCallback = new ActionButtonCallback() {
@Override
- public void onActionButtonPressed(FeedItem item) {
-
+ public int getItemDownloadProgressPercent(FeedItem item) {
+ if (downloaderList != null) {
+ for (Downloader downloader : downloaderList) {
+ if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
+ && downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
+ return downloader.getDownloadRequest().getProgressPercent();
+ }
+ }
+ }
+ return 0;
}
};
-
private ItemLoader itemLoader;
private void startItemLoader() {
diff --git a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java
index cb5632d05..3377dc565 100644
--- a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java
+++ b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java
@@ -6,7 +6,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -15,6 +14,7 @@ import android.widget.TextView;
import com.mobeta.android.dslv.DragSortListView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
+import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
import de.danoeh.antennapod.adapter.NewEpisodesListAdapter;
import de.danoeh.antennapod.asynctask.DownloadObserver;
import de.danoeh.antennapod.feed.EventDistributor;
@@ -127,7 +127,7 @@ public class NewEpisodesFragment extends Fragment {
private void onFragmentLoaded() {
if (listAdapter == null) {
- listAdapter = new NewEpisodesListAdapter(activity.get(), itemAccess);
+ listAdapter = new NewEpisodesListAdapter(activity.get(), itemAccess, new DefaultActionButtonCallback(activity.get()));
listView.setAdapter(listAdapter);
listView.setEmptyView(txtvEmpty);
downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback);
@@ -198,11 +198,6 @@ public class NewEpisodesFragment extends Fragment {
}
}
- @Override
- public void onFeedItemSecondaryAction(FeedItem item) {
- Log.i(TAG, item.getTitle());
- }
-
};
diff --git a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java
index 1e4140b7b..a8627f12e 100644
--- a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java
+++ b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java
@@ -4,12 +4,17 @@ import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v4.app.ListFragment;
import android.view.View;
import de.danoeh.antennapod.adapter.ActionButtonCallback;
+import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter;
+import de.danoeh.antennapod.asynctask.DownloadObserver;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.FeedItem;
+import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.service.download.Downloader;
import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.util.QueueAccess;
@@ -28,6 +33,9 @@ public class PlaybackHistoryFragment extends ListFragment {
private AtomicReference<Activity> activity = new AtomicReference<Activity>();
+ private DownloadObserver downloadObserver;
+ private List<Downloader> downloaderList;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -56,12 +64,19 @@ public class PlaybackHistoryFragment extends ListFragment {
adapter = null;
viewsCreated = false;
activity.set(null);
+ if (downloadObserver != null) {
+ downloadObserver.onPause();
+ }
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity.set(activity);
+ if (downloadObserver != null) {
+ downloadObserver.setActivity(activity);
+ downloadObserver.onResume();
+ }
if (viewsCreated && itemsLoaded) {
onFragmentLoaded();
}
@@ -88,14 +103,32 @@ public class PlaybackHistoryFragment extends ListFragment {
private void onFragmentLoaded() {
if (adapter == null) {
- adapter = new InternalFeedItemlistAdapter(getActivity(), itemAccess, actionButtonCallback, true);
+ adapter = new InternalFeedItemlistAdapter(getActivity(), itemAccess, new DefaultActionButtonCallback(activity.get()), true);
setListAdapter(adapter);
+ downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback);
+ downloadObserver.onResume();
}
setListShown(true);
adapter.notifyDataSetChanged();
-
}
+ private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() {
+ @Override
+ public void onContentChanged() {
+ if (adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public void onDownloadDataAvailable(List<Downloader> downloaderList) {
+ PlaybackHistoryFragment.this.downloaderList = downloaderList;
+ if (adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
+ }
+ };
+
private InternalFeedItemlistAdapter.ItemAccess itemAccess = new InternalFeedItemlistAdapter.ItemAccess() {
@Override
public boolean isInQueue(FeedItem item) {
@@ -103,6 +136,19 @@ public class PlaybackHistoryFragment extends ListFragment {
}
@Override
+ public int getItemDownloadProgressPercent(FeedItem item) {
+ if (downloaderList != null) {
+ for (Downloader downloader : downloaderList) {
+ if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
+ && downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
+ return downloader.getDownloadRequest().getProgressPercent();
+ }
+ }
+ }
+ return 0;
+ }
+
+ @Override
public int getCount() {
return (playbackHistory != null) ? playbackHistory.size() : 0;
}
@@ -113,13 +159,6 @@ public class PlaybackHistoryFragment extends ListFragment {
}
};
- private ActionButtonCallback actionButtonCallback = new ActionButtonCallback() {
- @Override
- public void onActionButtonPressed(FeedItem item) {
-
- }
- };
-
private ItemLoader itemLoader;
private void startItemLoader() {
diff --git a/src/de/danoeh/antennapod/fragment/QueueFragment.java b/src/de/danoeh/antennapod/fragment/QueueFragment.java
index 73764df36..e88c7e178 100644
--- a/src/de/danoeh/antennapod/fragment/QueueFragment.java
+++ b/src/de/danoeh/antennapod/fragment/QueueFragment.java
@@ -16,6 +16,7 @@ import android.widget.TextView;
import com.mobeta.android.dslv.DragSortListView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
+import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
import de.danoeh.antennapod.adapter.QueueListAdapter;
import de.danoeh.antennapod.asynctask.DownloadObserver;
import de.danoeh.antennapod.feed.EventDistributor;
@@ -185,7 +186,7 @@ public class QueueFragment extends Fragment {
private void onFragmentLoaded() {
if (listAdapter == null) {
- listAdapter = new QueueListAdapter(activity.get(), itemAccess);
+ listAdapter = new QueueListAdapter(activity.get(), itemAccess, new DefaultActionButtonCallback(activity.get()));
listView.setAdapter(listAdapter);
downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback);
downloadObserver.onResume();
@@ -233,11 +234,6 @@ public class QueueFragment extends Fragment {
}
return 0;
}
-
- @Override
- public void onFeedItemSecondaryAction(FeedItem item) {
-
- }
};
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {