Set episode back to 'New' when undo remove from new episodes.

markItemRead -> markItemPlayed and now requires the desired state instead of boolean.

fixes AntennaPod/AntennaPod#1173
This commit is contained in:
Tom Hennen 2015-09-06 10:51:49 -04:00
parent 1ac58a34eb
commit 05cb09e4fa
11 changed files with 48 additions and 54 deletions

View File

@ -93,7 +93,7 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
}
} else {
if (!item.isPlayed()) {
DBWriter.markItemRead(context, item, true, true);
DBWriter.markItemPlayed(context, item, FeedItem.PLAYED, true);
}
}
}

View File

@ -372,12 +372,12 @@ public class EpisodesApplyActionFragment extends Fragment {
}
private void markedCheckedPlayed() {
DBWriter.markItemRead(getActivity(), true, checkedIds.toArray());
DBWriter.markItemPlayed(getActivity(), FeedItem.PLAYED, checkedIds.toArray());
close();
}
private void markedCheckedUnplayed() {
DBWriter.markItemRead(getActivity(), false, checkedIds.toArray());
DBWriter.markItemPlayed(getActivity(), FeedItem.UNPLAYED, checkedIds.toArray());
close();
}

View File

@ -13,7 +13,6 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.feed.QueueEvent;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.gui.FeedItemUndoToken;
@ -72,7 +71,9 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
Log.d(TAG, "remove(" + which + ")");
stopItemLoader();
FeedItem item = (FeedItem) listView.getAdapter().getItem(which);
DBWriter.markItemRead(getActivity(), true, item.getId());
// we're marking it as unplayed since the user didn't actually play it
// but they don't want it considered 'NEW' anymore
DBWriter.markItemPlayed(getActivity(), FeedItem.UNPLAYED, item.getId());
undoBarController.showUndoBar(false,
getString(R.string.marked_as_read_label), new FeedItemUndoToken(item,
which)
@ -88,7 +89,7 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
public void onUndo(FeedItemUndoToken token) {
if (token != null) {
long itemId = token.getFeedItemId();
DBWriter.markItemRead(context, false, itemId);
DBWriter.markItemPlayed(context, FeedItem.NEW, itemId);
}
}
@Override

View File

@ -155,7 +155,7 @@ public class FeedItemMenuHandler {
break;
case R.id.mark_read_item:
selectedItem.setPlayed(true);
DBWriter.markItemRead(context, selectedItem, true, false);
DBWriter.markItemPlayed(context, selectedItem, FeedItem.PLAYED, false);
if(GpodnetPreferences.loggedIn()) {
FeedMedia media = selectedItem.getMedia();
// not all items have media, Gpodder only cares about those that do
@ -173,7 +173,7 @@ public class FeedItemMenuHandler {
break;
case R.id.mark_unread_item:
selectedItem.setPlayed(false);
DBWriter.markItemRead(context, selectedItem, false, false);
DBWriter.markItemPlayed(context, selectedItem, FeedItem.UNPLAYED, false);
if(GpodnetPreferences.loggedIn()) {
GpodnetEpisodeAction actionNew = new GpodnetEpisodeAction.Builder(selectedItem, Action.NEW)
.currentDeviceId()
@ -195,7 +195,7 @@ public class FeedItemMenuHandler {
break;
case R.id.reset_position:
selectedItem.getMedia().setPosition(0);
DBWriter.markItemRead(context, selectedItem, false, true);
DBWriter.markItemPlayed(context, selectedItem, FeedItem.UNPLAYED, true);
break;
case R.id.activate_auto_download:
selectedItem.setAutoDownload(true);

View File

@ -16,7 +16,6 @@ import android.widget.RemoteViews;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
@ -59,7 +58,7 @@ public class PlayerWidgetService extends Service {
if (media.hasAlmostEnded()) {
Log.d(TAG, "smart mark as read");
FeedItem item = media.getItem();
DBWriter.markItemRead(this, item, true, false);
DBWriter.markItemPlayed(this, item, FeedItem.PLAYED, false);
DBWriter.removeQueueItem(this, item, false);
DBWriter.addItemToPlaybackHistory(this, media);
if (item.getFeed().getPreferences().getCurrentAutoDelete()) {

View File

@ -391,7 +391,7 @@ public class FeedMedia extends FeedFile implements Playable {
public void saveCurrentPosition(SharedPreferences pref, int newPosition) {
DBWriter.setFeedMediaPlaybackInformation(ClientConfig.applicationCallbacks.getApplicationInstance(), this);
if(item.isNew()) {
DBWriter.markItemRead(ClientConfig.applicationCallbacks.getApplicationInstance(), false, item.getId());
DBWriter.markItemPlayed(ClientConfig.applicationCallbacks.getApplicationInstance(), FeedItem.UNPLAYED, item.getId());
}
setPosition(newPosition);
}

View File

@ -244,7 +244,7 @@ public class GpodnetSyncService extends Service {
case NEW:
FeedItem newItem = DBReader.getFeedItem(this, action.getPodcast(), action.getEpisode());
if(newItem != null) {
DBWriter.markItemRead(this, newItem, false, true);
DBWriter.markItemPlayed(this, newItem, FeedItem.UNPLAYED, true);
} else {
Log.i(TAG, "Unknown feed item: " + action);
}
@ -279,7 +279,7 @@ public class GpodnetSyncService extends Service {
media.setPosition(action.getPosition() * 1000);
DBWriter.setFeedMedia(this, media);
if(playItem.getMedia().hasAlmostEnded()) {
DBWriter.markItemRead(this, playItem, true, true);
DBWriter.markItemPlayed(this, playItem, FeedItem.PLAYED, true);
DBWriter.addItemToPlaybackHistory(this, playItem.getMedia());
}
}

View File

@ -5,9 +5,7 @@ import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothHeadset;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@ -15,10 +13,8 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;
import android.media.RemoteControlClient;
import android.media.RemoteControlClient.MetadataEditor;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
@ -31,7 +27,6 @@ import android.view.SurfaceHolder;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.apache.commons.lang3.StringUtils;
@ -569,7 +564,7 @@ public class PlaybackService extends Service {
if (playable instanceof FeedMedia) {
FeedMedia media = (FeedMedia) playable;
FeedItem item = media.getItem();
DBWriter.markItemRead(PlaybackService.this, item, true, true);
DBWriter.markItemPlayed(PlaybackService.this, item, FeedItem.PLAYED, true);
try {
final List<FeedItem> queue = taskManager.getQueue();

View File

@ -201,7 +201,7 @@ public class PlaybackServiceMediaPlayer {
if(oldMedia.hasAlmostEnded()) {
Log.d(TAG, "smart mark as read");
FeedItem item = oldMedia.getItem();
DBWriter.markItemRead(context, item, true, false);
DBWriter.markItemPlayed(context, item, FeedItem.PLAYED, false);
DBWriter.removeQueueItem(context, item, false);
DBWriter.addItemToPlaybackHistory(context, oldMedia);
if (item.getFeed().getPreferences().getCurrentAutoDelete()) {

View File

@ -366,7 +366,7 @@ public class DBWriter {
adapter.setQueue(queue);
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED, item, index));
if(item.isNew()) {
DBWriter.markItemRead(context, false, item.getId());
DBWriter.markItemPlayed(context, FeedItem.UNPLAYED, item.getId());
}
}
}
@ -432,7 +432,7 @@ public class DBWriter {
adapter.setQueue(queue);
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED_ITEMS, queue));
if(markAsUnplayedIds.size() > 0) {
DBWriter.markItemRead(context, false, markAsUnplayedIds.toArray());
DBWriter.markItemPlayed(context, FeedItem.UNPLAYED, markAsUnplayedIds.toArray());
}
}
}
@ -614,20 +614,17 @@ public class DBWriter {
* Sets the 'read'-attribute of all specified FeedItems
*
* @param context A context that is used for opening a database connection.
* @param read New value of the 'read'-attribute
* @param played New value of the 'read'-attribute, one of FeedItem.PLAYED, FeedItem.NEW,
* FeedItem.UNPLAYED
* @param itemIds IDs of the FeedItems.
*/
public static Future<?> markItemRead(final Context context, final boolean read, final long... itemIds) {
return dbExec.submit(new Runnable() {
@Override
public void run() {
final PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
int played = read ? FeedItem.PLAYED : FeedItem.UNPLAYED;
adapter.setFeedItemRead(played, itemIds);
adapter.close();
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
}
public static Future<?> markItemPlayed(final Context context, final int played, final long... itemIds) {
return dbExec.submit(() -> {
final PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setFeedItemRead(played, itemIds);
adapter.close();
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
});
}
@ -637,30 +634,27 @@ public class DBWriter {
*
* @param context A context that is used for opening a database connection.
* @param item The FeedItem object
* @param read New value of the 'read'-attribute
* @param played New value of the 'read'-attribute one of FeedItem.PLAYED,
* FeedItem.NEW, FeedItem.UNPLAYED
* @param resetMediaPosition true if this method should also reset the position of the FeedItem's FeedMedia object.
* If the FeedItem has no FeedMedia object, this parameter will be ignored.
*/
public static Future<?> markItemRead(Context context, FeedItem item, boolean read, boolean resetMediaPosition) {
public static Future<?> markItemPlayed(Context context, FeedItem item, int played, boolean resetMediaPosition) {
long mediaId = (item.hasMedia()) ? item.getMedia().getId() : 0;
return markItemRead(context, item.getId(), read, mediaId, resetMediaPosition);
return markItemPlayed(context, item.getId(), played, mediaId, resetMediaPosition);
}
private static Future<?> markItemRead(final Context context, final long itemId,
final boolean read, final long mediaId,
final boolean resetMediaPosition) {
return dbExec.submit(new Runnable() {
private static Future<?> markItemPlayed(final Context context, final long itemId,
final int played, final long mediaId,
final boolean resetMediaPosition) {
return dbExec.submit(() -> {
final PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setFeedItemRead(played, itemId, mediaId,
resetMediaPosition);
adapter.close();
@Override
public void run() {
final PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setFeedItemRead(read, itemId, mediaId,
resetMediaPosition);
adapter.close();
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
}
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
});
}

View File

@ -778,12 +778,12 @@ public class PodDBAdapter {
return item.getId();
}
public void setFeedItemRead(boolean read, long itemId, long mediaId,
public void setFeedItemRead(int played, long itemId, long mediaId,
boolean resetMediaPosition) {
db.beginTransaction();
ContentValues values = new ContentValues();
values.put(KEY_READ, read ? FeedItem.PLAYED : FeedItem.UNPLAYED);
values.put(KEY_READ, played);
db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?", new String[]{String.valueOf(itemId)});
if (resetMediaPosition) {
@ -796,6 +796,11 @@ public class PodDBAdapter {
db.endTransaction();
}
/**
* Sets the 'read' attribute of the item.
* @param read must be one of FeedItem.PLAYED, FeedItem.NEW, FeedItem.UNPLAYED
* @param itemIds items to change the value of
*/
public void setFeedItemRead(int read, long... itemIds) {
db.beginTransaction();
ContentValues values = new ContentValues();