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
|
@ -93,25 +93,30 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
|
||||||
holder.feedtitle.setText(item.getFeed().getTitle());
|
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.title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
holder.statusLabel.setBackgroundColor(convertView
|
holder.statusLabel.setBackgroundColor(convertView
|
||||||
.getResources().getColor(R.color.status_playing));
|
.getResources().getColor(R.color.status_playing));
|
||||||
holder.statusLabel.setVisibility(View.VISIBLE);
|
holder.statusLabel.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
} else if (item.isInProgress()) {
|
case IN_PROGRESS:
|
||||||
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
holder.statusLabel.setBackgroundColor(convertView
|
holder.statusLabel.setBackgroundColor(convertView
|
||||||
.getResources().getColor(R.color.status_progress));
|
.getResources().getColor(R.color.status_progress));
|
||||||
holder.statusLabel.setVisibility(View.VISIBLE);
|
holder.statusLabel.setVisibility(View.VISIBLE);
|
||||||
} else if (!item.isRead()) {
|
break;
|
||||||
|
case NEW:
|
||||||
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
holder.statusLabel.setBackgroundColor(convertView
|
holder.statusLabel.setBackgroundColor(convertView
|
||||||
.getResources().getColor(R.color.status_unread));
|
.getResources().getColor(R.color.status_unread));
|
||||||
holder.statusLabel.setVisibility(View.VISIBLE);
|
holder.statusLabel.setVisibility(View.VISIBLE);
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
holder.title.setTypeface(Typeface.DEFAULT);
|
holder.title.setTypeface(Typeface.DEFAULT);
|
||||||
holder.statusLabel.setVisibility(View.INVISIBLE);
|
holder.statusLabel.setVisibility(View.INVISIBLE);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.published.setText(convertView.getResources().getString(
|
holder.published.setText(convertView.getResources().getString(
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class Feed extends FeedFile {
|
||||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||||
|
|
||||||
for (FeedItem item : items) {
|
for (FeedItem item : items) {
|
||||||
if (!item.isRead()) {
|
if (item.getState() == FeedItem.State.NEW) {
|
||||||
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,9 @@ public class Feed extends FeedFile {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for (FeedItem item : items) {
|
for (FeedItem item : items) {
|
||||||
if (item.isInProgress()) {
|
FeedItem.State state = item.getState();
|
||||||
|
if (state == FeedItem.State.IN_PROGRESS
|
||||||
|
|| state == FeedItem.State.PLAYING) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +110,7 @@ public class Feed extends FeedFile {
|
||||||
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
||||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||||
for (FeedItem item : items) {
|
for (FeedItem item : items) {
|
||||||
if (!item.isRead()) {
|
if (item.getState() == FeedItem.State.NEW) {
|
||||||
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class FeedItem extends FeedComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInProgress() {
|
private boolean isInProgress() {
|
||||||
return (media != null && media.isInProgress());
|
return (media != null && media.isInProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ public class FeedItem extends FeedComponent {
|
||||||
return media != null;
|
return media != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaying() {
|
private boolean isPlaying() {
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
|
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -217,4 +217,18 @@ public class FeedItem extends FeedComponent {
|
||||||
public void setCachedContentEncoded(String c) {
|
public void setCachedContentEncoded(String c) {
|
||||||
cachedContentEncoded = new SoftReference<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
|
// delete stored media files and mark them as read
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
if (!item.isRead()) {
|
if (item.getState() == FeedItem.State.NEW) {
|
||||||
unreadItems.remove(item);
|
unreadItems.remove(item);
|
||||||
}
|
}
|
||||||
if (queue.contains(item)) {
|
if (queue.contains(item)) {
|
||||||
|
@ -1173,7 +1173,7 @@ public class FeedManager {
|
||||||
: false;
|
: false;
|
||||||
item.setItemIdentifier(itemlistCursor
|
item.setItemIdentifier(itemlistCursor
|
||||||
.getString(PodDBAdapter.IDX_FI_SMALL_ITEM_IDENTIFIER));
|
.getString(PodDBAdapter.IDX_FI_SMALL_ITEM_IDENTIFIER));
|
||||||
if (!item.read) {
|
if (item.getState() == FeedItem.State.NEW) {
|
||||||
unreadItems.add(item);
|
unreadItems.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
|
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
|
||||||
import de.danoeh.antennapod.feed.FeedItem;
|
import de.danoeh.antennapod.feed.FeedItem;
|
||||||
|
import de.danoeh.antennapod.feed.FeedItem.State;
|
||||||
import de.danoeh.antennapod.feed.FeedManager;
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
import de.danoeh.antennapod.storage.DownloadRequestException;
|
import de.danoeh.antennapod.storage.DownloadRequestException;
|
||||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||||
|
@ -32,6 +33,7 @@ public class FeedItemMenuHandler {
|
||||||
&& requester.isDownloadingFile(selectedItem.getMedia());
|
&& requester.isDownloadingFile(selectedItem.getMedia());
|
||||||
boolean notLoadedAndNotLoading = hasMedia && (!downloaded)
|
boolean notLoadedAndNotLoading = hasMedia && (!downloaded)
|
||||||
&& (!downloading);
|
&& (!downloading);
|
||||||
|
FeedItem.State state = selectedItem.getState();
|
||||||
|
|
||||||
menu.findItem(R.id.play_item).setVisible(downloaded);
|
menu.findItem(R.id.play_item).setVisible(downloaded);
|
||||||
menu.findItem(R.id.remove_item).setVisible(downloaded);
|
menu.findItem(R.id.remove_item).setVisible(downloaded);
|
||||||
|
@ -50,13 +52,11 @@ public class FeedItemMenuHandler {
|
||||||
selectedItem.getLink() != null);
|
selectedItem.getLink() != null);
|
||||||
|
|
||||||
menu.findItem(R.id.mark_unread_item).setVisible(
|
menu.findItem(R.id.mark_unread_item).setVisible(
|
||||||
!selectedItem.isPlaying()
|
state == FeedItem.State.IN_PROGRESS
|
||||||
&& (selectedItem.isRead() || selectedItem
|
|| state == FeedItem.State.READ);
|
||||||
.isInProgress()));
|
|
||||||
menu.findItem(R.id.mark_read_item).setVisible(
|
menu.findItem(R.id.mark_read_item).setVisible(
|
||||||
!selectedItem.isPlaying()
|
state == FeedItem.State.NEW
|
||||||
&& (!selectedItem.isRead() || selectedItem
|
|| state == FeedItem.State.IN_PROGRESS);
|
||||||
.isInProgress()));
|
|
||||||
|
|
||||||
if (selectedItem.getLink() != null) {
|
if (selectedItem.getLink() != null) {
|
||||||
menu.findItem(R.id.visit_website_item).setVisible(true);
|
menu.findItem(R.id.visit_website_item).setVisible(true);
|
||||||
|
|
Loading…
Reference in New Issue