Browse Source

Fixed check of modifications applied in server (still based on modification date)

David A. Velasco 12 years ago
parent
commit
abd5f51554

+ 4 - 0
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -108,6 +108,7 @@ public class FileDataStorageManager implements DataStorageManager {
         boolean overriden = false;
         ContentValues cv = new ContentValues();
         cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
+        cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
         cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
         cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
         cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
@@ -189,6 +190,7 @@ public class FileDataStorageManager implements DataStorageManager {
             file = filesIt.next();
             ContentValues cv = new ContentValues();
             cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
+            cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
             cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
             cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
             cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
@@ -414,6 +416,8 @@ public class FileDataStorageManager implements DataStorageManager {
                     .getColumnIndex(ProviderTableMeta.FILE_CREATION)));
             file.setModificationTimestamp(c.getLong(c
                     .getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
+            file.setModificationTimestampAtLastSyncForData(c.getLong(c
+                    .getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
             file.setLastSyncDateForProperties(c.getLong(c
                     .getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
             file.setLastSyncDateForData(c.getLong(c.

+ 36 - 3
src/com/owncloud/android/datamodel/OCFile.java

@@ -47,6 +47,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     private long mLength;
     private long mCreationTimestamp;
     private long mModifiedTimestamp;
+    private long mModifiedTimestampAtLastSyncForData;
     private String mRemotePath;
     private String mLocalPath;
     private String mMimeType;
@@ -84,6 +85,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mLength = source.readLong();
         mCreationTimestamp = source.readLong();
         mModifiedTimestamp = source.readLong();
+        mModifiedTimestampAtLastSyncForData = source.readLong();
         mRemotePath = source.readString();
         mLocalPath = source.readString();
         mMimeType = source.readString();
@@ -100,6 +102,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         dest.writeLong(mLength);
         dest.writeLong(mCreationTimestamp);
         dest.writeLong(mModifiedTimestamp);
+        dest.writeLong(mModifiedTimestampAtLastSyncForData);
         dest.writeString(mRemotePath);
         dest.writeString(mLocalPath);
         dest.writeString(mMimeType);
@@ -196,9 +199,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     }
 
     /**
-     * Get a UNIX timestamp of the file modification time
-     * 
-     * @return A UNIX timestamp of the modification time
+     * Get a UNIX timestamp of the file modification time.
+     *
+     * @return  A UNIX timestamp of the modification time, corresponding to the value returned by the server
+     *          in the last synchronization of the properties of this file. 
      */
     public long getModificationTimestamp() {
         return mModifiedTimestamp;
@@ -207,12 +211,40 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     /**
      * Set a UNIX timestamp of the time the time the file was modified.
      * 
+     * To update with the value returned by the server in every synchronization of the properties 
+     * of this file.
+     * 
      * @param modification_timestamp to set
      */
     public void setModificationTimestamp(long modification_timestamp) {
         mModifiedTimestamp = modification_timestamp;
     }
 
+    
+    /**
+     * Get a UNIX timestamp of the file modification time.
+     *
+     * @return  A UNIX timestamp of the modification time, corresponding to the value returned by the server
+     *          in the last synchronization of THE CONTENTS of this file. 
+     */
+    public long getModificationTimestampAtLastSyncForData() {
+        return mModifiedTimestampAtLastSyncForData;
+    }
+
+    /**
+     * Set a UNIX timestamp of the time the time the file was modified.
+     * 
+     * To update with the value returned by the server in every synchronization of THE CONTENTS 
+     * of this file.
+     * 
+     * @param modification_timestamp to set
+     */
+    public void setModificationTimestampAtLastSyncForData(long modificationTimestamp) {
+        mModifiedTimestampAtLastSyncForData = modificationTimestamp;
+    }
+
+    
+    
     /**
      * Returns the filename and "/" for the root directory
      * 
@@ -280,6 +312,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mLength = 0;
         mCreationTimestamp = 0;
         mModifiedTimestamp = 0;
+        mModifiedTimestampAtLastSyncForData = 0;
         mLastSyncDateForProperties = 0;
         mLastSyncDateForData = 0;
         mKeepInSync = false;

+ 2 - 2
src/com/owncloud/android/db/ProviderMeta.java

@@ -31,8 +31,7 @@ public class ProviderMeta {
     public static final String AUTHORITY_FILES = "org.owncloud";
     public static final String DB_FILE = "owncloud.db";
     public static final String DB_NAME = "filelist";
-    //public static final int DB_VERSION = 2;
-    public static final int DB_VERSION = 3;
+    public static final int DB_VERSION = 4;
 
     private ProviderMeta() {
     }
@@ -53,6 +52,7 @@ public class ProviderMeta {
         public static final String FILE_NAME = "filename";
         public static final String FILE_CREATION = "created";
         public static final String FILE_MODIFIED = "modified";
+        public static final String FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA = "modified_at_last_sync_for_data";
         public static final String FILE_CONTENT_LENGTH = "content_length";
         public static final String FILE_CONTENT_TYPE = "content_type";
         public static final String FILE_STORAGE_PATH = "media_path";

+ 1 - 0
src/com/owncloud/android/files/services/FileDownloader.java

@@ -301,6 +301,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         file.setLastSyncDateForProperties(syncDate);
         file.setLastSyncDateForData(syncDate);
         file.setModificationTimestamp(mCurrentDownload.getModificationTimestamp());
+        file.setModificationTimestampAtLastSyncForData(mCurrentDownload.getModificationTimestamp());
         // file.setEtag(mCurrentDownload.getEtag());    // TODO Etag, where available
         file.setMimetype(mCurrentDownload.getMimeType());
         file.setStoragePath(mCurrentDownload.getSavePath());

+ 2 - 1
src/com/owncloud/android/files/services/FileUploader.java

@@ -489,7 +489,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         file.setCreationTimestamp(we.createTimestamp());
         file.setFileLength(we.contentLength());
         file.setMimetype(we.contentType());
-        file.setModificationTimestamp(we.modifiedTimesamp());
+        file.setModificationTimestamp(we.modifiedTimestamp());
+        file.setModificationTimestampAtLastSyncForData(we.modifiedTimestamp());
         // file.setEtag(mCurrentDownload.getEtag());    // TODO Etag, where available
     }
     

+ 2 - 2
src/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -113,7 +113,7 @@ public class SynchronizeFileOperation extends RemoteOperation {
                         serverChanged = (!mServerFile.getEtag().equals(mLocalFile.getEtag()));   // TODO could this be dangerous when the user upgrades the server from non-tagged to tagged?
                     } else {
                         // server without etags
-                        serverChanged = (mServerFile.getModificationTimestamp() > mLocalFile.getModificationTimestamp());
+                        serverChanged = (mServerFile.getModificationTimestamp() > mLocalFile.getModificationTimestampAtLastSyncForData());
                     }
                     boolean localChanged = (mLocalChangeAlreadyKnown || mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData());
                         // TODO this will be always true after the app is upgraded to database version 3; will result in unnecessary uploads
@@ -214,7 +214,7 @@ public class SynchronizeFileOperation extends RemoteOperation {
         file.setCreationTimestamp(we.createTimestamp());
         file.setFileLength(we.contentLength());
         file.setMimetype(we.contentType());
-        file.setModificationTimestamp(we.modifiedTimesamp());
+        file.setModificationTimestamp(we.modifiedTimestamp());
         return file;
     }
 

+ 1 - 1
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -279,7 +279,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         file.setCreationTimestamp(we.createTimestamp());
         file.setFileLength(we.contentLength());
         file.setMimetype(we.contentType());
-        file.setModificationTimestamp(we.modifiedTimesamp());
+        file.setModificationTimestamp(we.modifiedTimestamp());
         file.setParentId(mParentId);
         return file;
     }

+ 1 - 0
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -310,6 +310,7 @@ public class UploadFileOperation extends RemoteOperation {
         newFile.setFileLength(mFile.getFileLength());
         newFile.setMimetype(mFile.getMimetype());
         newFile.setModificationTimestamp(mFile.getModificationTimestamp());
+        newFile.setModificationTimestampAtLastSyncForData(mFile.getModificationTimestampAtLastSyncForData());
         // newFile.setEtag(mFile.getEtag())
         newFile.setKeepInSync(mFile.keepInSync());
         newFile.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties());

+ 11 - 1
src/com/owncloud/android/providers/FileContentProvider.java

@@ -62,6 +62,8 @@ public class FileContentProvider extends ContentProvider {
                 ProviderTableMeta.FILE_CREATION);
         mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED,
                 ProviderTableMeta.FILE_MODIFIED);
+        mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
+                ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA);
         mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH,
                 ProviderTableMeta.FILE_CONTENT_LENGTH);
         mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE,
@@ -224,7 +226,8 @@ public class FileContentProvider extends ContentProvider {
                     + ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, "
                     + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, "
                     + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, "
-                    + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER );"
+                    + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, "
+                    + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER );"
                     );
         }
 
@@ -246,6 +249,13 @@ public class FileContentProvider extends ContentProvider {
                            " DEFAULT 0");
                 upgraded = true;
             }
+            if (oldVersion < 4 && newVersion >= 4) {
+                Log.i("SQL", "Entering in the #3 ADD in onUpgrade");
+                db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
+                           " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA  + " INTEGER " +
+                           " DEFAULT 0");
+                upgraded = true;
+            }
             if (!upgraded)
                 Log.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
         }

+ 1 - 1
src/eu/alefzero/webdav/WebdavEntry.java

@@ -126,7 +126,7 @@ public class WebdavEntry {
         return mCreateTimestamp;
     }
 
-    public long modifiedTimesamp() {
+    public long modifiedTimestamp() {
         return mModifiedTimestamp;
     }