use of de.danoeh.antennapod.core.util.flattr.FlattrThing in project AntennaPod by AntennaPod.
the class DBReader method getFlattrQueue.
/**
* Returns the flattr queue as a List of FlattrThings. The list consists of Feeds and FeedItems.
*
* @return The flattr queue as a List.
*/
public static List<FlattrThing> getFlattrQueue() {
Log.d(TAG, "getFlattrQueue() called with: " + "");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
List<FlattrThing> result = new ArrayList<>();
// load feeds
Cursor feedCursor = adapter.getFeedsInFlattrQueueCursor();
if (feedCursor.moveToFirst()) {
do {
result.add(extractFeedFromCursorRow(adapter, feedCursor));
} while (feedCursor.moveToNext());
}
feedCursor.close();
//load feed items
Cursor feedItemCursor = adapter.getFeedItemsInFlattrQueueCursor();
result.addAll(extractItemlistFromCursor(adapter, feedItemCursor));
feedItemCursor.close();
adapter.close();
Log.d(TAG, "Returning flattrQueueIterator for queue with " + result.size() + " items.");
return result;
}
use of de.danoeh.antennapod.core.util.flattr.FlattrThing in project AntennaPod by AntennaPod.
the class FlattrClickWorker method doInBackground.
@Override
protected ExitCode doInBackground(Void... params) {
if (!FlattrUtils.hasToken()) {
return ExitCode.NO_TOKEN;
}
if (!NetworkUtils.networkAvailable()) {
return ExitCode.NO_NETWORK;
}
final List<FlattrThing> flattrQueue = DBReader.getFlattrQueue();
if (extraFlattrThing != null) {
flattrQueue.add(extraFlattrThing);
} else if (flattrQueue.size() == 1) {
// if only one item is flattrd, the report can specifically mentioned that this item has failed
extraFlattrThing = flattrQueue.get(0);
}
if (flattrQueue.isEmpty()) {
return ExitCode.NO_THINGS;
}
List<Future<?>> dbFutures = new LinkedList<>();
for (FlattrThing thing : flattrQueue) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Processing " + thing.getTitle());
try {
// pop from queue to prevent unflattrable things from getting stuck in flattr queue infinitely
thing.getFlattrStatus().setUnflattred();
FlattrUtils.clickUrl(context, thing.getPaymentLink());
thing.getFlattrStatus().setFlattred();
publishProgress(R.string.flattr_click_success);
countSuccess.incrementAndGet();
} catch (FlattrException e) {
e.printStackTrace();
int failed = countFailed.incrementAndGet();
if (failed == 1) {
exception = e;
}
}
Future<?> f = DBWriter.setFlattredStatus(context, thing, false);
if (f != null) {
dbFutures.add(f);
}
}
for (Future<?> f : dbFutures) {
try {
f.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
return ExitCode.EXIT_NORMAL;
}
Aggregations