Merge branch 'feed-item-labels' of git://github.com/patheticpat/AntennaPod into patheticpat-feed-item-labels

Conflicts:
	src/de/danoeh/antennapod/feed/FeedItem.java
This commit is contained in:
daniel oeh 2012-11-16 19:17:13 +01:00
commit a7831abf77
11 changed files with 211 additions and 92 deletions

View File

@ -1,102 +1,103 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" > android:paddingLeft="4dp" >
<ImageButton <View
android:id="@+id/butAction" android:id="@+id/vStatusLabel"
android:layout_width="wrap_content" android:layout_width="5dip"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentRight="true" android:background="@color/status_unread"
android:layout_centerVertical="true" android:visibility="invisible" />
android:background="@drawable/borderless_button"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="8dp"
android:scaleType="fitXY"
android:src="@drawable/navigation_expand" />
<LinearLayout <RelativeLayout
android:layout_width="wrap_content" android:layout_width="0dip"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentLeft="true" android:layout_weight="1"
android:layout_marginBottom="4dp" android:paddingLeft="4dp" >
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_toLeftOf="@id/butAction"
android:orientation="vertical" >
<TextView <TextView
android:id="@+id/txtvItemname" android:id="@+id/txtvItemname"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:layout_toLeftOf="@+id/butAction"
android:textSize="16dp" /> android:textSize="16dp" />
<TextView <TextView
android:id="@+id/txtvFeedname" android:id="@+id/txtvFeedname"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/txtvItemname"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:layout_toLeftOf="@id/butAction"
android:visibility="gone" /> android:visibility="gone" />
<TextView <TextView
android:id="@+id/txtvPublished" android:id="@+id/txtvPublished"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/txtvFeedname"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:layout_toLeftOf="@id/butAction"
android:textColor="@color/gray" /> android:textColor="@color/gray" />
<RelativeLayout <ImageView
android:id="@+id/enc_info" android:id="@+id/imgvType"
android:layout_width="match_parent" android:layout_width="@dimen/enc_icons_size"
android:layout_height="wrap_content" > android:layout_height="@dimen/enc_icons_size"
android:layout_below="@id/txtvPublished"
android:layout_toLeftOf="@+id/imgvInPlaylist" />
<LinearLayout <ImageView
android:id="@+id/enc_icons" android:id="@id/imgvInPlaylist"
android:layout_width="wrap_content" android:layout_width="@dimen/enc_icons_size"
android:layout_height="@dimen/enc_icons_size" android:layout_height="@dimen/enc_icons_size"
android:layout_alignParentRight="true" android:layout_below="@id/txtvPublished"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/imgvDownloaded"
android:orientation="horizontal" > android:src="@drawable/stat_playlist"
android:visibility="visible" />
<ImageView <ImageView
android:id="@+id/imgvType" android:id="@id/imgvDownloaded"
android:layout_width="@dimen/enc_icons_size" android:layout_width="@dimen/enc_icons_size"
android:layout_height="match_parent" /> android:layout_height="@dimen/enc_icons_size"
android:layout_below="@id/txtvPublished"
android:layout_toLeftOf="@+id/imgvDownloading"
android:src="@drawable/av_download"
android:visibility="visible" />
<ImageView <ImageView
android:id="@+id/imgvInPlaylist" android:id="@id/imgvDownloading"
android:layout_width="@dimen/enc_icons_size" android:layout_width="@dimen/enc_icons_size"
android:layout_height="match_parent" android:layout_height="@dimen/enc_icons_size"
android:src="@drawable/stat_playlist" android:layout_below="@id/txtvPublished"
android:visibility="gone" /> android:layout_toLeftOf="@id/butAction"
android:src="@drawable/navigation_refresh"
android:visibility="visible" />
<ImageView <TextView
android:id="@+id/imgvDownloaded" android:id="@+id/txtvLenSize"
android:layout_width="@dimen/enc_icons_size" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:src="@drawable/av_download" android:layout_alignParentLeft="true"
android:visibility="gone" /> android:layout_below="@id/txtvPublished"
android:maxLines="2" />
<ImageView <ImageButton
android:id="@+id/imgvDownloading" android:id="@id/butAction"
android:layout_width="@dimen/enc_icons_size" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/navigation_refresh" android:layout_alignParentRight="true"
android:visibility="gone" /> android:layout_centerVertical="true"
</LinearLayout> android:background="@drawable/borderless_button"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="8dp"
android:scaleType="center"
android:src="@drawable/navigation_expand" />
</RelativeLayout>
<TextView </LinearLayout>
android:id="@+id/txtvLenSize"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/enc_icons"
android:maxLines="2" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -3,7 +3,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:paddingRight="16dp" android:paddingRight="8dp"
android:paddingTop="4dp" > android:paddingTop="4dp" >
<ImageView <ImageView
@ -18,19 +18,61 @@
android:cropToPadding="true" android:cropToPadding="true"
android:scaleType="fitXY" /> android:scaleType="fitXY" />
<TextView <LinearLayout
android:id="@+id/txtvNewEps" android:id="@+id/lEpisodeCounts"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="fill_parent"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:textSize="20dp" android:orientation="vertical" >
android:textStyle="bold" />
<LinearLayout
android:id="@+id/lNewStatusLabel"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1" >
<TextView
android:id="@+id/txtvNewEps"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="4dip"
android:textSize="20dp"
android:textStyle="bold" />
<View
android:layout_width="5dip"
android:layout_height="match_parent"
android:background="@color/status_unread"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:id="@+id/lProgressStatusLabel"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1" >
<TextView
android:id="@+id/txtvProgressEps"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="4dip"
android:textSize="20dp"
android:textStyle="bold" />
<View
android:layout_width="5dip"
android:layout_height="match_parent"
android:background="@color/status_progress"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_toLeftOf="@id/txtvNewEps" android:layout_toLeftOf="@id/lEpisodeCounts"
android:layout_toRightOf="@id/imgvFeedimage" android:layout_toRightOf="@id/imgvFeedimage"
android:orientation="vertical" > android:orientation="vertical" >

