Added list which shows unread items
This commit is contained in:
parent
c2542c6f92
commit
14845e9a42
|
@ -10,18 +10,21 @@ import com.actionbarsherlock.app.ActionBar.Tab;
|
|||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
|
||||
import de.podfetcher.R;
|
||||
import de.podfetcher.fragment.FeedItemlistFragment;
|
||||
import de.podfetcher.fragment.FeedlistFragment;
|
||||
import de.podfetcher.fragment.UnreadItemlistFragment;
|
||||
|
||||
public class PodfetcherActivity extends SherlockFragmentActivity {
|
||||
private static final String TAG = "PodfetcherActivity";
|
||||
|
||||
private FeedlistFragment feedlist;
|
||||
FeedItemlistFragment unreadList;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
// Set up tabs
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
|
@ -36,13 +39,14 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
|||
FeedlistFragment.class));
|
||||
|
||||
actionBar.addTab(tab);
|
||||
|
||||
tab = actionBar
|
||||
.newTab()
|
||||
.setText(getText(R.string.new_label).toString())
|
||||
.setTabListener(
|
||||
new TabListener<FeedlistFragment>(this, getText(
|
||||
new TabListener<UnreadItemlistFragment>(this, getText(
|
||||
R.string.new_label).toString(),
|
||||
FeedlistFragment.class));
|
||||
UnreadItemlistFragment.class));
|
||||
actionBar.addTab(tab);
|
||||
}
|
||||
|
||||
|
@ -54,7 +58,6 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
|||
private final String tag;
|
||||
private final Class<T> fClass;
|
||||
private Fragment fragment;
|
||||
private boolean attachedOnce = false;
|
||||
|
||||
public TabListener(Activity activity, String tag, Class<T> fClass) {
|
||||
this.activity = activity;
|
||||
|
@ -76,10 +79,6 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
|||
if (fragment == null) {
|
||||
fragment = Fragment.instantiate(activity, fClass.getName());
|
||||
ft.replace(R.id.main_fragment, fragment);
|
||||
attachedOnce = true;
|
||||
} else if (!attachedOnce) {
|
||||
ft.replace(R.id.main_fragment, fragment);
|
||||
attachedOnce = true;
|
||||
} else {
|
||||
ft.attach(fragment);
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ import java.util.Date;
|
|||
* @author daniel
|
||||
*
|
||||
*/
|
||||
public class FeedItem extends FeedComponent{
|
||||
public class FeedItem extends FeedComponent implements Comparable<FeedItem>{
|
||||
private String title;
|
||||
private String description;
|
||||
private String link;
|
||||
private Date pubDate;
|
||||
private FeedMedia media;
|
||||
private Feed feed;
|
||||
private boolean read;
|
||||
protected boolean read;
|
||||
|
||||
public FeedItem() {
|
||||
this.read = true;
|
||||
|
@ -85,8 +85,10 @@ public class FeedItem extends FeedComponent{
|
|||
return read;
|
||||
}
|
||||
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
@Override
|
||||
public int compareTo(FeedItem another) {
|
||||
long diff = pubDate.getTime() - another.getPubDate().getTime();
|
||||
return (int) Math.signum(diff);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package de.podfetcher.feed;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/** Compares the pubDate of two FeedItems */
|
||||
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
|
||||
|
||||
@Override
|
||||
public int compare(FeedItem lhs, FeedItem rhs) {
|
||||
long diff = lhs.getPubDate().getTime() - rhs.getPubDate().getTime();
|
||||
return (int) Math.signum(diff);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,11 +24,15 @@ public class FeedManager {
|
|||
|
||||
private ArrayList<Feed> feeds;
|
||||
private ArrayList<FeedCategory> categories;
|
||||
|
||||
/** Contains all items where 'read' is false */
|
||||
private ArrayList<FeedItem> unreadItems;
|
||||
private DownloadRequester requester;
|
||||
|
||||
private FeedManager() {
|
||||
feeds = new ArrayList<Feed>();
|
||||
categories = new ArrayList<FeedCategory>();
|
||||
unreadItems = new ArrayList<FeedItem>();
|
||||
requester = DownloadRequester.getInstance();
|
||||
|
||||
}
|
||||
|
@ -40,18 +44,20 @@ public class FeedManager {
|
|||
return singleton;
|
||||
}
|
||||
|
||||
/** Play FeedMedia and start the playback service + launch Mediaplayer Activity. */
|
||||
/**
|
||||
* Play FeedMedia and start the playback service + launch Mediaplayer
|
||||
* Activity.
|
||||
*/
|
||||
public void playMedia(Context context, FeedMedia media) {
|
||||
// Start playback Service
|
||||
Intent launchIntent = new Intent(context,
|
||||
PlaybackService.class);
|
||||
Intent launchIntent = new Intent(context, PlaybackService.class);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, media.getId());
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_FEED_ID, media.getItem().getFeed().getId());
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_FEED_ID, media.getItem()
|
||||
.getFeed().getId());
|
||||
context.startService(launchIntent);
|
||||
|
||||
// Launch Mediaplayer
|
||||
Intent playerIntent = new Intent(context,
|
||||
MediaplayerActivity.class);
|
||||
Intent playerIntent = new Intent(context, MediaplayerActivity.class);
|
||||
context.startActivity(playerIntent);
|
||||
}
|
||||
|
||||
|
@ -71,6 +77,20 @@ public class FeedManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 'read'-attribute of a FeedItem. Should be used by all Classes
|
||||
* instead of the setters of FeedItem.
|
||||
*/
|
||||
public void markItemRead(Context context, FeedItem item, boolean read) {
|
||||
item.read = read;
|
||||
setFeedItem(context, item);
|
||||
if (read == true) {
|
||||
unreadItems.remove(item);
|
||||
} else {
|
||||
unreadItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshAllFeeds(Context context) {
|
||||
Log.d(TAG, "Refreshing all feeds.");
|
||||
for (Feed feed : feeds) {
|
||||
|
@ -86,8 +106,8 @@ public class FeedManager {
|
|||
setFeedItem(context, item);
|
||||
}
|
||||
}
|
||||
/* TODO Decide if still useful
|
||||
|
||||
/** Adds a new Feeditem if its not in the list */
|
||||
public void addFeedItem(Context context, FeedItem item) {
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
// Search list for feeditem
|
||||
|
@ -104,7 +124,7 @@ public class FeedManager {
|
|||
item.id = adapter.setFeedItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
public void updateFeed(Context context, Feed newFeed) {
|
||||
// Look up feed in the feedslist
|
||||
Feed savedFeed = searchFeedByLink(newFeed.getLink());
|
||||
|
@ -113,7 +133,7 @@ public class FeedManager {
|
|||
"Found no existing Feed with title " + newFeed.getTitle()
|
||||
+ ". Adding as new one.");
|
||||
// Add a new Feed
|
||||
newFeed.getItems().get(0).setRead(false);
|
||||
markItemRead(context, newFeed.getItems().get(0), false);
|
||||
addNewFeed(context, newFeed);
|
||||
} else {
|
||||
Log.d(TAG, "Feed with title " + newFeed.getTitle()
|
||||
|
@ -125,6 +145,7 @@ public class FeedManager {
|
|||
if (oldItem == null) {
|
||||
// item is new
|
||||
savedFeed.getItems().add(item);
|
||||
markItemRead(context, item, false);
|
||||
}
|
||||
}
|
||||
savedFeed.setLastUpdate(newFeed.getLastUpdate());
|
||||
|
@ -293,10 +314,12 @@ public class FeedManager {
|
|||
item.setMedia(adapter.getFeedMedia(itemlistCursor
|
||||
.getLong(itemlistCursor
|
||||
.getColumnIndex(PodDBAdapter.KEY_MEDIA)), item));
|
||||
item.setRead((itemlistCursor.getInt(itemlistCursor
|
||||
item.read = (itemlistCursor.getInt(itemlistCursor
|
||||
.getColumnIndex(PodDBAdapter.KEY_READ)) > 0) ? true
|
||||
: false);
|
||||
|
||||
: false;
|
||||
if (!item.read) {
|
||||
unreadItems.add(item);
|
||||
}
|
||||
items.add(item);
|
||||
} while (itemlistCursor.moveToNext());
|
||||
}
|
||||
|
@ -308,4 +331,10 @@ public class FeedManager {
|
|||
return feeds;
|
||||
}
|
||||
|
||||
public ArrayList<FeedItem> getUnreadItems() {
|
||||
return unreadItems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,15 +26,15 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
|||
private static final String TAG = "FeedItemlistFragment";
|
||||
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
||||
|
||||
private FeedItemlistAdapter fila;
|
||||
private FeedManager manager;
|
||||
private DownloadRequester requester;
|
||||
protected FeedItemlistAdapter fila;
|
||||
protected FeedManager manager;
|
||||
protected DownloadRequester requester;
|
||||
|
||||
/** The feed which the activity displays */
|
||||
private ArrayList<FeedItem> items;
|
||||
protected ArrayList<FeedItem> items;
|
||||
|
||||
private FeedItem selectedItem;
|
||||
private ActionMode mActionMode;
|
||||
protected FeedItem selectedItem;
|
||||
protected ActionMode mActionMode;
|
||||
|
||||
public FeedItemlistFragment(ArrayList<FeedItem> items) {
|
||||
super();
|
||||
|
@ -150,10 +150,10 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
|||
.getMedia().getDownloadId());
|
||||
break;
|
||||
case R.id.mark_read_item:
|
||||
selectedItem.setRead(true);
|
||||
manager.markItemRead(getSherlockActivity(), selectedItem, true);
|
||||
break;
|
||||
case R.id.mark_unread_item:
|
||||
selectedItem.setRead(false);
|
||||
manager.markItemRead(getSherlockActivity(), selectedItem, false);
|
||||
break;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package de.podfetcher.fragment;
|
||||
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
|
||||
/** Contains all unread items. */
|
||||
public class UnreadItemlistFragment extends FeedItemlistFragment {
|
||||
|
||||
public UnreadItemlistFragment() {
|
||||
super(FeedManager.getInstance().getUnreadItems());
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue