Add ability to clear the download log, as requested in AntennaPod/AntennaPod#506
This commit is contained in:
parent
30a202665a
commit
8f9c9c8d3b
|
@ -1,25 +1,35 @@
|
|||
package de.danoeh.antennapod.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.adapter.DownloadLogAdapter;
|
||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
|
||||
import java.util.List;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
|
||||
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
||||
|
||||
/**
|
||||
* Shows the download log
|
||||
*/
|
||||
public class DownloadLogFragment extends ListFragment {
|
||||
|
||||
private static final String TAG = "DownloadLogFragment";
|
||||
|
||||
private List<DownloadStatus> downloadLog;
|
||||
private DownloadLogAdapter adapter;
|
||||
|
||||
|
@ -29,6 +39,7 @@ public class DownloadLogFragment extends ListFragment {
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
setHasOptionsMenu(true);
|
||||
EventDistributor.getInstance().register(contentUpdate);
|
||||
startItemLoader();
|
||||
}
|
||||
|
@ -63,7 +74,7 @@ public class DownloadLogFragment extends ListFragment {
|
|||
}
|
||||
setListShown(true);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() {
|
||||
|
@ -105,6 +116,41 @@ public class DownloadLogFragment extends ListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) {
|
||||
MenuItem clearHistory = menu.add(Menu.NONE, R.id.clear_history_item, Menu.CATEGORY_CONTAINER, R.string.clear_history_label);
|
||||
MenuItemCompat.setShowAsAction(clearHistory, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
TypedArray drawables = getActivity().obtainStyledAttributes(new int[]{R.attr.content_discard});
|
||||
clearHistory.setIcon(drawables.getDrawable(0));
|
||||
drawables.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) {
|
||||
menu.findItem(R.id.clear_history_item).setVisible(downloadLog != null && !downloadLog.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (!super.onOptionsItemSelected(item)) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.clear_history_item:
|
||||
DBWriter.clearDownloadLog(getActivity());
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class ItemLoader extends AsyncTask<Void, Void, List<DownloadStatus>> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -238,6 +238,26 @@ public class DBWriter {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the entire download log.
|
||||
*
|
||||
* @param context A context that is used for opening a database connection.
|
||||
*/
|
||||
public static Future<?> clearDownloadLog(final Context context) {
|
||||
return dbExec.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
adapter.clearDownloadLog();
|
||||
adapter.close();
|
||||
EventDistributor.getInstance()
|
||||
.sendDownloadLogUpdateBroadcast();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a FeedMedia object to the playback history. A FeedMedia object is in the playback history if
|
||||
* its playback completion date is set to a non-null value. This method will set the playback completion date to the
|
||||
|
|
|
@ -889,6 +889,10 @@ public class PodDBAdapter {
|
|||
db.update(TABLE_NAME_FEED_MEDIA, values, null, null);
|
||||
}
|
||||
|
||||
public void clearDownloadLog() {
|
||||
db.delete(TABLE_NAME_DOWNLOAD_LOG, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Feeds from the Feed Table.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue