Implemented Queue for FeedItems
This commit is contained in:
parent
2288beb247
commit
8f9344fbe7
@ -6,6 +6,8 @@
|
|||||||
<item android:id="@+id/cancel_download_item" android:icon="@drawable/navigation_cancel" android:title="@string/cancel_download_label" android:visible="false"></item>
|
<item android:id="@+id/cancel_download_item" android:icon="@drawable/navigation_cancel" android:title="@string/cancel_download_label" android:visible="false"></item>
|
||||||
<item android:id="@+id/mark_read_item" android:title="@string/mark_read_label" android:showAsAction="collapseActionView" android:visible="false"></item>
|
<item android:id="@+id/mark_read_item" android:title="@string/mark_read_label" android:showAsAction="collapseActionView" android:visible="false"></item>
|
||||||
<item android:id="@+id/mark_unread_item" android:title="@string/mark_unread_label" android:visible="false" android:showAsAction="collapseActionView"></item>
|
<item android:id="@+id/mark_unread_item" android:title="@string/mark_unread_label" android:visible="false" android:showAsAction="collapseActionView"></item>
|
||||||
|
<item android:id="@+id/add_to_queue_item" android:title="@string/add_to_queue_label" android:visible="false" android:showAsAction="collapseActionView"></item>
|
||||||
|
<item android:id="@+id/remove_from_queue_item" android:title="@string/remove_from_queue_label" android:visible="false" android:showAsAction="collapseActionView"></item>
|
||||||
|
|
||||||
|
|
||||||
</menu>
|
</menu>
|
@ -49,4 +49,6 @@
|
|||||||
<string name="download_error_http_data_error">HTTP Data Error</string>
|
<string name="download_error_http_data_error">HTTP Data Error</string>
|
||||||
<string name="download_error_error_unknown">Unknown Error</string>
|
<string name="download_error_error_unknown">Unknown Error</string>
|
||||||
<string name="show_player_label">Show player</string>
|
<string name="show_player_label">Show player</string>
|
||||||
|
<string name="add_to_queue_label">Add to Queue</string>
|
||||||
|
<string name="remove_from_queue_label">Remove from Queue</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -13,6 +13,9 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.asynctask.DownloadObserver;
|
import de.podfetcher.asynctask.DownloadObserver;
|
||||||
@ -49,14 +52,13 @@ public class ItemviewActivity extends SherlockActivity {
|
|||||||
manager = FeedManager.getInstance();
|
manager = FeedManager.getInstance();
|
||||||
extractFeeditem();
|
extractFeeditem();
|
||||||
populateUI();
|
populateUI();
|
||||||
getDownloadStatus();
|
|
||||||
|
|
||||||
butDownload.setOnClickListener(new View.OnClickListener() {
|
butDownload.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
requester = DownloadRequester.getInstance();
|
requester = DownloadRequester.getInstance();
|
||||||
requester.downloadMedia(v.getContext(), item.getMedia());
|
requester.downloadMedia(v.getContext(), item.getMedia());
|
||||||
getDownloadStatus();
|
//getDownloadStatus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,7 +74,7 @@ public class ItemviewActivity extends SherlockActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (manager.deleteFeedMedia(v.getContext(), item.getMedia())) {
|
if (manager.deleteFeedMedia(v.getContext(), item.getMedia())) {
|
||||||
setNotDownloadedState();
|
//setNotDownloadedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -123,16 +125,16 @@ public class ItemviewActivity extends SherlockActivity {
|
|||||||
webvDescription.loadData(item.getDescription(), "text/html", null);
|
webvDescription.loadData(item.getDescription(), "text/html", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDownloadStatus() {
|
private void getDownloadStatus(Menu menu) {
|
||||||
FeedMedia media = item.getMedia();
|
FeedMedia media = item.getMedia();
|
||||||
if (media.getFile_url() == null) {
|
if (media.getFile_url() == null) {
|
||||||
setNotDownloadedState();
|
setNotDownloadedState(menu);
|
||||||
} else if (media.isDownloaded()) {
|
} else if (media.isDownloaded()) {
|
||||||
setDownloadedState();
|
setDownloadedState(menu);
|
||||||
} else {
|
} else {
|
||||||
// observe
|
// observe
|
||||||
setDownloadingState();
|
setDownloadingState(menu);
|
||||||
downloadObserver.execute(media);
|
//downloadObserver.execute(media);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,26 +149,44 @@ public class ItemviewActivity extends SherlockActivity {
|
|||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
boolean r = getStatusList()[0].isSuccessful();
|
boolean r = getStatusList()[0].isSuccessful();
|
||||||
if (r) {
|
if (r) {
|
||||||
setDownloadedState();
|
//setDownloadedState();
|
||||||
} else {
|
} else {
|
||||||
setNotDownloadedState();
|
//setNotDownloadedState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = new MenuInflater(this);
|
||||||
|
inflater.inflate(R.menu.feeditemlist, menu);
|
||||||
|
getDownloadStatus(menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void setDownloadingState() {
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setDownloadingState(Menu menu) {
|
||||||
|
|
||||||
butDownload.setEnabled(false);
|
butDownload.setEnabled(false);
|
||||||
butPlay.setEnabled(false);
|
butPlay.setEnabled(false);
|
||||||
butRemove.setEnabled(false);
|
butRemove.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDownloadedState() {
|
private void setDownloadedState(Menu menu) {
|
||||||
butDownload.setEnabled(false);
|
butDownload.setEnabled(false);
|
||||||
butPlay.setEnabled(true);
|
butPlay.setEnabled(true);
|
||||||
butRemove.setEnabled(true);
|
butRemove.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNotDownloadedState() {
|
private void setNotDownloadedState(Menu menu) {
|
||||||
butPlay.setEnabled(false);
|
butPlay.setEnabled(false);
|
||||||
butDownload.setEnabled(true);
|
butDownload.setEnabled(true);
|
||||||
butRemove.setEnabled(false);
|
butRemove.setEnabled(false);
|
||||||
|
@ -34,6 +34,9 @@ public class FeedManager {
|
|||||||
|
|
||||||
/** Contains completed Download status entries */
|
/** Contains completed Download status entries */
|
||||||
private ArrayList<DownloadStatus> downloadLog;
|
private ArrayList<DownloadStatus> downloadLog;
|
||||||
|
|
||||||
|
/** Contains the queue of items to be played. */
|
||||||
|
private ArrayList<FeedItem> queue;
|
||||||
|
|
||||||
private DownloadRequester requester;
|
private DownloadRequester requester;
|
||||||
|
|
||||||
@ -43,6 +46,7 @@ public class FeedManager {
|
|||||||
unreadItems = new ArrayList<FeedItem>();
|
unreadItems = new ArrayList<FeedItem>();
|
||||||
requester = DownloadRequester.getInstance();
|
requester = DownloadRequester.getInstance();
|
||||||
downloadLog = new ArrayList<DownloadStatus>();
|
downloadLog = new ArrayList<DownloadStatus>();
|
||||||
|
queue = new ArrayList<FeedItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FeedManager getInstance() {
|
public static FeedManager getInstance() {
|
||||||
@ -141,6 +145,24 @@ public class FeedManager {
|
|||||||
}
|
}
|
||||||
return adapter.setDownloadStatus(status);
|
return adapter.setDownloadStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addQueueItem(Context context, FeedItem item) {
|
||||||
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
queue.add(item);
|
||||||
|
adapter.setQueue(queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeQueueItem(Context context, FeedItem item) {
|
||||||
|
boolean removed = queue.remove(item);
|
||||||
|
if (removed) {
|
||||||
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
adapter.setQueue(queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInQueue(FeedItem item) {
|
||||||
|
return queue.contains(item);
|
||||||
|
}
|
||||||
|
|
||||||
private void addNewFeed(Context context, Feed feed) {
|
private void addNewFeed(Context context, Feed feed) {
|
||||||
feeds.add(feed);
|
feeds.add(feed);
|
||||||
@ -300,7 +322,6 @@ public class FeedManager {
|
|||||||
|
|
||||||
/** Reads the database */
|
/** Reads the database */
|
||||||
public void loadDBData(Context context) {
|
public void loadDBData(Context context) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
|
||||||
updateArrays(context);
|
updateArrays(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,6 +330,7 @@ public class FeedManager {
|
|||||||
categories.clear();
|
categories.clear();
|
||||||
extractFeedlistFromCursor(context);
|
extractFeedlistFromCursor(context);
|
||||||
extractDownloadLogFromCursor(context);
|
extractDownloadLogFromCursor(context);
|
||||||
|
extractQueueFromCursor(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractFeedlistFromCursor(Context context) {
|
private void extractFeedlistFromCursor(Context context) {
|
||||||
@ -423,6 +445,20 @@ public class FeedManager {
|
|||||||
} while (logCursor.moveToNext());
|
} while (logCursor.moveToNext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void extractQueueFromCursor(Context context) {
|
||||||
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
adapter.open();
|
||||||
|
Cursor cursor = adapter.getQueueCursor();
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
int index = cursor.getInt(cursor.getColumnIndex(PodDBAdapter.KEY_ID));
|
||||||
|
Feed feed = getFeed(cursor.getColumnIndex(PodDBAdapter.KEY_FEED));
|
||||||
|
FeedItem item = getFeedItem(cursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM), feed);
|
||||||
|
queue.add(index, item);
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Feed> getFeeds() {
|
public ArrayList<Feed> getFeeds() {
|
||||||
return feeds;
|
return feeds;
|
||||||
|
@ -125,7 +125,13 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
|||||||
} else {
|
} else {
|
||||||
menu.findItem(R.id.mark_read_item).setVisible(true);
|
menu.findItem(R.id.mark_read_item).setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (manager.isInQueue(selectedItem)) {
|
||||||
|
menu.findItem(R.id.remove_from_queue_item).setVisible(true);
|
||||||
|
} else {
|
||||||
|
menu.findItem(R.id.add_to_queue_item).setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -155,7 +161,12 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
|||||||
case R.id.mark_unread_item:
|
case R.id.mark_unread_item:
|
||||||
manager.markItemRead(getSherlockActivity(), selectedItem, false);
|
manager.markItemRead(getSherlockActivity(), selectedItem, false);
|
||||||
break;
|
break;
|
||||||
|
case R.id.add_to_queue_item:
|
||||||
|
manager.addQueueItem(getSherlockActivity(), selectedItem);
|
||||||
|
break;
|
||||||
|
case R.id.remove_from_queue_item:
|
||||||
|
manager.removeQueueItem(getSherlockActivity(), selectedItem);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
fila.notifyDataSetChanged();
|
fila.notifyDataSetChanged();
|
||||||
mode.finish();
|
mode.finish();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.podfetcher.storage;
|
package de.podfetcher.storage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.podfetcher.asynctask.DownloadStatus;
|
import de.podfetcher.asynctask.DownloadStatus;
|
||||||
import de.podfetcher.feed.Feed;
|
import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.feed.FeedCategory;
|
import de.podfetcher.feed.FeedCategory;
|
||||||
@ -48,6 +50,8 @@ public class PodDBAdapter {
|
|||||||
public static final String KEY_SUCCESSFUL = "successful";
|
public static final String KEY_SUCCESSFUL = "successful";
|
||||||
public static final String KEY_FEEDFILETYPE = "feedfile_type";
|
public static final String KEY_FEEDFILETYPE = "feedfile_type";
|
||||||
public static final String KEY_COMPLETION_DATE = "completion_date";
|
public static final String KEY_COMPLETION_DATE = "completion_date";
|
||||||
|
public static final String KEY_FEEDITEM = "feeditem";
|
||||||
|
|
||||||
// Table names
|
// Table names
|
||||||
public static final String TABLE_NAME_FEEDS = "Feeds";
|
public static final String TABLE_NAME_FEEDS = "Feeds";
|
||||||
public static final String TABLE_NAME_FEED_ITEMS = "FeedItems";
|
public static final String TABLE_NAME_FEED_ITEMS = "FeedItems";
|
||||||
@ -55,6 +59,7 @@ public class PodDBAdapter {
|
|||||||
public static final String TABLE_NAME_FEED_IMAGES = "FeedImages";
|
public static final String TABLE_NAME_FEED_IMAGES = "FeedImages";
|
||||||
public static final String TABLE_NAME_FEED_MEDIA = "FeedMedia";
|
public static final String TABLE_NAME_FEED_MEDIA = "FeedMedia";
|
||||||
public static final String TABLE_NAME_DOWNLOAD_LOG = "DownloadLog";
|
public static final String TABLE_NAME_DOWNLOAD_LOG = "DownloadLog";
|
||||||
|
public static final String TABLE_NAME_QUEUE = "Queue";
|
||||||
|
|
||||||
// SQL Statements for creating new tables
|
// SQL Statements for creating new tables
|
||||||
private static final String TABLE_PRIMARY_KEY = KEY_ID
|
private static final String TABLE_PRIMARY_KEY = KEY_ID
|
||||||
@ -92,6 +97,11 @@ public class PodDBAdapter {
|
|||||||
+ " INTEGER," + KEY_FEEDFILETYPE + " INTEGER," + KEY_REASON
|
+ " INTEGER," + KEY_FEEDFILETYPE + " INTEGER," + KEY_REASON
|
||||||
+ " INTEGER," + KEY_SUCCESSFUL + " INTEGER," + KEY_COMPLETION_DATE
|
+ " INTEGER," + KEY_SUCCESSFUL + " INTEGER," + KEY_COMPLETION_DATE
|
||||||
+ " INTEGER)";
|
+ " INTEGER)";
|
||||||
|
|
||||||
|
private static final String CREATE_TABLE_QUEUE = "CREATE TABLE "
|
||||||
|
+ TABLE_NAME_QUEUE + "(" + KEY_ID + " INTEGER PRIMARY KEY,"
|
||||||
|
+ KEY_FEEDITEM + " INTEGER,"
|
||||||
|
+ KEY_FEED + " INTEGER)";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for storing download status entries to determine the type of the
|
* Used for storing download status entries to determine the type of the
|
||||||
@ -115,6 +125,7 @@ public class PodDBAdapter {
|
|||||||
try {
|
try {
|
||||||
db = helper.getWritableDatabase();
|
db = helper.getWritableDatabase();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
db = helper.getReadableDatabase();
|
db = helper.getReadableDatabase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,6 +305,20 @@ public class PodDBAdapter {
|
|||||||
return status.getId();
|
return status.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setQueue(ArrayList<FeedItem> queue) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
open();
|
||||||
|
db.delete(TABLE_NAME_QUEUE, null, null);
|
||||||
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
|
FeedItem item = queue.get(i);
|
||||||
|
values.put(KEY_ID, i);
|
||||||
|
values.put(KEY_FEEDITEM, item.getId());
|
||||||
|
values.put(KEY_FEED, item.getFeed().getId());
|
||||||
|
db.insertWithOnConflict(TABLE_NAME_QUEUE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
public void removeFeedMedia(FeedMedia media) {
|
public void removeFeedMedia(FeedMedia media) {
|
||||||
open();
|
open();
|
||||||
db.delete(TABLE_NAME_FEED_MEDIA, KEY_ID + "=?", new String[] {String.valueOf(media.getId())});
|
db.delete(TABLE_NAME_FEED_MEDIA, KEY_ID + "=?", new String[] {String.valueOf(media.getId())});
|
||||||
@ -411,6 +436,12 @@ public class PodDBAdapter {
|
|||||||
null, null);
|
null, null);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Cursor getQueueCursor() {
|
||||||
|
open();
|
||||||
|
Cursor c = db.query(TABLE_NAME_QUEUE, null, null, null, null, null, null);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a FeedMedia object from the Database.
|
* Get a FeedMedia object from the Database.
|
||||||
@ -491,6 +522,7 @@ public class PodDBAdapter {
|
|||||||
db.execSQL(CREATE_TABLE_FEED_IMAGES);
|
db.execSQL(CREATE_TABLE_FEED_IMAGES);
|
||||||
db.execSQL(CREATE_TABLE_FEED_MEDIA);
|
db.execSQL(CREATE_TABLE_FEED_MEDIA);
|
||||||
db.execSQL(CREATE_TABLE_DOWNLOAD_LOG);
|
db.execSQL(CREATE_TABLE_DOWNLOAD_LOG);
|
||||||
|
db.execSQL(CREATE_TABLE_QUEUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user