diff --git a/app/build.gradle b/app/build.gradle index db4f90bce14b0ac797d3da286eb0abd0e9352a4e..648bfa2bd1ec68602ef422c24e55ec4e1b737809 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { def versionMajor = 1 def versionMinor = 2 -def versionPatch = 3 +def versionPatch = 4 diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index 24191867fb31b811c041c536487e79486ee99be7..43266beece690e03367d6cd262f5273abbeee468 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -8,6 +8,7 @@ package foundation.e.drive.FileObservers; +import static foundation.e.drive.models.SyncRequest.Type.REMOTE_DELETE; import static foundation.e.drive.models.SyncRequest.Type.UPLOAD; import android.content.Context; @@ -222,8 +223,8 @@ public class FileEventListener { //If already in DB if (fileState.getScannable() > 0) { - fileState.setScannable(0); - DbHelper.manageSyncedFileStateDB(fileState, "UPDATE", appContext); + SyncRequest deleteRequest = new SyncRequest(fileState, REMOTE_DELETE); + this.sendSyncRequestToSynchronizationService(deleteRequest); } } diff --git a/app/src/main/java/foundation/e/drive/database/DbHelper.java b/app/src/main/java/foundation/e/drive/database/DbHelper.java index c0d2d9cb5b063f4a1d172552ddb4f289f84c1d1c..e0356834c1a39c3cc6f1646cd03ee7ee31c8b858 100644 --- a/app/src/main/java/foundation/e/drive/database/DbHelper.java +++ b/app/src/main/java/foundation/e/drive/database/DbHelper.java @@ -366,9 +366,10 @@ public final class DbHelper extends SQLiteOpenHelper { * @param context * @throws SQLiteException if database can't be open */ - public static void removeHiddenSyncedFileState(Context context) throws SQLiteException { + public static void cleanSyncedFileStateTableAfterUpdate(Context context) throws SQLiteException { SyncedFileStateDAO dao = openSyncedFileStateDAO(context, true); - dao.deleteHiddenFileState(); + dao.deleteHiddenFileStates(); + dao.updateUnscannableMediaFiles(); dao.close(); } } diff --git a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java index 9f93de59c7e9eb0f2ca0abd4a06e37792fd0b770..5503578c125471c6ca7eab819bdf79cd15c33b16 100644 --- a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java +++ b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java @@ -106,13 +106,27 @@ class SyncedFileStateDAO { /** - * Remove SyncedFileState for hidden file (starting with '.') + * Remove SyncedFileState for hidden files (starting with '.') * @return number of deleted input */ - public int deleteHiddenFileState() { + public int deleteHiddenFileStates() { return mDB.delete(TABLE_NAME, FILE_NAME + " LIKE ?", new String[]{".%"}); } + /** + * In previous version, when a synchronized file was removed, the DB value for scannable column + * was set to "0"; Now we consider those entries has to be scannable set to "2" in order to let synchronization algo + * to remove them + * @return number of deleted input + */ + public int updateUnscannableMediaFiles() { + final ContentValues value = new ContentValues(); + value.put(SCANNABLE, SyncedFileState.DEVICE_SCANNABLE); + final String whereClause = IS_MEDIA_TYPE + " =1 AND " + SCANNABLE + " ="+SyncedFileState.NOT_SCANNABLE; + + return mDB.update(TABLE_NAME, value, whereClause, null); + } + /** * Delete each syncedFileState which is bound to syncedFOlder with specified ID * @param folderId syncedFolder's id used as foreign key diff --git a/app/src/main/java/foundation/e/drive/models/SyncWrapper.java b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java index a1984972596c3eff221fd25ab9350f9afb7a68d7..240352ea035af8a5c0d5975c907d618edca69c12 100644 --- a/app/src/main/java/foundation/e/drive/models/SyncWrapper.java +++ b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java @@ -16,6 +16,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import java.io.File; import foundation.e.drive.operations.DownloadFileOperation; +import foundation.e.drive.operations.RemoveFileOperation; import foundation.e.drive.operations.UploadFileOperation; /** @@ -66,7 +67,7 @@ public class SyncWrapper { final File file = new File(sfs.getLocalPath()); if (!file.exists()) { operation = null; - Log.w(TAG, "createRemoteOperation: local file doesn't exist for upload"); + Log.w(TAG, "createRemoteOperation: local file doesn't. Can't upload"); break; } operation = new UploadFileOperation(sfs, account, context); @@ -78,6 +79,8 @@ public class SyncWrapper { context); break; case REMOTE_DELETE: + operation = new RemoveFileOperation(request.getSyncedFileState()); + break; default: operation = null; break; diff --git a/app/src/main/java/foundation/e/drive/models/SyncedFileState.java b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java index 7104feb8ea65ef3be48beb5363aae3c8c5a156d2..38ee333131ad353c274e266dcc83f1506a7ae5db 100644 --- a/app/src/main/java/foundation/e/drive/models/SyncedFileState.java +++ b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java @@ -176,14 +176,6 @@ public class SyncedFileState implements Parcelable { return scannable; } - /** - * Define in which context the file can be scan - * @param scannable 0: never. 1: on cloud only. 2: on device only. 3: in every context. - */ - public void setScannable(int scannable) { - this.scannable = scannable; - } - @Override public String toString(){ diff --git a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java index 6ec31479f296a6e07ae353df6c0ea22f28e89169..779a3f6a4519cc8b0b7ba2ad755b911517ed07ab 100644 --- a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java @@ -47,7 +47,7 @@ public class BootCompletedReceiver extends BroadcastReceiver { && BuildConfig.VERSION_CODE > pref.getInt(PREF_VERSION_CODE, 1002000)) { pref.edit().putInt(PREF_VERSION_CODE, BuildConfig.VERSION_CODE).apply(); try { - DbHelper.removeHiddenSyncedFileState(context); + DbHelper.cleanSyncedFileStateTableAfterUpdate(context); } catch (SQLiteException e) { Log.e(TAG, "Can't remove entry for hidden file in Database", e); }