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 com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
|
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
|
import de.podfetcher.fragment.FeedItemlistFragment;
|
||||||
import de.podfetcher.fragment.FeedlistFragment;
|
import de.podfetcher.fragment.FeedlistFragment;
|
||||||
|
import de.podfetcher.fragment.UnreadItemlistFragment;
|
||||||
|
|
||||||
public class PodfetcherActivity extends SherlockFragmentActivity {
|
public class PodfetcherActivity extends SherlockFragmentActivity {
|
||||||
private static final String TAG = "PodfetcherActivity";
|
private static final String TAG = "PodfetcherActivity";
|
||||||
|
|
||||||
private FeedlistFragment feedlist;
|
private FeedlistFragment feedlist;
|
||||||
|
FeedItemlistFragment unreadList;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
// Set up tabs
|
// Set up tabs
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||||
|
@ -36,13 +39,14 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
||||||
FeedlistFragment.class));
|
FeedlistFragment.class));
|
||||||
|
|
||||||
actionBar.addTab(tab);
|
actionBar.addTab(tab);
|
||||||
|
|
||||||
tab = actionBar
|
tab = actionBar
|
||||||
.newTab()
|
.newTab()
|
||||||
.setText(getText(R.string.new_label).toString())
|
.setText(getText(R.string.new_label).toString())
|
||||||
.setTabListener(
|
.setTabListener(
|
||||||
new TabListener<FeedlistFragment>(this, getText(
|
new TabListener<UnreadItemlistFragment>(this, getText(
|
||||||
R.string.new_label).toString(),
|
R.string.new_label).toString(),
|
||||||
FeedlistFragment.class));
|
UnreadItemlistFragment.class));
|
||||||
actionBar.addTab(tab);
|
actionBar.addTab(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +58,6 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
||||||
private final String tag;
|
private final String tag;
|
||||||
private final Class<T> fClass;
|
private final Class<T> fClass;
|
||||||
private Fragment fragment;
|
private Fragment fragment;
|
||||||
private boolean attachedOnce = false;
|
|
||||||
|
|
||||||
public TabListener(Activity activity, String tag, Class<T> fClass) {
|
public TabListener(Activity activity, String tag, Class<T> fClass) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
@ -76,10 +79,6 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
fragment = Fragment.instantiate(activity, fClass.getName());
|
fragment = Fragment.instantiate(activity, fClass.getName());
|
||||||
ft.replace(R.id.main_fragment, fragment);
|
ft.replace(R.id.main_fragment, fragment);
|
||||||
attachedOnce = true;
|
|
||||||
} else if (!attachedOnce) {
|
|
||||||
ft.replace(R.id.main_fragment, fragment);
|
|
||||||
attachedOnce = true;
|
|
||||||
} else {
|
} else {
|
||||||
ft.attach(fragment);
|
ft.attach(fragment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,14 @@ import java.util.Date;
|
||||||
* @author daniel
|
* @author daniel
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FeedItem extends FeedComponent{
|
public class FeedItem extends FeedComponent implements Comparable<FeedItem>{
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private String link;
|
private String link;
|
||||||
private Date pubDate;
|
private Date pubDate;
|
||||||
private FeedMedia media;
|
private FeedMedia media;
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
private boolean read;
|
protected boolean read;
|
||||||
|
|
||||||
public FeedItem() {
|
public FeedItem() {
|
||||||
this.read = true;
|
this.read = true;
|
||||||
|
@ -85,8 +85,10 @@ public class FeedItem extends FeedComponent{
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRead(boolean read) {
|
@Override
|
||||||
this.read = read;
|
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<Feed> feeds;
|
||||||
private ArrayList<FeedCategory> categories;
|
private ArrayList<FeedCategory> categories;
|
||||||
|
|
||||||
|
/** Contains all items where 'read' is false */
|
||||||
|
private ArrayList<FeedItem> unreadItems;
|
||||||
private DownloadRequester requester;
|
private DownloadRequester requester;
|
||||||
|
|
||||||
private FeedManager() {
|
private FeedManager() {
|
||||||
feeds = new ArrayList<Feed>();
|
feeds = new ArrayList<Feed>();
|
||||||
categories = new ArrayList<FeedCategory>();
|
categories = new ArrayList<FeedCategory>();
|
||||||
|
unreadItems = new ArrayList<FeedItem>();
|
||||||
requester = DownloadRequester.getInstance();
|
requester = DownloadRequester.getInstance();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,18 +44,20 @@ public class FeedManager {
|
||||||
return singleton;
|
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) {
|
public void playMedia(Context context, FeedMedia media) {
|
||||||
// Start playback Service
|
// Start playback Service
|
||||||
Intent launchIntent = new Intent(context,
|
Intent launchIntent = new Intent(context, PlaybackService.class);
|
||||||
PlaybackService.class);
|
|
||||||
launchIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, media.getId());
|
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);
|
context.startService(launchIntent);
|
||||||
|
|
||||||
// Launch Mediaplayer
|
// Launch Mediaplayer
|
||||||
Intent playerIntent = new Intent(context,
|
Intent playerIntent = new Intent(context, MediaplayerActivity.class);
|
||||||
MediaplayerActivity.class);
|
|
||||||
context.startActivity(playerIntent);
|
context.startActivity(playerIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +77,20 @@ public class FeedManager {
|
||||||
return result;
|
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) {
|
public void refreshAllFeeds(Context context) {
|
||||||
Log.d(TAG, "Refreshing all feeds.");
|
Log.d(TAG, "Refreshing all feeds.");
|
||||||
for (Feed feed : feeds) {
|
for (Feed feed : feeds) {
|
||||||
|
@ -86,8 +106,8 @@ public class FeedManager {
|
||||||
setFeedItem(context, item);
|
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) {
|
public void addFeedItem(Context context, FeedItem item) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
// Search list for feeditem
|
// Search list for feeditem
|
||||||
|
@ -104,7 +124,7 @@ public class FeedManager {
|
||||||
item.id = adapter.setFeedItem(item);
|
item.id = adapter.setFeedItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
public void updateFeed(Context context, Feed newFeed) {
|
public void updateFeed(Context context, Feed newFeed) {
|
||||||
// Look up feed in the feedslist
|
// Look up feed in the feedslist
|
||||||
Feed savedFeed = searchFeedByLink(newFeed.getLink());
|
Feed savedFeed = searchFeedByLink(newFeed.getLink());
|
||||||
|
@ -113,7 +133,7 @@ public class FeedManager {
|
||||||
"Found no existing Feed with title " + newFeed.getTitle()
|
"Found no existing Feed with title " + newFeed.getTitle()
|
||||||
+ ". Adding as new one.");
|
+ ". Adding as new one.");
|
||||||
// Add a new Feed
|
// Add a new Feed
|
||||||
newFeed.getItems().get(0).setRead(false);
|
markItemRead(context, newFeed.getItems().get(0), false);
|
||||||
addNewFeed(context, newFeed);
|
addNewFeed(context, newFeed);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Feed with title " + newFeed.getTitle()
|
Log.d(TAG, "Feed with title " + newFeed.getTitle()
|
||||||
|
@ -125,6 +145,7 @@ public class FeedManager {
|
||||||
if (oldItem == null) {
|
if (oldItem == null) {
|
||||||
// item is new
|
// item is new
|
||||||
savedFeed.getItems().add(item);
|
savedFeed.getItems().add(item);
|
||||||
|
markItemRead(context, item, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
savedFeed.setLastUpdate(newFeed.getLastUpdate());
|
savedFeed.setLastUpdate(newFeed.getLastUpdate());
|
||||||
|
@ -293,10 +314,12 @@ public class FeedManager {
|
||||||
item.setMedia(adapter.getFeedMedia(itemlistCursor
|
item.setMedia(adapter.getFeedMedia(itemlistCursor
|
||||||
.getLong(itemlistCursor
|
.getLong(itemlistCursor
|
||||||
.getColumnIndex(PodDBAdapter.KEY_MEDIA)), item));
|
.getColumnIndex(PodDBAdapter.KEY_MEDIA)), item));
|
||||||
item.setRead((itemlistCursor.getInt(itemlistCursor
|
item.read = (itemlistCursor.getInt(itemlistCursor
|
||||||
.getColumnIndex(PodDBAdapter.KEY_READ)) > 0) ? true
|
.getColumnIndex(PodDBAdapter.KEY_READ)) > 0) ? true
|
||||||
: false);
|
: false;
|
||||||
|
if (!item.read) {
|
||||||
|
unreadItems.add(item);
|
||||||
|
}
|
||||||
items.add(item);
|
items.add(item);
|
||||||
} while (itemlistCursor.moveToNext());
|
} while (itemlistCursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
@ -308,4 +331,10 @@ public class FeedManager {
|
||||||
return feeds;
|
return feeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<FeedItem> getUnreadItems() {
|
||||||
|
return unreadItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,15 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
||||||
private static final String TAG = "FeedItemlistFragment";
|
private static final String TAG = "FeedItemlistFragment";
|
||||||
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
||||||
|
|
||||||
private FeedItemlistAdapter fila;
|
protected FeedItemlistAdapter fila;
|
||||||
private FeedManager manager;
|
protected FeedManager manager;
|
||||||
private DownloadRequester requester;
|
protected DownloadRequester requester;
|
||||||
|
|
||||||
/** The feed which the activity displays */
|
/** The feed which the activity displays */
|
||||||
private ArrayList<FeedItem> items;
|
protected ArrayList<FeedItem> items;
|
||||||
|
|
||||||
private FeedItem selectedItem;
|
protected FeedItem selectedItem;
|
||||||
private ActionMode mActionMode;
|
protected ActionMode mActionMode;
|
||||||
|
|
||||||
public FeedItemlistFragment(ArrayList<FeedItem> items) {
|
public FeedItemlistFragment(ArrayList<FeedItem> items) {
|
||||||
super();
|
super();
|
||||||
|
@ -150,10 +150,10 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
||||||
.getMedia().getDownloadId());
|
.getMedia().getDownloadId());
|
||||||
break;
|
break;
|
||||||
case R.id.mark_read_item:
|
case R.id.mark_read_item:
|
||||||
selectedItem.setRead(true);
|
manager.markItemRead(getSherlockActivity(), selectedItem, true);
|
||||||
break;
|
break;
|
||||||
case R.id.mark_unread_item:
|
case R.id.mark_unread_item:
|
||||||
selectedItem.setRead(false);
|
manager.markItemRead(getSherlockActivity(), selectedItem, false);
|
||||||
break;
|
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