Make all AsyncTasks return Exceptions

This commit is contained in:
Daniel Schaal 2015-10-03 07:53:51 +02:00
parent 2c52085ab4
commit 8766bfb8b7
8 changed files with 24 additions and 22 deletions

View file

@ -806,7 +806,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
OnAsyncTaskCompletedListener onAsyncTaskComplete = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(Object task_result) {
public void onAsyncTaskCompleted(Exception task_result) {
updateCurrentRssView();
Log.v(TAG, "Finished Download extra items..");
}

View file

@ -29,7 +29,7 @@ import java.util.concurrent.Future;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
public abstract class AsyncTask_Reader extends AsyncTask<Object, Void, Object> {
public abstract class AsyncTask_Reader extends AsyncTask<Object, Void, Exception> {
protected Context context;
protected int task_id;
protected OnAsyncTaskCompletedListener[] listener;
@ -61,7 +61,7 @@ public abstract class AsyncTask_Reader extends AsyncTask<Object, Void, Object> {
}
@Override
protected void onPostExecute(Object ex) {
protected void onPostExecute(Exception ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(ex);

View file

@ -23,5 +23,5 @@ package de.luhmer.owncloudnewsreader.reader;
public interface OnAsyncTaskCompletedListener {
void onAsyncTaskCompleted(final Object task_result);
void onAsyncTaskCompleted(final Exception task_result);
}

View file

@ -128,7 +128,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
}
@Override
protected void onPostExecute(Object ex) {
protected void onPostExecute(Exception ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(ex);

View file

@ -101,7 +101,7 @@ public class AsyncTask_GetOldItems extends AsyncTask_Reader {
}
@Override
protected void onPostExecute(Object ex) {
protected void onPostExecute(Exception ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(ex);

View file

@ -39,8 +39,8 @@ public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
}
@Override
protected Boolean doInBackground(Object... params) {
List<Boolean> succeeded = new ArrayList<>();
protected Exception doInBackground(Object... params) {
boolean succeeded;
try {
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
@ -50,41 +50,43 @@ public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
boolean result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_READ, context);
if(result)
dbConn.change_readUnreadStateOfItem(itemIds, true);
succeeded.add(result);
succeeded = result;
//Mark as UNREAD
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnreadRssItems());
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNREAD, context);
if(result)
dbConn.change_readUnreadStateOfItem(itemIds, false);
succeeded.add(result);
succeeded &= result;
//Mark as STARRED
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewStarredRssItems());
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_STARRED, context);
if(result)
dbConn.change_starrUnstarrStateOfItem(itemIds, true);
succeeded.add(result);
succeeded &= result;
//Mark as UNSTARRED
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnstarredRssItems());
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNSTARRED, context);
if(result)
dbConn.change_starrUnstarrStateOfItem(itemIds, false);
succeeded.add(result);
succeeded &= result;
} catch (Exception e) {
e.printStackTrace();
succeeded.add(false);
return e;
}
return !succeeded.contains(false);
Exception e = null;
if(!succeeded)
e = new Exception("Performing item state change failed");
return e;
}
@Override
protected void onPostExecute(Object values) {
protected void onPostExecute(Exception ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(values);
listenerInstance.onAsyncTaskCompleted(ex);
}
detach();

View file

@ -107,7 +107,7 @@ public class OwnCloud_Reader {
OnAsyncTaskCompletedListener AsyncTask_finished = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(Object task_result) {
public void onAsyncTaskCompleted(Exception task_result) {
setSyncRunning(false);
}
};

View file

@ -104,7 +104,7 @@ public class OwnCloudSyncService extends Service {
//Sync state of items e.g. read/unread/starred/unstarred
private final OnAsyncTaskCompletedListener onAsyncTask_PerformTagExecute = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(Object task_result) {
public void onAsyncTaskCompleted(Exception task_result) {
syncCompletedLatch = new CountDownLatch(3);
OwnCloud_Reader.getInstance().Start_AsyncTask_GetFolder(OwnCloudSyncService.this, onAsyncTaskFinished);
@ -134,9 +134,9 @@ public class OwnCloudSyncService extends Service {
private final OnAsyncTaskCompletedListener onAsyncTaskFinished = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(Object task_result) {
if(task_result instanceof Exception)
ThrowException((Exception) task_result);
public void onAsyncTaskCompleted(Exception task_result) {
if(task_result != null)
ThrowException(task_result);
syncCompletedLatch.countDown();
}
};