Make all AsyncTasks return Exceptions
This commit is contained in:
parent
2c52085ab4
commit
8766bfb8b7
8 changed files with 24 additions and 22 deletions
|
@ -806,7 +806,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
||||||
|
|
||||||
OnAsyncTaskCompletedListener onAsyncTaskComplete = new OnAsyncTaskCompletedListener() {
|
OnAsyncTaskCompletedListener onAsyncTaskComplete = new OnAsyncTaskCompletedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAsyncTaskCompleted(Object task_result) {
|
public void onAsyncTaskCompleted(Exception task_result) {
|
||||||
updateCurrentRssView();
|
updateCurrentRssView();
|
||||||
Log.v(TAG, "Finished Download extra items..");
|
Log.v(TAG, "Finished Download extra items..");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.concurrent.Future;
|
||||||
|
|
||||||
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
|
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 Context context;
|
||||||
protected int task_id;
|
protected int task_id;
|
||||||
protected OnAsyncTaskCompletedListener[] listener;
|
protected OnAsyncTaskCompletedListener[] listener;
|
||||||
|
@ -61,7 +61,7 @@ public abstract class AsyncTask_Reader extends AsyncTask<Object, Void, Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object ex) {
|
protected void onPostExecute(Exception ex) {
|
||||||
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
||||||
if(listenerInstance != null)
|
if(listenerInstance != null)
|
||||||
listenerInstance.onAsyncTaskCompleted(ex);
|
listenerInstance.onAsyncTaskCompleted(ex);
|
||||||
|
|
|
@ -23,5 +23,5 @@ package de.luhmer.owncloudnewsreader.reader;
|
||||||
|
|
||||||
|
|
||||||
public interface OnAsyncTaskCompletedListener {
|
public interface OnAsyncTaskCompletedListener {
|
||||||
void onAsyncTaskCompleted(final Object task_result);
|
void onAsyncTaskCompleted(final Exception task_result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object ex) {
|
protected void onPostExecute(Exception ex) {
|
||||||
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
||||||
if(listenerInstance != null)
|
if(listenerInstance != null)
|
||||||
listenerInstance.onAsyncTaskCompleted(ex);
|
listenerInstance.onAsyncTaskCompleted(ex);
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class AsyncTask_GetOldItems extends AsyncTask_Reader {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object ex) {
|
protected void onPostExecute(Exception ex) {
|
||||||
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
||||||
if(listenerInstance != null)
|
if(listenerInstance != null)
|
||||||
listenerInstance.onAsyncTaskCompleted(ex);
|
listenerInstance.onAsyncTaskCompleted(ex);
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Object... params) {
|
protected Exception doInBackground(Object... params) {
|
||||||
List<Boolean> succeeded = new ArrayList<>();
|
boolean succeeded;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
|
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);
|
boolean result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_READ, context);
|
||||||
if(result)
|
if(result)
|
||||||
dbConn.change_readUnreadStateOfItem(itemIds, true);
|
dbConn.change_readUnreadStateOfItem(itemIds, true);
|
||||||
succeeded.add(result);
|
succeeded = result;
|
||||||
|
|
||||||
//Mark as UNREAD
|
//Mark as UNREAD
|
||||||
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnreadRssItems());
|
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnreadRssItems());
|
||||||
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNREAD, context);
|
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNREAD, context);
|
||||||
if(result)
|
if(result)
|
||||||
dbConn.change_readUnreadStateOfItem(itemIds, false);
|
dbConn.change_readUnreadStateOfItem(itemIds, false);
|
||||||
succeeded.add(result);
|
succeeded &= result;
|
||||||
|
|
||||||
//Mark as STARRED
|
//Mark as STARRED
|
||||||
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewStarredRssItems());
|
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewStarredRssItems());
|
||||||
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_STARRED, context);
|
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_STARRED, context);
|
||||||
if(result)
|
if(result)
|
||||||
dbConn.change_starrUnstarrStateOfItem(itemIds, true);
|
dbConn.change_starrUnstarrStateOfItem(itemIds, true);
|
||||||
succeeded.add(result);
|
succeeded &= result;
|
||||||
|
|
||||||
//Mark as UNSTARRED
|
//Mark as UNSTARRED
|
||||||
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnstarredRssItems());
|
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnstarredRssItems());
|
||||||
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNSTARRED, context);
|
result = apiFuture.get().PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNSTARRED, context);
|
||||||
if(result)
|
if(result)
|
||||||
dbConn.change_starrUnstarrStateOfItem(itemIds, false);
|
dbConn.change_starrUnstarrStateOfItem(itemIds, false);
|
||||||
succeeded.add(result);
|
succeeded &= result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
return e;
|
||||||
succeeded.add(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !succeeded.contains(false);
|
Exception e = null;
|
||||||
|
if(!succeeded)
|
||||||
|
e = new Exception("Performing item state change failed");
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object values) {
|
protected void onPostExecute(Exception ex) {
|
||||||
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
|
||||||
if(listenerInstance != null)
|
if(listenerInstance != null)
|
||||||
listenerInstance.onAsyncTaskCompleted(values);
|
listenerInstance.onAsyncTaskCompleted(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
detach();
|
detach();
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class OwnCloud_Reader {
|
||||||
OnAsyncTaskCompletedListener AsyncTask_finished = new OnAsyncTaskCompletedListener() {
|
OnAsyncTaskCompletedListener AsyncTask_finished = new OnAsyncTaskCompletedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAsyncTaskCompleted(Object task_result) {
|
public void onAsyncTaskCompleted(Exception task_result) {
|
||||||
setSyncRunning(false);
|
setSyncRunning(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class OwnCloudSyncService extends Service {
|
||||||
//Sync state of items e.g. read/unread/starred/unstarred
|
//Sync state of items e.g. read/unread/starred/unstarred
|
||||||
private final OnAsyncTaskCompletedListener onAsyncTask_PerformTagExecute = new OnAsyncTaskCompletedListener() {
|
private final OnAsyncTaskCompletedListener onAsyncTask_PerformTagExecute = new OnAsyncTaskCompletedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAsyncTaskCompleted(Object task_result) {
|
public void onAsyncTaskCompleted(Exception task_result) {
|
||||||
syncCompletedLatch = new CountDownLatch(3);
|
syncCompletedLatch = new CountDownLatch(3);
|
||||||
|
|
||||||
OwnCloud_Reader.getInstance().Start_AsyncTask_GetFolder(OwnCloudSyncService.this, onAsyncTaskFinished);
|
OwnCloud_Reader.getInstance().Start_AsyncTask_GetFolder(OwnCloudSyncService.this, onAsyncTaskFinished);
|
||||||
|
@ -134,9 +134,9 @@ public class OwnCloudSyncService extends Service {
|
||||||
private final OnAsyncTaskCompletedListener onAsyncTaskFinished = new OnAsyncTaskCompletedListener() {
|
private final OnAsyncTaskCompletedListener onAsyncTaskFinished = new OnAsyncTaskCompletedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAsyncTaskCompleted(Object task_result) {
|
public void onAsyncTaskCompleted(Exception task_result) {
|
||||||
if(task_result instanceof Exception)
|
if(task_result != null)
|
||||||
ThrowException((Exception) task_result);
|
ThrowException(task_result);
|
||||||
syncCompletedLatch.countDown();
|
syncCompletedLatch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue