Fixed Download screen problems and download report notification
This commit is contained in:
parent
cb9741b417
commit
d0ff899990
@ -15,7 +15,7 @@
|
||||
android:id="@+id/imgvImage"
|
||||
android:contentDescription="@string/cover_label"
|
||||
android:layout_width="@dimen/thumbnail_length_downloaded_item"
|
||||
android:layout_height="@dimen/thumbnail_length_itemlist"
|
||||
android:layout_height="@dimen/thumbnail_length_downloaded_item"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
public FeedItem getItem(int position) {
|
||||
return itemAccess.getItem(position);
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ import de.danoeh.antennapod.util.QueueAccess;
|
||||
import de.danoeh.antennapod.util.ShownotesProvider;
|
||||
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.shredzone.flattr4j.model.User;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
@ -193,7 +193,6 @@ public class FeedItemDialog extends Dialog {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private final FeedItemMenuHandler.MenuInterface popupMenuInterface = new FeedItemMenuHandler.MenuInterface() {
|
||||
@Override
|
||||
public void setItemVisibility(int id, boolean visible) {
|
||||
@ -306,18 +305,49 @@ public class FeedItemDialog extends Dialog {
|
||||
loadTask.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that calls setQueue() and setItemFromCollection() with
|
||||
* the given arguments.
|
||||
*
|
||||
* @return true if one of the calls to setItemFromCollection returned true,
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean updateContent(QueueAccess queue, List<FeedItem>... collections) {
|
||||
setQueue(queue);
|
||||
|
||||
boolean setItemFromCollectionResult = false;
|
||||
if (collections != null) {
|
||||
for (List<FeedItem> list : collections) {
|
||||
setItemFromCollectionResult |= setItemFromCollection(list);
|
||||
}
|
||||
}
|
||||
if (isShowing()) {
|
||||
updateMenuAppearance();
|
||||
}
|
||||
|
||||
return setItemFromCollectionResult;
|
||||
}
|
||||
|
||||
|
||||
public void setItem(FeedItem item) {
|
||||
if (item == null) throw new IllegalArgumentException("item = null");
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void setItemFromCollection(Collection<FeedItem> items) {
|
||||
/**
|
||||
* Finds the FeedItem of this dialog in a collection and updates its state from that
|
||||
* collection.
|
||||
*
|
||||
* @return true if the FeedItem was found, false otherwise.
|
||||
*/
|
||||
public boolean setItemFromCollection(Collection<FeedItem> items) {
|
||||
for (FeedItem item : items) {
|
||||
if (item.getId() == this.item.getId()) {
|
||||
setItem(item);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setQueue(QueueAccess queue) {
|
||||
|
@ -6,11 +6,14 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter;
|
||||
import de.danoeh.antennapod.dialog.FeedItemDialog;
|
||||
import de.danoeh.antennapod.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.storage.DBReader;
|
||||
import de.danoeh.antennapod.storage.DBWriter;
|
||||
import de.danoeh.antennapod.util.QueueAccess;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -18,17 +21,21 @@ import java.util.List;
|
||||
* Displays all running downloads and provides a button to delete them
|
||||
*/
|
||||
public class CompletedDownloadsFragment extends ListFragment {
|
||||
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED |
|
||||
private static final int EVENTS =
|
||||
EventDistributor.DOWNLOAD_HANDLED |
|
||||
EventDistributor.DOWNLOADLOG_UPDATE |
|
||||
EventDistributor.QUEUE_UPDATE |
|
||||
EventDistributor.UNREAD_ITEMS_UPDATE;
|
||||
|
||||
private List<FeedItem> items;
|
||||
private QueueAccess queue;
|
||||
private DownloadedEpisodesListAdapter listAdapter;
|
||||
|
||||
private boolean viewCreated = false;
|
||||
private boolean itemsLoaded = false;
|
||||
|
||||
private FeedItemDialog feedItemDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -60,6 +67,7 @@ public class CompletedDownloadsFragment extends ListFragment {
|
||||
super.onDestroyView();
|
||||
listAdapter = null;
|
||||
viewCreated = false;
|
||||
feedItemDialog = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,12 +87,29 @@ public class CompletedDownloadsFragment extends ListFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
FeedItem item = listAdapter.getItem(position - l.getHeaderViewsCount());
|
||||
if (item != null) {
|
||||
feedItemDialog = FeedItemDialog.newInstace(getActivity(), item, queue);
|
||||
feedItemDialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onFragmentLoaded() {
|
||||
if (listAdapter == null) {
|
||||
listAdapter = new DownloadedEpisodesListAdapter(getActivity(), itemAccess);
|
||||
setListAdapter(listAdapter);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
if (feedItemDialog != null) {
|
||||
boolean res = feedItemDialog.updateContent(queue, items);
|
||||
if (!res && feedItemDialog.isShowing()) {
|
||||
feedItemDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadedEpisodesListAdapter.ItemAccess itemAccess = new DownloadedEpisodesListAdapter.ItemAccess() {
|
||||
@ -107,7 +132,11 @@ public class CompletedDownloadsFragment extends ListFragment {
|
||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||
@Override
|
||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||
if ((arg & EVENTS) != 0) {
|
||||
if ((arg & EventDistributor.DOWNLOAD_QUEUED) != 0) {
|
||||
if (feedItemDialog != null && feedItemDialog.isShowing()) {
|
||||
feedItemDialog.updateMenuAppearance();
|
||||
}
|
||||
} else if ((arg & EVENTS) != 0) {
|
||||
startItemLoader();
|
||||
}
|
||||
}
|
||||
@ -129,7 +158,7 @@ public class CompletedDownloadsFragment extends ListFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private class ItemLoader extends AsyncTask<Void, Void, List<FeedItem>> {
|
||||
private class ItemLoader extends AsyncTask<Void, Void, Object[]> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
@ -140,11 +169,12 @@ public class CompletedDownloadsFragment extends ListFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<FeedItem> feedItems) {
|
||||
super.onPostExecute(feedItems);
|
||||
protected void onPostExecute(Object[] results) {
|
||||
super.onPostExecute(results);
|
||||
setListShown(true);
|
||||
if (feedItems != null) {
|
||||
items = feedItems;
|
||||
if (results != null) {
|
||||
items = (List<FeedItem>) results[0];
|
||||
queue = (QueueAccess) results[1];
|
||||
itemsLoaded = true;
|
||||
if (viewCreated && getActivity() != null) {
|
||||
onFragmentLoaded();
|
||||
@ -153,10 +183,11 @@ public class CompletedDownloadsFragment extends ListFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FeedItem> doInBackground(Void... params) {
|
||||
protected Object[] doInBackground(Void... params) {
|
||||
Context context = getActivity();
|
||||
if (context != null) {
|
||||
return DBReader.getDownloadedItems(context);
|
||||
return new Object[] {DBReader.getDownloadedItems(context),
|
||||
QueueAccess.IDListAccess(DBReader.getQueueIDList(context))};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -283,10 +283,8 @@ public class ItemlistFragment extends ListFragment {
|
||||
setListShown(true);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
if (feedItemDialog != null && feedItemDialog.isShowing()) {
|
||||
feedItemDialog.setItemFromCollection(feed.getItems());
|
||||
feedItemDialog.setQueue(queue);
|
||||
feedItemDialog.updateMenuAppearance();
|
||||
if (feedItemDialog != null) {
|
||||
feedItemDialog.updateContent(queue, feed.getItems());
|
||||
}
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
@ -219,11 +219,8 @@ public class NewEpisodesFragment extends Fragment {
|
||||
downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback);
|
||||
downloadObserver.onResume();
|
||||
}
|
||||
if (feedItemDialog != null && feedItemDialog.isShowing()) {
|
||||
feedItemDialog.setQueue(queueAccess);
|
||||
feedItemDialog.setItemFromCollection(unreadItems);
|
||||
feedItemDialog.setItemFromCollection(recentItems);
|
||||
feedItemDialog.updateMenuAppearance();
|
||||
if (feedItemDialog != null) {
|
||||
feedItemDialog.updateContent(queueAccess, unreadItems, recentItems);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
|
@ -175,9 +175,7 @@ public class PlaybackHistoryFragment extends ListFragment {
|
||||
setListShown(true);
|
||||
adapter.notifyDataSetChanged();
|
||||
if (feedItemDialog != null && feedItemDialog.isShowing()) {
|
||||
feedItemDialog.setItemFromCollection(playbackHistory);
|
||||
feedItemDialog.setQueue(queue);
|
||||
feedItemDialog.updateMenuAppearance();
|
||||
feedItemDialog.updateContent(queue, playbackHistory);
|
||||
}
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
@ -234,10 +234,8 @@ public class QueueFragment extends Fragment {
|
||||
downloadObserver.onResume();
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
if (feedItemDialog != null && feedItemDialog.isShowing()) {
|
||||
feedItemDialog.setQueue(QueueAccess.ItemListAccess(queue));
|
||||
feedItemDialog.setItemFromCollection(queue);
|
||||
feedItemDialog.updateMenuAppearance();
|
||||
if (feedItemDialog != null) {
|
||||
feedItemDialog.updateContent(QueueAccess.ItemListAccess(queue), queue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ public class DownloadService extends Service {
|
||||
if (notificationCompatBuilder != null) {
|
||||
notificationCompatBuilder.setContentTitle(contentTitle);
|
||||
notificationCompatBuilder.setContentText(downloadsLeft);
|
||||
return notificationCompatBuilder.getNotification();
|
||||
return notificationCompatBuilder.build();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -525,9 +525,9 @@ public class DownloadService extends Service {
|
||||
R.drawable.stat_notify_sync)
|
||||
)
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(this, 0, intent, 0)
|
||||
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
)
|
||||
.setAutoCancel(true).getNotification();
|
||||
.setAutoCancel(true).build();
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(REPORT_ID, notification);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user