return result of state sync

This commit is contained in:
David Luhmer 2019-01-05 09:44:37 +01:00
parent edede10c8c
commit ab1d2a520d
3 changed files with 12 additions and 5 deletions

View file

@ -127,8 +127,8 @@ public class OwnCloudSyncAdapter extends AbstractThreadedSyncAdapter {
public void subscribe(Subscriber<? super Boolean> s) {
Log.v(TAG, "(rssStateSync) subscribe() called with: s = [" + s + "] [" + Thread.currentThread().getName() + "]");
try {
ItemStateSync.PerformItemStateSync(mApi.getAPI(), dbConn);
s.onNext(true);
boolean success = ItemStateSync.PerformItemStateSync(mApi.getAPI(), dbConn);
s.onNext(success);
s.onComplete();
} catch(Exception ex) {
s.onError(ex);

View file

@ -12,31 +12,38 @@ import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
public class ItemStateSync {
public static void PerformItemStateSync(API api, DatabaseConnectionOrm dbConn) throws IOException {
public static boolean PerformItemStateSync(API api, DatabaseConnectionOrm dbConn) throws IOException {
boolean successful;
//Mark as READ
List<String> itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewReadRssItems());
boolean result = PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_READ, dbConn, api);
if(result)
dbConn.change_readUnreadStateOfItem(itemIds, true);
successful = result;
//Mark as UNREAD
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnreadRssItems());
result = PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNREAD, dbConn, api);
if(result)
dbConn.change_readUnreadStateOfItem(itemIds, false);
successful &= result;
//Mark as STARRED
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewStarredRssItems());
result = PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_STARRED, dbConn, api);
if(result)
dbConn.changeStarrUnstarrStateOfItem(itemIds, true);
successful &= result;
//Mark as UNSTARRED
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnstarredRssItems());
result = PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNSTARRED, dbConn, api);
if(result)
dbConn.changeStarrUnstarrStateOfItem(itemIds, false);
successful &= result;
return successful;
}
private static boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag, DatabaseConnectionOrm dbConn, API api) throws IOException {

View file

@ -65,8 +65,8 @@ public class SyncItemStateService extends JobIntentService {
final DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);
try {
ItemStateSync.PerformItemStateSync(mApi.getAPI(), dbConn);
Log.v(TAG, "SyncItemStateService successful");
boolean success = ItemStateSync.PerformItemStateSync(mApi.getAPI(), dbConn);
Log.v(TAG, "SyncItemStateService finished. Success: " + success);
} catch (IOException e) {
e.printStackTrace();
}