Added state enum to feeditem class
The getStatus() method should now be used to handle feeditems in different states instead of handling its attributes directly.
This commit is contained in:
parent
385b11eae2
commit
ef5dc7cb0e
|
@ -92,26 +92,31 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
|||
holder.feedtitle.setVisibility(View.VISIBLE);
|
||||
holder.feedtitle.setText(item.getFeed().getTitle());
|
||||
}
|
||||
|
||||
if (item.isPlaying()) {
|
||||
|
||||
FeedItem.State state = item.getState();
|
||||
switch (state) {
|
||||
case PLAYING:
|
||||
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
holder.statusLabel.setBackgroundColor(convertView
|
||||
.getResources().getColor(R.color.status_playing));
|
||||
holder.statusLabel.setVisibility(View.VISIBLE);
|
||||
|
||||
} else if (item.isInProgress()) {
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
holder.statusLabel.setBackgroundColor(convertView
|
||||
.getResources().getColor(R.color.status_progress));
|
||||
holder.statusLabel.setVisibility(View.VISIBLE);
|
||||
} else if (!item.isRead()) {
|
||||
break;
|
||||
case NEW:
|
||||
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
holder.statusLabel.setBackgroundColor(convertView
|
||||
.getResources().getColor(R.color.status_unread));
|
||||
holder.statusLabel.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
holder.title.setTypeface(Typeface.DEFAULT);
|
||||
holder.statusLabel.setVisibility(View.INVISIBLE);
|
||||
break;
|
||||
}
|
||||
|
||||
holder.published.setText(convertView.getResources().getString(
|
||||
|
|
|
@ -74,7 +74,7 @@ public class Feed extends FeedFile {
|
|||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
|
||||
for (FeedItem item : items) {
|
||||
if (!item.isRead()) {
|
||||
if (item.getState() == FeedItem.State.NEW) {
|
||||
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
||||
count++;
|
||||
}
|
||||
|
@ -91,7 +91,9 @@ public class Feed extends FeedFile {
|
|||
int count = 0;
|
||||
|
||||
for (FeedItem item : items) {
|
||||
if (item.isInProgress()) {
|
||||
FeedItem.State state = item.getState();
|
||||
if (state == FeedItem.State.IN_PROGRESS
|
||||
|| state == FeedItem.State.PLAYING) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +110,7 @@ public class Feed extends FeedFile {
|
|||
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
for (FeedItem item : items) {
|
||||
if (!item.isRead()) {
|
||||
if (item.getState() == FeedItem.State.NEW) {
|
||||
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
||||
return true;
|
||||
}
|
||||
|
@ -159,7 +161,7 @@ public class Feed extends FeedFile {
|
|||
return download_url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Calls cacheDescriptions on all items. */
|
||||
protected void cacheDescriptionsOfItems() {
|
||||
if (items != null) {
|
||||
|
|
|
@ -157,7 +157,7 @@ public class FeedItem extends FeedComponent {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isInProgress() {
|
||||
private boolean isInProgress() {
|
||||
return (media != null && media.isInProgress());
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ public class FeedItem extends FeedComponent {
|
|||
return media != null;
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
private boolean isPlaying() {
|
||||
if (media != null) {
|
||||
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
|
||||
return true;
|
||||
|
@ -217,4 +217,18 @@ public class FeedItem extends FeedComponent {
|
|||
public void setCachedContentEncoded(String c) {
|
||||
cachedContentEncoded = new SoftReference<String>(c);
|
||||
}
|
||||
|
||||
public enum State {NEW, IN_PROGRESS, READ, PLAYING}
|
||||
|
||||
public State getState() {
|
||||
if (hasMedia()) {
|
||||
if (isPlaying()) {
|
||||
return State.PLAYING;
|
||||
}
|
||||
if (isInProgress()) {
|
||||
return State.IN_PROGRESS;
|
||||
}
|
||||
}
|
||||
return (isRead() ? State.READ : State.NEW);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class FeedManager {
|
|||
}
|
||||
// delete stored media files and mark them as read
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (!item.isRead()) {
|
||||
if (item.getState() == FeedItem.State.NEW) {
|
||||
unreadItems.remove(item);
|
||||
}
|
||||
if (queue.contains(item)) {
|
||||
|
@ -1173,7 +1173,7 @@ public class FeedManager {
|
|||
: false;
|
||||
item.setItemIdentifier(itemlistCursor
|
||||
.getString(PodDBAdapter.IDX_FI_SMALL_ITEM_IDENTIFIER));
|
||||
if (!item.read) {
|
||||
if (item.getState() == FeedItem.State.NEW) {
|
||||
unreadItems.add(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import de.danoeh.antennapod.AppConfig;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.feed.FeedItem.State;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.storage.DownloadRequestException;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
|
@ -32,6 +33,7 @@ public class FeedItemMenuHandler {
|
|||
&& requester.isDownloadingFile(selectedItem.getMedia());
|
||||
boolean notLoadedAndNotLoading = hasMedia && (!downloaded)
|
||||
&& (!downloading);
|
||||
FeedItem.State state = selectedItem.getState();
|
||||
|
||||
menu.findItem(R.id.play_item).setVisible(downloaded);
|
||||
menu.findItem(R.id.remove_item).setVisible(downloaded);
|
||||
|
@ -50,13 +52,11 @@ public class FeedItemMenuHandler {
|
|||
selectedItem.getLink() != null);
|
||||
|
||||
menu.findItem(R.id.mark_unread_item).setVisible(
|
||||
!selectedItem.isPlaying()
|
||||
&& (selectedItem.isRead() || selectedItem
|
||||
.isInProgress()));
|
||||
state == FeedItem.State.IN_PROGRESS
|
||||
|| state == FeedItem.State.READ);
|
||||
menu.findItem(R.id.mark_read_item).setVisible(
|
||||
!selectedItem.isPlaying()
|
||||
&& (!selectedItem.isRead() || selectedItem
|
||||
.isInProgress()));
|
||||
state == FeedItem.State.NEW
|
||||
|| state == FeedItem.State.IN_PROGRESS);
|
||||
|
||||
if (selectedItem.getLink() != null) {
|
||||
menu.findItem(R.id.visit_website_item).setVisible(true);
|
||||
|
|
Loading…
Reference in New Issue