View File

@ -23,5 +23,7 @@
<color name="actionbar_gray">#DDDDDD</color> <color name="actionbar_gray">#DDDDDD</color>
<color name="download_success_green">#669900</color> <color name="download_success_green">#669900</color>
<color name="download_failed_red">#CC0000</color> <color name="download_failed_red">#CC0000</color>
<color name="status_unread">#99CC00</color>
<color name="status_progress">#FFBB33</color>
</resources> </resources>

View File

@ -14,7 +14,6 @@ import android.widget.Adapter;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
@ -68,12 +67,12 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.type = (ImageView) convertView.findViewById(R.id.imgvType); holder.type = (ImageView) convertView.findViewById(R.id.imgvType);
holder.downloading = (ImageView) convertView holder.downloading = (ImageView) convertView
.findViewById(R.id.imgvDownloading); .findViewById(R.id.imgvDownloading);
holder.encInfo = (RelativeLayout) convertView
.findViewById(R.id.enc_info);
if (showFeedtitle) { if (showFeedtitle) {
holder.feedtitle = (TextView) convertView holder.feedtitle = (TextView) convertView
.findViewById(R.id.txtvFeedname); .findViewById(R.id.txtvFeedname);
} }
holder.statusLabel = (View) convertView
.findViewById(R.id.vStatusLabel);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
@ -93,22 +92,34 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.feedtitle.setVisibility(View.VISIBLE); holder.feedtitle.setVisibility(View.VISIBLE);
holder.feedtitle.setText(item.getFeed().getTitle()); holder.feedtitle.setText(item.getFeed().getTitle());
} }
if (!item.isRead()) {
if (item.isInProgress()) {
holder.title.setTypeface(Typeface.DEFAULT_BOLD); 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()) {
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
holder.statusLabel.setBackgroundColor(convertView.getResources().getColor(R.color.status_unread));
holder.statusLabel.setVisibility(View.VISIBLE);
} else { } else {
holder.title.setTypeface(Typeface.DEFAULT); holder.title.setTypeface(Typeface.DEFAULT);
holder.statusLabel.setVisibility(View.INVISIBLE);
} }
holder.published.setText(convertView.getResources().getString( holder.published.setText(convertView.getResources().getString(
R.string.published_prefix) R.string.published_prefix)
+ DateUtils.formatSameDayTime(item.getPubDate().getTime(), + DateUtils.formatSameDayTime(item.getPubDate().getTime(),
System.currentTimeMillis(), DateFormat.SHORT, System.currentTimeMillis(), DateFormat.MEDIUM,
DateFormat.SHORT)); DateFormat.SHORT));
if (item.getMedia() == null) { if (item.getMedia() == null) {
holder.encInfo.setVisibility(View.GONE); holder.downloaded.setVisibility(View.GONE);
holder.downloading.setVisibility(View.GONE);
holder.inPlaylist.setVisibility(View.GONE);
holder.type.setVisibility(View.GONE);
holder.lenSize.setVisibility(View.GONE);
} else { } else {
holder.encInfo.setVisibility(View.VISIBLE); holder.lenSize.setVisibility(View.VISIBLE);
if (FeedManager.getInstance().isInQueue(item)) { if (FeedManager.getInstance().isInQueue(item)) {
holder.inPlaylist.setVisibility(View.VISIBLE); holder.inPlaylist.setVisibility(View.VISIBLE);
} else { } else {
@ -139,10 +150,13 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
MediaType mediaType = item.getMedia().getMediaType(); MediaType mediaType = item.getMedia().getMediaType();
if (mediaType == MediaType.AUDIO) { if (mediaType == MediaType.AUDIO) {
holder.type.setImageResource(R.drawable.type_audio); holder.type.setImageResource(R.drawable.type_audio);
holder.type.setVisibility(View.VISIBLE);
} else if (mediaType == MediaType.VIDEO) { } else if (mediaType == MediaType.VIDEO) {
holder.type.setImageResource(R.drawable.type_video); holder.type.setImageResource(R.drawable.type_video);
holder.type.setVisibility(View.VISIBLE);
} else { } else {
holder.type.setImageBitmap(null); holder.type.setImageBitmap(null);
holder.type.setVisibility(View.GONE);
} }
} }
@ -165,7 +179,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
ImageView type; ImageView type;
ImageView downloading; ImageView downloading;
ImageButton butAction; ImageButton butAction;
RelativeLayout encInfo; View statusLabel;
} }
public int getSelectedItemIndex() { public int getSelectedItemIndex() {

View File

@ -47,6 +47,12 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
holder.newEpisodes = (TextView) convertView holder.newEpisodes = (TextView) convertView
.findViewById(R.id.txtvNewEps); .findViewById(R.id.txtvNewEps);
holder.inProgressEpisodes = (TextView) convertView
.findViewById(R.id.txtvProgressEps);
holder.newEpisodesLabel = (View) convertView
.findViewById(R.id.lNewStatusLabel);
holder.inProgressEpisodesLabel = (View) convertView
.findViewById(R.id.lProgressStatusLabel);
holder.image = (ImageView) convertView holder.image = (ImageView) convertView
.findViewById(R.id.imgvFeedimage); .findViewById(R.id.imgvFeedimage);
holder.lastUpdate = (TextView) convertView holder.lastUpdate = (TextView) convertView
@ -74,18 +80,30 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
R.string.last_update_prefix) R.string.last_update_prefix)
+ DateUtils.formatSameDayTime(feed.getLastUpdate() + DateUtils.formatSameDayTime(feed.getLastUpdate()
.getTime(), System.currentTimeMillis(), .getTime(), System.currentTimeMillis(),
DateFormat.SHORT, DateFormat.SHORT)); DateFormat.MEDIUM, DateFormat.SHORT));
} }
holder.numberOfEpisodes.setText(feed.getNumOfItems() holder.numberOfEpisodes.setText(feed.getNumOfItems()
+ convertView.getResources() + convertView.getResources()
.getString(R.string.episodes_suffix)); .getString(R.string.episodes_suffix));
int newItems = feed.getNumOfNewItems(); int newItems = feed.getNumOfNewItems();
int inProgressItems = feed.getNumOfStartedItems();
if (newItems > 0) { if (newItems > 0) {
holder.newEpisodes.setText(Integer.toString(newItems)); holder.newEpisodes.setText(Integer.toString(newItems));
holder.newEpisodes.setVisibility(View.VISIBLE); holder.newEpisodesLabel.setVisibility(View.VISIBLE);
} else { } else {
holder.newEpisodes.setVisibility(View.INVISIBLE); holder.newEpisodesLabel.setVisibility(View.INVISIBLE);
} }
if (inProgressItems > 0) {
holder.inProgressEpisodes
.setText(Integer.toString(inProgressItems));
holder.inProgressEpisodesLabel.setVisibility(View.VISIBLE);
} else {
holder.inProgressEpisodesLabel.setVisibility(View.INVISIBLE);
}
holder.image.setTag(feed.getImage()); holder.image.setTag(feed.getImage());
imageLoader.loadThumbnailBitmap( imageLoader.loadThumbnailBitmap(
@ -102,7 +120,10 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
TextView lastUpdate; TextView lastUpdate;
TextView numberOfEpisodes; TextView numberOfEpisodes;
TextView newEpisodes; TextView newEpisodes;
TextView inProgressEpisodes;
ImageView image; ImageView image;
View newEpisodesLabel;
View inProgressEpisodesLabel;
} }
public int getSelectedItemIndex() { public int getSelectedItemIndex() {

View File

@ -83,6 +83,21 @@ public class Feed extends FeedFile {
return count; return count;
} }
/**
* Returns the number of FeedItems where the media started to play but
* wasn't finished yet.
* */
public int getNumOfStartedItems() {
int count = 0;
for (FeedItem item : items) {
if (item.isInProgress()) {
count++;
}
}
return count;
}
/** /**
* Returns true if at least one item in the itemlist is unread.If the * Returns true if at least one item in the itemlist is unread.If the
* 'display only episodes' - preference is set to true, this method will * 'display only episodes' - preference is set to true, this method will

View File

@ -147,7 +147,18 @@ public class FeedItem extends FeedComponent {
} }
public boolean isRead() { public boolean isRead() {
return read; return read || isInProgress();
}
public void setRead(boolean read) {
this.read = read;
if (media != null) {
media.setPosition(0);
}
}
public boolean isInProgress() {
return (media != null && media.isInProgress());
} }
public String getContentEncoded() { public String getContentEncoded() {
@ -186,6 +197,10 @@ public class FeedItem extends FeedComponent {
this.itemIdentifier = itemIdentifier; this.itemIdentifier = itemIdentifier;
} }
public boolean hasMedia() {
return media != null;
}
public boolean isPlaying() { public boolean isPlaying() {
if (media != null) { if (media != null) {
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) { if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
@ -202,5 +217,4 @@ 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);
} }
} }

View File

@ -379,8 +379,13 @@ public class FeedManager {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Setting item with title " + item.getTitle() Log.d(TAG, "Setting item with title " + item.getTitle()
+ " as read/unread"); + " as read/unread");
item.read = read;
item.setRead(read);
setFeedItem(context, item); setFeedItem(context, item);
if (item.hasMedia())
setFeedMedia(context, item.getMedia());
contentChanger.post(new Runnable() { contentChanger.post(new Runnable() {
@Override @Override
@ -416,7 +421,7 @@ public class FeedManager {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "marking all items as read"); Log.d(TAG, "marking all items as read");
for (FeedItem item : unreadItems) { for (FeedItem item : unreadItems) {
item.read = true; item.setRead(true);
} }
final ArrayList<FeedItem> unreadItemsCopy = new ArrayList<FeedItem>( final ArrayList<FeedItem> unreadItemsCopy = new ArrayList<FeedItem>(
unreadItems); unreadItems);
@ -430,6 +435,8 @@ public class FeedManager {
adapter.open(); adapter.open();
for (FeedItem item : unreadItemsCopy) { for (FeedItem item : unreadItemsCopy) {
setFeedItem(item, adapter); setFeedItem(item, adapter);
if (item.hasMedia())
setFeedMedia(context, item.getMedia());
} }
adapter.close(); adapter.close();
} }

View File

@ -118,4 +118,8 @@ public class FeedMedia extends FeedFile {
this.playbackCompletionDate = playbackCompletionDate; this.playbackCompletionDate = playbackCompletionDate;
} }
public boolean isInProgress() {
return (this.position > 0);
}
} }

View File

@ -688,7 +688,6 @@ public class PlaybackService extends Service {
.getDefaultSharedPreferences(getApplicationContext()); .getDefaultSharedPreferences(getApplicationContext());
// Save state // Save state
cancelPositionSaver(); cancelPositionSaver();
media.setPosition(0);
media.setPlaybackCompletionDate(new Date()); media.setPlaybackCompletionDate(new Date());
manager.markItemRead(PlaybackService.this, media.getItem(), true); manager.markItemRead(PlaybackService.this, media.getItem(), true);
FeedItem nextItem = manager FeedItem nextItem = manager

View File

@ -50,8 +50,8 @@ 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.isRead() && AppConfig.DEBUG); selectedItem.isRead() || selectedItem.isInProgress());
menu.findItem(R.id.mark_read_item).setVisible(!selectedItem.isRead()); menu.findItem(R.id.mark_read_item).setVisible(!selectedItem.isRead() || selectedItem.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);