From: David A. Velasco Date: Thu, 20 Aug 2015 08:44:19 +0000 (+0200) Subject: Persist conflicts in local database and show with an icon in the list of files X-Git-Tag: oc-android-1.9^2~37^2~17 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e6c1454458419ff0c47c64fac3d11ebc158cccc8 Persist conflicts in local database and show with an icon in the list of files --- diff --git a/res/drawable/conflict_file_indicator.png b/res/drawable/conflict_file_indicator.png new file mode 100644 index 00000000..fd580caf Binary files /dev/null and b/res/drawable/conflict_file_indicator.png differ diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 29a11c42..ce3510d3 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -204,7 +204,8 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading()); - + cv.put(ProviderTableMeta.FILE_IN_CONFLICT, file.isInConflict()); + boolean sameRemotePath = fileExists(file.getRemotePath()); if (sameRemotePath || fileExists(file.getFileId())) { // for renamed files; no more delete and create @@ -313,6 +314,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading()); + cv.put(ProviderTableMeta.FILE_IN_CONFLICT, file.isInConflict()); boolean existsByPath = fileExists(file.getRemotePath()); if (existsByPath || fileExists(file.getFileId())) { @@ -942,7 +944,9 @@ public class FileDataStorageManager { c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false); file.setDownloading(c.getInt( c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false); - + file.setInConflict(c.getInt( + c.getColumnIndex(ProviderTableMeta.FILE_IN_CONFLICT)) == 1 ? true : false); + } return file; } @@ -1310,6 +1314,10 @@ public class FileDataStorageManager { ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading() ? 1 : 0 ); + cv.put( + ProviderTableMeta.FILE_IN_CONFLICT, + file.isInConflict() ? 1 : 0 + ); boolean existsByPath = fileExists(file.getRemotePath()); if (existsByPath || fileExists(file.getFileId())) { @@ -1578,4 +1586,27 @@ public class FileDataStorageManager { } + public void saveConflict(long fileId, boolean inConflict) { + ContentValues cv = new ContentValues(); + cv.put(ProviderTableMeta.FILE_IN_CONFLICT, inConflict); + if (getContentResolver() != null) { + getContentResolver().update( + ProviderTableMeta.CONTENT_URI_FILE, + cv, + ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(fileId)} + ); + } else { + try { + getContentProviderClient().update( + ProviderTableMeta.CONTENT_URI_FILE, + cv, + ProviderTableMeta._ID + "=?", + new String[]{String.valueOf(fileId)} + ); + } catch (RemoteException e) { + Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage()); + } + } + } } diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index 39666dfe..cef849f8 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -74,6 +74,8 @@ public class OCFile implements Parcelable, Comparable { private boolean mIsDownloading; + private boolean mInConflict; + /** * Create new {@link OCFile} with given path. @@ -115,8 +117,9 @@ public class OCFile implements Parcelable, Comparable { mPublicLink = source.readString(); mPermissions = source.readString(); mRemoteId = source.readString(); - mNeedsUpdateThumbnail = source.readInt() == 0; - mIsDownloading = source.readInt() == 0; + mNeedsUpdateThumbnail = source.readInt() == 1; + mIsDownloading = source.readInt() == 1; + mInConflict = source.readInt() == 1; } @@ -142,6 +145,7 @@ public class OCFile implements Parcelable, Comparable { dest.writeString(mRemoteId); dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0); dest.writeInt(mIsDownloading ? 1 : 0); + dest.writeInt(mInConflict ? 1 : 0); } /** @@ -357,6 +361,7 @@ public class OCFile implements Parcelable, Comparable { mRemoteId = null; mNeedsUpdateThumbnail = false; mIsDownloading = false; + mInConflict = false; } /** @@ -597,9 +602,11 @@ public class OCFile implements Parcelable, Comparable { this.mIsDownloading = isDownloading; } - public boolean isSynchronizing() { - // TODO real implementation - return false; + public boolean isInConflict() { + return mInConflict; } + public void setInConflict(boolean inConflict) { + mInConflict = inConflict; + } } diff --git a/src/com/owncloud/android/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index 25e8fbd1..7db74f05 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -31,7 +31,7 @@ import com.owncloud.android.MainApp; public class ProviderMeta { public static final String DB_NAME = "filelist"; - public static final int DB_VERSION = 10; + public static final int DB_VERSION = 11; private ProviderMeta() { } @@ -72,6 +72,7 @@ public class ProviderMeta { public static final String FILE_REMOTE_ID = "remote_id"; public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail"; public static final String FILE_IS_DOWNLOADING= "is_downloading"; + public static final String FILE_IN_CONFLICT = "in_conflict"; public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME + " collate nocase asc"; @@ -94,7 +95,7 @@ public class ProviderMeta { public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE + " collate nocase asc"; - + } } diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index f0ba3d51..cf5bccd6 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -354,50 +354,55 @@ public class RefreshFolderOperation extends RemoteOperation { } // loop to update every child - OCFile remoteFile = null, localFile = null; + OCFile remoteFile = null, localFile = null, updatedFile = null; + RemoteFile r; for (int i=1; i mLocalFile.getLastSyncDateForData() ); - Log_OC.d(TAG, "TOKENs checked to SYNC " + mRemotePath ); - Log_OC.d(TAG, " server#modificationTimestamp " + mServerFile.getModificationTimestamp()); - Log_OC.d(TAG, " local#modificationTimestampAtLastSyncForData " + mServerFile.getModificationTimestampAtLastSyncForData()); - Log_OC.d(TAG, " local#modificationTimestamp " + mLocalFile.getLocalModificationTimestamp()); - Log_OC.d(TAG, " local#lastSyncDateForData " + mLocalFile.getLastSyncDateForData()); - /// decide action to perform depending upon changes //if (!mLocalFile.getEtag().isEmpty() && localChanged && serverChanged) { if (localChanged && serverChanged) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); + getStorageManager().saveConflict(mLocalFile.getFileId(), true); } else if (localChanged) { if (mSyncFileContents && mAllowUploads) { @@ -257,6 +252,7 @@ public class SynchronizeFileOperation extends SyncOperation { mServerFile.setLastSyncDateForData(mLocalFile.getLastSyncDateForData()); mServerFile.setStoragePath(mLocalFile.getStoragePath()); mServerFile.setParentId(mLocalFile.getParentId()); + mServerFile.setEtag(mLocalFile.getEtag()); getStorageManager().saveFile(mServerFile); } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 82ce3132..05962324 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -302,47 +302,52 @@ public class SynchronizeFolderOperation extends SyncOperation { } // loop to synchronize every child - OCFile remoteFile = null, localFile = null; + OCFile remoteFile = null, localFile = null, updatedFile = null; + RemoteFile r; for (int i=1; i= 11) { + Log_OC.i("SQL", "Entering in the #11 ADD in onUpgrade"); + db.beginTransaction(); + try { + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_IN_CONFLICT + " INTEGER " + + " DEFAULT 0"); + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + if (!upgraded) + Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + + ", newVersion == " + newVersion); + } } diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index ecd17213..2672926f 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -291,6 +291,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { localStateView.setImageResource(R.drawable.uploading_file_indicator); localStateView.setVisibility(View.VISIBLE); + } else if (file.isInConflict()) { // conflict + localStateView.setImageResource(R.drawable.conflict_file_indicator); + localStateView.setVisibility(View.VISIBLE); + } else if (file.isDown()) { localStateView.setImageResource(R.drawable.local_file_indicator); localStateView.setVisibility(View.VISIBLE);