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"?>
<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_height="match_parent"
android:layout_margin="8dp" >
android:paddingLeft="4dp" >
<ImageButton
android:id="@+id/butAction"
android:layout_width="wrap_content"
<View
android:id="@+id/vStatusLabel"
android:layout_width="5dip"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
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" />
android:background="@color/status_unread"
android:visibility="invisible" />
<LinearLayout
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_toLeftOf="@id/butAction"
android:orientation="vertical" >
android:layout_weight="1"
android:paddingLeft="4dp" >
<TextView
android:id="@+id/txtvItemname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_toLeftOf="@+id/butAction"
android:textSize="16dp" />
<TextView
android:id="@+id/txtvFeedname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtvItemname"
android:layout_marginBottom="4dp"
android:layout_toLeftOf="@id/butAction"
android:visibility="gone" />
<TextView
android:id="@+id/txtvPublished"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtvFeedname"
android:layout_marginBottom="4dp"
android:layout_toLeftOf="@id/butAction"
android:textColor="@color/gray" />
<RelativeLayout
android:id="@+id/enc_info"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imgvType"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="@dimen/enc_icons_size"
android:layout_below="@id/txtvPublished"
android:layout_toLeftOf="@+id/imgvInPlaylist" />
<LinearLayout
android:id="@+id/enc_icons"
android:layout_width="wrap_content"
android:layout_height="@dimen/enc_icons_size"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<ImageView
android:id="@id/imgvInPlaylist"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="@dimen/enc_icons_size"
android:layout_below="@id/txtvPublished"
android:layout_toLeftOf="@+id/imgvDownloaded"
android:src="@drawable/stat_playlist"
android:visibility="visible" />
<ImageView
android:id="@+id/imgvType"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="match_parent" />
<ImageView
android:id="@id/imgvDownloaded"
android:layout_width="@dimen/enc_icons_size"
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
android:id="@+id/imgvInPlaylist"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="match_parent"
android:src="@drawable/stat_playlist"
android:visibility="gone" />
<ImageView
android:id="@id/imgvDownloading"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="@dimen/enc_icons_size"
android:layout_below="@id/txtvPublished"
android:layout_toLeftOf="@id/butAction"
android:src="@drawable/navigation_refresh"
android:visibility="visible" />
<ImageView
android:id="@+id/imgvDownloaded"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="match_parent"
android:src="@drawable/av_download"
android:visibility="gone" />
<TextView
android:id="@+id/txtvLenSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/txtvPublished"
android:maxLines="2" />
<ImageView
android:id="@+id/imgvDownloading"
android:layout_width="@dimen/enc_icons_size"
android:layout_height="match_parent"
android:src="@drawable/navigation_refresh"
android:visibility="gone" />
</LinearLayout>
<ImageButton
android:id="@id/butAction"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
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
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>
</LinearLayout>

View File

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="4dp"
android:paddingRight="16dp"
android:paddingRight="8dp"
android:paddingTop="4dp" >
<ImageView
@ -18,19 +18,61 @@
android:cropToPadding="true"
android:scaleType="fitXY" />
<TextView
android:id="@+id/txtvNewEps"
<LinearLayout
android:id="@+id/lEpisodeCounts"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textSize="20dp"
android:textStyle="bold" />
android:orientation="vertical" >
<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
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/txtvNewEps"
android:layout_toLeftOf="@id/lEpisodeCounts"
android:layout_toRightOf="@id/imgvFeedimage"
android:orientation="vertical" >

View File

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

View File

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

View File

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

View File

@ -83,6 +83,21 @@ public class Feed extends FeedFile {
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
* '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() {
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() {
@ -186,6 +197,10 @@ public class FeedItem extends FeedComponent {
this.itemIdentifier = itemIdentifier;
}
public boolean hasMedia() {
return media != null;
}
public boolean isPlaying() {
if (media != null) {
if (PodcastApp.getCurrentlyPlayingMediaId() == media.getId()) {
@ -202,5 +217,4 @@ public class FeedItem extends FeedComponent {
public void setCachedContentEncoded(String c) {
cachedContentEncoded = new SoftReference<String>(c);
}
}

View File

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

View File

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

View File

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

View File

@ -50,8 +50,8 @@ public class FeedItemMenuHandler {
selectedItem.getLink() != null);
menu.findItem(R.id.mark_unread_item).setVisible(
selectedItem.isRead() && AppConfig.DEBUG);
menu.findItem(R.id.mark_read_item).setVisible(!selectedItem.isRead());
selectedItem.isRead() || selectedItem.isInProgress());
menu.findItem(R.id.mark_read_item).setVisible(!selectedItem.isRead() || selectedItem.isInProgress());
if (selectedItem.getLink() != null) {
menu.findItem(R.id.visit_website_item).setVisible(true);