mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-02-02 11:46:55 +01:00
QueueEvents, Queue shows undobar on removal of an item
This commit is contained in:
parent
b2a50983ef
commit
8850c09920
@ -17,6 +17,7 @@ dependencies {
|
|||||||
compile 'com.squareup.okhttp:okhttp:2.2.0'
|
compile 'com.squareup.okhttp:okhttp:2.2.0'
|
||||||
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
|
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
|
||||||
compile 'com.squareup.okio:okio:1.2.0'
|
compile 'com.squareup.okio:okio:1.2.0'
|
||||||
|
compile 'de.greenrobot:eventbus:2.4.0'
|
||||||
compile project(':core')
|
compile project(':core')
|
||||||
compile project(':library:drag-sort-listview')
|
compile project(':library:drag-sort-listview')
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class PlaybackServiceTaskManagerTest extends InstrumentationTestCase {
|
|||||||
};
|
};
|
||||||
EventDistributor.getInstance().register(queueListener);
|
EventDistributor.getInstance().register(queueListener);
|
||||||
List<FeedItem> queue = writeTestQueue("a");
|
List<FeedItem> queue = writeTestQueue("a");
|
||||||
EventDistributor.getInstance().sendQueueUpdateBroadcast();
|
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED_ITEMS, queue));
|
||||||
countDownLatch.await(5000, TimeUnit.MILLISECONDS);
|
countDownLatch.await(5000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
assertNotNull(queue);
|
assertNotNull(queue);
|
||||||
|
@ -204,6 +204,6 @@ public class UITestUtils {
|
|||||||
adapter.setQueue(queue);
|
adapter.setQueue(queue);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
||||||
EventDistributor.getInstance().sendQueueUpdateBroadcast();
|
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED_ITEMS, queue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||||||
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED
|
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED
|
||||||
| EventDistributor.DOWNLOAD_QUEUED
|
| EventDistributor.DOWNLOAD_QUEUED
|
||||||
| EventDistributor.FEED_LIST_UPDATE
|
| EventDistributor.FEED_LIST_UPDATE
|
||||||
| EventDistributor.UNREAD_ITEMS_UPDATE
|
| EventDistributor.UNREAD_ITEMS_UPDATE;
|
||||||
| EventDistributor.QUEUE_UPDATE;
|
|
||||||
|
|
||||||
public static final String PREF_NAME = "MainActivityPrefs";
|
public static final String PREF_NAME = "MainActivityPrefs";
|
||||||
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
||||||
@ -324,6 +323,13 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
EventDistributor.getInstance().register(contentUpdate);
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@ -333,7 +339,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
StorageUtils.checkStorageAvailability(this);
|
StorageUtils.checkStorageAvailability(this);
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (navDrawerData != null && intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) {
|
if (navDrawerData != null && intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) {
|
||||||
@ -348,6 +353,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
cancelLoadTask();
|
cancelLoadTask();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
EventDistributor.getInstance().unregister(contentUpdate);
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -436,6 +442,11 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEvent(QueueEvent event) {
|
||||||
|
Log.d(TAG, "onEvent(" + event + ")");
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,7 +67,6 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
|||||||
|
|
||||||
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED |
|
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED |
|
||||||
EventDistributor.DOWNLOAD_QUEUED |
|
EventDistributor.DOWNLOAD_QUEUED |
|
||||||
EventDistributor.QUEUE_UPDATE |
|
|
||||||
EventDistributor.UNREAD_ITEMS_UPDATE;
|
EventDistributor.UNREAD_ITEMS_UPDATE;
|
||||||
|
|
||||||
private static final String ARG_FEEDITEM = "feeditem";
|
private static final String ARG_FEEDITEM = "feeditem";
|
||||||
@ -129,6 +128,7 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
EventDistributor.getInstance().register(contentUpdate);
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
if (downloadObserver != null) {
|
if (downloadObserver != null) {
|
||||||
downloadObserver.setActivity(getActivity());
|
downloadObserver.setActivity(getActivity());
|
||||||
downloadObserver.onResume();
|
downloadObserver.onResume();
|
||||||
@ -143,6 +143,7 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
|||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
EventDistributor.getInstance().unregister(contentUpdate);
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetViewState() {
|
private void resetViewState() {
|
||||||
@ -392,6 +393,10 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEvent(QueueEvent event) {
|
||||||
|
Log.d(TAG, "onEvent(" + event + ")");
|
||||||
|
getLoaderManager().restartLoader(0, null, ItemFragment.this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Pair<FeedItem,LongList>> onCreateLoader(int id, Bundle args) {
|
public Loader<Pair<FeedItem,LongList>> onCreateLoader(int id, Bundle args) {
|
||||||
|
@ -67,7 +67,6 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
|
|
||||||
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED
|
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED
|
||||||
| EventDistributor.DOWNLOAD_QUEUED
|
| EventDistributor.DOWNLOAD_QUEUED
|
||||||
| EventDistributor.QUEUE_UPDATE
|
|
||||||
| EventDistributor.UNREAD_ITEMS_UPDATE
|
| EventDistributor.UNREAD_ITEMS_UPDATE
|
||||||
| EventDistributor.PLAYER_STATUS_UPDATE;
|
| EventDistributor.PLAYER_STATUS_UPDATE;
|
||||||
|
|
||||||
@ -120,6 +119,7 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
EventDistributor.getInstance().register(contentUpdate);
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
if (downloadObserver != null) {
|
if (downloadObserver != null) {
|
||||||
downloadObserver.setActivity(getActivity());
|
downloadObserver.setActivity(getActivity());
|
||||||
downloadObserver.onResume();
|
downloadObserver.onResume();
|
||||||
@ -133,6 +133,7 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
EventDistributor.getInstance().unregister(contentUpdate);
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
stopItemLoader();
|
stopItemLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,6 +286,11 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEvent(QueueEvent event) {
|
||||||
|
Log.d(TAG, "onEvent(" + event + ")");
|
||||||
|
startItemLoader();
|
||||||
|
}
|
||||||
|
|
||||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -45,13 +44,9 @@ import de.danoeh.antennapod.core.storage.DBReader;
|
|||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
|
import de.danoeh.antennapod.core.util.LongList;
|
||||||
import de.danoeh.antennapod.core.util.QueueAccess;
|
|
||||||
import de.danoeh.antennapod.core.util.gui.FeedItemUndoToken;
|
import de.danoeh.antennapod.core.util.gui.FeedItemUndoToken;
|
||||||
import de.danoeh.antennapod.core.util.gui.UndoBarController;
|
import de.danoeh.antennapod.core.util.gui.UndoBarController;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.util.LongList;
|
|
||||||
|
|
||||||
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
|
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
|
||||||
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
@ -112,6 +107,7 @@ public class NewEpisodesFragment extends Fragment {
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
EventDistributor.getInstance().register(contentUpdate);
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
this.activity.set((MainActivity) getActivity());
|
this.activity.set((MainActivity) getActivity());
|
||||||
if (downloadObserver != null) {
|
if (downloadObserver != null) {
|
||||||
downloadObserver.setActivity(getActivity());
|
downloadObserver.setActivity(getActivity());
|
||||||
@ -126,6 +122,7 @@ public class NewEpisodesFragment extends Fragment {
|
|||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
EventDistributor.getInstance().unregister(contentUpdate);
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
stopItemLoader();
|
stopItemLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,17 +266,26 @@ public class NewEpisodesFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
undoBarController = new UndoBarController(root.findViewById(R.id.undobar), new UndoBarController.UndoListener() {
|
undoBarController = new UndoBarController<FeedItemUndoToken>(root.findViewById(R.id.undobar), new UndoBarController.UndoListener<FeedItemUndoToken>() {
|
||||||
@Override
|
@Override
|
||||||
public void onUndo(Parcelable token) {
|
public void onUndo(FeedItemUndoToken token) {
|
||||||
// Perform the undo
|
|
||||||
FeedItemUndoToken undoToken = (FeedItemUndoToken) token;
|
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
long itemId = undoToken.getFeedItemId();
|
long itemId = token.getFeedItemId();
|
||||||
int position = undoToken.getPosition();
|
int position = token.getPosition();
|
||||||
DBWriter.markItemRead(getActivity(), itemId, false);
|
DBWriter.markItemRead(getActivity(), itemId, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onHide(FeedItemUndoToken token) {
|
||||||
|
if (token != null) {
|
||||||
|
long itemId = token.getFeedItemId();
|
||||||
|
FeedItem item = DBReader.getFeedItem(getActivity(), itemId);
|
||||||
|
FeedMedia media = item.getMedia();
|
||||||
|
if(media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
|
||||||
|
DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final int secondColor = (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) ? R.color.swipe_refresh_secondary_color_dark : R.color.swipe_refresh_secondary_color_light;
|
final int secondColor = (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) ? R.color.swipe_refresh_secondary_color_dark : R.color.swipe_refresh_secondary_color_light;
|
||||||
@ -371,6 +377,11 @@ public class NewEpisodesFragment extends Fragment {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void onEvent(QueueEvent event) {
|
||||||
|
Log.d(TAG, "onEvent(" + event + ")");
|
||||||
|
startItemLoader();
|
||||||
|
}
|
||||||
|
|
||||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||||
|
@ -70,12 +70,14 @@ public class PlaybackHistoryFragment extends ListFragment {
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
EventDistributor.getInstance().register(contentUpdate);
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
EventDistributor.getInstance().unregister(contentUpdate);
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
stopItemLoader();
|
stopItemLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +171,11 @@ public class PlaybackHistoryFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEvent(QueueEvent event) {
|
||||||
|
Log.d(TAG, "onEvent(" + event + ")");
|
||||||
|
startItemLoader();
|
||||||
|
}
|
||||||
|
|
||||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,7 +58,6 @@ public class QueueFragment extends Fragment {
|
|||||||
private static final String TAG = "QueueFragment";
|
private static final String TAG = "QueueFragment";
|
||||||
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED |
|
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED |
|
||||||
EventDistributor.DOWNLOAD_QUEUED |
|
EventDistributor.DOWNLOAD_QUEUED |
|
||||||
EventDistributor.QUEUE_UPDATE |
|
|
||||||
EventDistributor.PLAYER_STATUS_UPDATE;
|
EventDistributor.PLAYER_STATUS_UPDATE;
|
||||||
|
|
||||||
private DragSortListView listView;
|
private DragSortListView listView;
|
||||||
@ -66,7 +65,7 @@ public class QueueFragment extends Fragment {
|
|||||||
private TextView txtvEmpty;
|
private TextView txtvEmpty;
|
||||||
private ProgressBar progLoading;
|
private ProgressBar progLoading;
|
||||||
|
|
||||||
private UndoBarController undoBarController;
|
private UndoBarController<FeedItemUndoToken> undoBarController;
|
||||||
|
|
||||||
private List<FeedItem> queue;
|
private List<FeedItem> queue;
|
||||||
private List<Downloader> downloaderList;
|
private List<Downloader> downloaderList;
|
||||||
@ -106,6 +105,7 @@ public class QueueFragment extends Fragment {
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
EventDistributor.getInstance().register(contentUpdate);
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
this.activity.set((MainActivity) getActivity());
|
this.activity.set((MainActivity) getActivity());
|
||||||
if (downloadObserver != null) {
|
if (downloadObserver != null) {
|
||||||
downloadObserver.setActivity(getActivity());
|
downloadObserver.setActivity(getActivity());
|
||||||
@ -126,6 +126,7 @@ public class QueueFragment extends Fragment {
|
|||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
EventDistributor.getInstance().unregister(contentUpdate);
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
stopItemLoader();
|
stopItemLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +136,15 @@ public class QueueFragment extends Fragment {
|
|||||||
this.activity.set((MainActivity) activity);
|
this.activity.set((MainActivity) activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEventMainThread(QueueEvent event) {
|
||||||
|
Log.d(TAG, "onEvent(" + event + ")");
|
||||||
|
if(event.action == QueueEvent.Action.REMOVED) {
|
||||||
|
undoBarController.showUndoBar(false, getString(R.string.removed_from_queue),
|
||||||
|
new FeedItemUndoToken(event.item, event.position));
|
||||||
|
}
|
||||||
|
startItemLoader();
|
||||||
|
}
|
||||||
|
|
||||||
private void saveScrollPosition() {
|
private void saveScrollPosition() {
|
||||||
SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE);
|
SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
@ -345,29 +355,40 @@ public class QueueFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(int which) {
|
public void remove(int which) {
|
||||||
Log.d(TAG, "remove("+which+")");
|
Log.d(TAG, "remove(" + which + ")");
|
||||||
stopItemLoader();
|
stopItemLoader();
|
||||||
FeedItem item = (FeedItem) listView.getAdapter().getItem(which);
|
FeedItem item = (FeedItem) listView.getAdapter().getItem(which);
|
||||||
DBWriter.removeQueueItem(getActivity(), item.getId(), true);
|
DBWriter.markItemRead(getActivity(), item.getId(), true);
|
||||||
undoBarController.showUndoBar(false,
|
DBWriter.removeQueueItem(getActivity(), item, true);
|
||||||
getString(R.string.removed_from_queue), new FeedItemUndoToken(item,
|
|
||||||
which)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
undoBarController = new UndoBarController(root.findViewById(R.id.undobar), new UndoBarController.UndoListener() {
|
undoBarController = new UndoBarController<FeedItemUndoToken>(root.findViewById(R.id.undobar),
|
||||||
@Override
|
new UndoBarController.UndoListener<FeedItemUndoToken>() {
|
||||||
public void onUndo(Parcelable token) {
|
|
||||||
// Perform the undo
|
@Override
|
||||||
FeedItemUndoToken undoToken = (FeedItemUndoToken) token;
|
public void onUndo(FeedItemUndoToken token) {
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
long itemId = undoToken.getFeedItemId();
|
long itemId = token.getFeedItemId();
|
||||||
int position = undoToken.getPosition();
|
int position = token.getPosition();
|
||||||
DBWriter.addQueueItemAt(getActivity(), itemId, position, false);
|
DBWriter.markItemRead(getActivity(), itemId, false);
|
||||||
}
|
DBWriter.addQueueItemAt(getActivity(), itemId, position, false);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHide(FeedItemUndoToken token) {
|
||||||
|
if (token != null) {
|
||||||
|
long itemId = token.getFeedItemId();
|
||||||
|
FeedItem item = DBReader.getFeedItem(getActivity(), itemId);
|
||||||
|
FeedMedia media = item.getMedia();
|
||||||
|
if(media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
|
||||||
|
DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
registerForContextMenu(listView);
|
registerForContextMenu(listView);
|
||||||
|
@ -17,7 +17,6 @@ import de.danoeh.antennapod.core.storage.DBWriter;
|
|||||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
import de.danoeh.antennapod.core.util.LongList;
|
import de.danoeh.antennapod.core.util.LongList;
|
||||||
import de.danoeh.antennapod.core.util.QueueAccess;
|
|
||||||
import de.danoeh.antennapod.core.util.ShareUtils;
|
import de.danoeh.antennapod.core.util.ShareUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +56,7 @@ public class FeedItemMenuHandler {
|
|||||||
* @return Returns true if selectedItem is not null.
|
* @return Returns true if selectedItem is not null.
|
||||||
*/
|
*/
|
||||||
public static boolean onPrepareMenu(MenuInterface mi,
|
public static boolean onPrepareMenu(MenuInterface mi,
|
||||||
FeedItem selectedItem, boolean showExtendedMenu, QueueAccess queueAccess) {
|
FeedItem selectedItem, boolean showExtendedMenu, LongList queueAccess) {
|
||||||
if (selectedItem == null) {
|
if (selectedItem == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -45,4 +45,5 @@ dependencies {
|
|||||||
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
|
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
|
||||||
compile 'com.squareup.okio:okio:1.2.0'
|
compile 'com.squareup.okio:okio:1.2.0'
|
||||||
compile 'com.nineoldandroids:library:2.4.0'
|
compile 'com.nineoldandroids:library:2.4.0'
|
||||||
|
compile 'de.greenrobot:eventbus:2.4.0'
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ public class EventDistributor extends Observable {
|
|||||||
|
|
||||||
public static final int FEED_LIST_UPDATE = 1;
|
public static final int FEED_LIST_UPDATE = 1;
|
||||||
public static final int UNREAD_ITEMS_UPDATE = 2;
|
public static final int UNREAD_ITEMS_UPDATE = 2;
|
||||||
public static final int QUEUE_UPDATE = 4;
|
|
||||||
public static final int DOWNLOADLOG_UPDATE = 8;
|
public static final int DOWNLOADLOG_UPDATE = 8;
|
||||||
public static final int PLAYBACK_HISTORY_UPDATE = 16;
|
public static final int PLAYBACK_HISTORY_UPDATE = 16;
|
||||||
public static final int DOWNLOAD_QUEUED = 32;
|
public static final int DOWNLOAD_QUEUED = 32;
|
||||||
@ -97,10 +96,6 @@ public class EventDistributor extends Observable {
|
|||||||
addEvent(UNREAD_ITEMS_UPDATE);
|
addEvent(UNREAD_ITEMS_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendQueueUpdateBroadcast() {
|
|
||||||
addEvent(QUEUE_UPDATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendFeedUpdateBroadcast() {
|
public void sendFeedUpdateBroadcast() {
|
||||||
addEvent(FEED_LIST_UPDATE);
|
addEvent(FEED_LIST_UPDATE);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package de.danoeh.antennapod.core.feed;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class QueueEvent {
|
||||||
|
|
||||||
|
public enum Action {
|
||||||
|
ADDED, ADDED_ITEMS, REMOVED, CLEARED, DELETED_MEDIA, SORTED
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Action action;
|
||||||
|
public final FeedItem item;
|
||||||
|
public final int position;
|
||||||
|
public final List<FeedItem> items;
|
||||||
|
|
||||||
|
public QueueEvent(Action action) {
|
||||||
|
this(action, null, null, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueEvent(Action action, FeedItem item) {
|
||||||
|
this(action, item, null, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueEvent(Action action, FeedItem item, int position) {
|
||||||
|
this(action, item, null, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueEvent(Action action, List<FeedItem> items) {
|
||||||
|
this(action, null, items, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QueueEvent(Action action, FeedItem item, List<FeedItem> items, int position) {
|
||||||
|
this.action = action;
|
||||||
|
this.item = item;
|
||||||
|
this.items = items;
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
|
||||||
|
.append("action", action)
|
||||||
|
.append("item", item)
|
||||||
|
.append("items", items)
|
||||||
|
.append("position", position)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -76,18 +76,13 @@ public class PlaybackServiceTaskManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
loadQueue();
|
loadQueue();
|
||||||
EventDistributor.getInstance().register(eventDistributorListener);
|
EventBus.getDefault().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EventDistributor.EventListener eventDistributorListener = new EventDistributor.EventListener() {
|
public void onEvent(QueueEvent event) {
|
||||||
@Override
|
cancelQueueLoader();
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
loadQueue();
|
||||||
if ((EventDistributor.QUEUE_UPDATE & arg) != 0) {
|
}
|
||||||
cancelQueueLoader();
|
|
||||||
loadQueue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private synchronized boolean isQueueLoaderActive() {
|
private synchronized boolean isQueueLoaderActive() {
|
||||||
return queueFuture != null && !queueFuture.isDone();
|
return queueFuture != null && !queueFuture.isDone();
|
||||||
@ -319,7 +314,7 @@ public class PlaybackServiceTaskManager {
|
|||||||
* execution of this method.
|
* execution of this method.
|
||||||
*/
|
*/
|
||||||
public synchronized void shutdown() {
|
public synchronized void shutdown() {
|
||||||
EventDistributor.getInstance().unregister(eventDistributorListener);
|
EventBus.getDefault().unregister(this);
|
||||||
cancelAllTasks();
|
cancelAllTasks();
|
||||||
schedExecutor.shutdown();
|
schedExecutor.shutdown();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|||||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
import de.danoeh.antennapod.core.util.LongList;
|
import de.danoeh.antennapod.core.util.LongList;
|
||||||
import de.danoeh.antennapod.core.util.QueueAccess;
|
|
||||||
import de.danoeh.antennapod.core.util.flattr.FlattrStatus;
|
import de.danoeh.antennapod.core.util.flattr.FlattrStatus;
|
||||||
import de.danoeh.antennapod.core.util.flattr.FlattrThing;
|
import de.danoeh.antennapod.core.util.flattr.FlattrThing;
|
||||||
import de.danoeh.antennapod.core.util.flattr.SimpleFlattrThing;
|
import de.danoeh.antennapod.core.util.flattr.SimpleFlattrThing;
|
||||||
@ -350,8 +349,7 @@ public class DBWriter {
|
|||||||
public void run() {
|
public void run() {
|
||||||
final PodDBAdapter adapter = new PodDBAdapter(context);
|
final PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
final List<FeedItem> queue = DBReader
|
final List<FeedItem> queue = DBReader.getQueue(context, adapter);
|
||||||
.getQueue(context, adapter);
|
|
||||||
FeedItem item = null;
|
FeedItem item = null;
|
||||||
|
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
@ -490,21 +488,14 @@ public class DBWriter {
|
|||||||
public void run() {
|
public void run() {
|
||||||
final PodDBAdapter adapter = new PodDBAdapter(context);
|
final PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
final List<FeedItem> queue = DBReader
|
final List<FeedItem> queue = DBReader.getQueue(context, adapter);
|
||||||
.getQueue(context, adapter);
|
|
||||||
FeedItem item = null;
|
|
||||||
|
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
boolean queueModified = false;
|
int position = queue.indexOf(item);
|
||||||
QueueAccess queueAccess = QueueAccess.ItemListAccess(queue);
|
if(position >= 0) {
|
||||||
if (queueAccess.contains(item.getId())) {
|
queue.remove(position);
|
||||||
if (item != null) {
|
|
||||||
queueModified = queueAccess.remove(item.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (queueModified) {
|
|
||||||
adapter.setQueue(queue);
|
adapter.setQueue(queue);
|
||||||
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.REMOVED, item));
|
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.REMOVED, item, position));
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Queue was not modified by call to removeQueueItem");
|
Log.w(TAG, "Queue was not modified by call to removeQueueItem");
|
||||||
}
|
}
|
||||||
@ -628,6 +619,19 @@ public class DBWriter {
|
|||||||
adapter.close();
|
adapter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the 'read'-attribute of a FeedItem to the specified value.
|
||||||
|
*
|
||||||
|
* @param context A context that is used for opening a database connection.
|
||||||
|
* @param itemId ID of the FeedItem
|
||||||
|
* @param read New value of the 'read'-attribute
|
||||||
|
*/
|
||||||
|
public static Future<?> markItemRead(final Context context, final long itemId,
|
||||||
|
final boolean read) {
|
||||||
|
return markItemRead(context, itemId, read, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the 'read'-attribute of a FeedItem to the specified value.
|
* Sets the 'read'-attribute of a FeedItem to the specified value.
|
||||||
*
|
*
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package de.danoeh.antennapod.core.util.gui;
|
package de.danoeh.antennapod.core.util.gui;
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -16,23 +13,36 @@ import de.danoeh.antennapod.core.R;
|
|||||||
|
|
||||||
import static com.nineoldandroids.view.ViewPropertyAnimator.animate;
|
import static com.nineoldandroids.view.ViewPropertyAnimator.animate;
|
||||||
|
|
||||||
public class UndoBarController {
|
public class UndoBarController<T> {
|
||||||
private View mBarView;
|
private View mBarView;
|
||||||
private TextView mMessageView;
|
private TextView mMessageView;
|
||||||
private ViewPropertyAnimator mBarAnimator;
|
private ViewPropertyAnimator mBarAnimator;
|
||||||
private Handler mHideHandler = new Handler();
|
private Handler mHideHandler = new Handler();
|
||||||
|
|
||||||
private UndoListener mUndoListener;
|
private UndoListener<T> mUndoListener;
|
||||||
|
|
||||||
// State objects
|
// State objects
|
||||||
private Parcelable mUndoToken;
|
private T mUndoToken;
|
||||||
private CharSequence mUndoMessage;
|
private CharSequence mUndoMessage;
|
||||||
|
|
||||||
public interface UndoListener {
|
public interface UndoListener<T> {
|
||||||
void onUndo(Parcelable token);
|
/**
|
||||||
|
* This callback function is called when the undo button is pressed
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
*/
|
||||||
|
void onUndo(T token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This callback function is called when the bar fades out without button press
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
*/
|
||||||
|
void onHide(T token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UndoBarController(View undoBarView, UndoListener undoListener) {
|
public UndoBarController(View undoBarView, UndoListener<T> undoListener) {
|
||||||
mBarView = undoBarView;
|
mBarView = undoBarView;
|
||||||
mBarAnimator = animate(mBarView);
|
mBarAnimator = animate(mBarView);
|
||||||
mUndoListener = undoListener;
|
mUndoListener = undoListener;
|
||||||
@ -50,7 +60,7 @@ public class UndoBarController {
|
|||||||
hideUndoBar(true);
|
hideUndoBar(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showUndoBar(boolean immediate, CharSequence message, Parcelable undoToken) {
|
public void showUndoBar(boolean immediate, CharSequence message, T undoToken) {
|
||||||
mUndoToken = undoToken;
|
mUndoToken = undoToken;
|
||||||
mUndoMessage = message;
|
mUndoMessage = message;
|
||||||
mMessageView.setText(mUndoMessage);
|
mMessageView.setText(mUndoMessage);
|
||||||
@ -96,26 +106,11 @@ public class UndoBarController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
outState.putCharSequence("undo_message", mUndoMessage);
|
|
||||||
outState.putParcelable("undo_token", mUndoToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
mUndoMessage = savedInstanceState.getCharSequence("undo_message");
|
|
||||||
mUndoToken = savedInstanceState.getParcelable("undo_token");
|
|
||||||
|
|
||||||
if (mUndoToken != null || !TextUtils.isEmpty(mUndoMessage)) {
|
|
||||||
showUndoBar(true, mUndoMessage, mUndoToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Runnable mHideRunnable = new Runnable() {
|
private Runnable mHideRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
hideUndoBar(false);
|
hideUndoBar(false);
|
||||||
|
mUndoListener.onHide(mUndoToken);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user