X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/d25af7eea587e0112d3baeac6faf3c8321439aae..e4bc3bdadc47c01e88dd1de94a4666d3753ee90e:/src/com/owncloud/android/syncadapter/FileSyncAdapter.java diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 3763908a..e977e41c 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -31,6 +31,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.operations.RemoteOperationResult; import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UpdateOCVersionOperation; +import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import android.accounts.Account; import android.app.Notification; @@ -65,6 +66,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { private int mFailedResultsCounter; private RemoteOperationResult mLastFailedResult; private SyncResult mSyncResult; + private int mConflictsFound; + private int mFailsInFavouritesFound; public FileSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); @@ -82,8 +85,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false); mFailedResultsCounter = 0; mLastFailedResult = null; + mConflictsFound = 0; + mFailsInFavouritesFound = 0; mSyncResult = syncResult; - + mSyncResult.fullSyncRequested = false; + mSyncResult.delayUntil = 60*60*24; // sync after 24h + this.setAccount(account); this.setContentProvider(provider); this.setStorageManager(new FileDataStorageManager(account, getContentProvider())); @@ -120,13 +127,15 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { /// notify the user about the failure of MANUAL synchronization notifyFailedSynchronization(); + + } else if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { + notifyFailsInFavourites(); } sendStickyBroadcast(false, null, mLastFailedResult); // message to signal the end to the UI } } - - + /** * Called by system SyncManager when a synchronization is required to be cancelled. @@ -180,7 +189,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { // synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess sendStickyBroadcast(true, remotePath, null); - if (result.isSuccess()) { + if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) { + + if (result.getCode() == ResultCode.SYNC_CONFLICT) { + mConflictsFound += synchFolderOp.getConflictsFound(); + mFailsInFavouritesFound += synchFolderOp.getFailsInFavouritesFound(); + } // synchronize children folders List children = synchFolderOp.getChildren(); fetchChildren(children); // beware of the 'hidden' recursion here! @@ -194,7 +208,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { } else if (result.getException() instanceof IOException) { mSyncResult.stats.numIoExceptions++; - } mFailedResultsCounter++; mLastFailedResult = result; @@ -273,6 +286,35 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_ticker, notification); } - + + /** + * Notifies the user about conflicts and strange fails when trying to synchronize the contents of favourite files. + * + * By now, we won't consider a failed synchronization. + */ + private void notifyFailsInFavourites() { + if (mFailedResultsCounter > 0) { + Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_in_favourites_ticker), System.currentTimeMillis()); + notification.flags |= Notification.FLAG_AUTO_CANCEL; + // TODO put something smart in the contentIntent below + notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0); + notification.setLatestEventInfo(getContext().getApplicationContext(), + getContext().getString(R.string.sync_fail_in_favourites_ticker), + String.format(getContext().getString(R.string.sync_fail_in_favourites_content), mFailedResultsCounter + mConflictsFound, mConflictsFound), + notification.contentIntent); + ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_in_favourites_ticker, notification); + + } else { + Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_conflicts_in_favourites_ticker), System.currentTimeMillis()); + notification.flags |= Notification.FLAG_AUTO_CANCEL; + // TODO put something smart in the contentIntent below + notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0); + notification.setLatestEventInfo(getContext().getApplicationContext(), + getContext().getString(R.string.sync_conflicts_in_favourites_ticker), + String.format(getContext().getString(R.string.sync_conflicts_in_favourites_content), mConflictsFound), + notification.contentIntent); + ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_conflicts_in_favourites_ticker, notification); + } + } }