From 623bd0b15a56b10b78766d15cae5775e174741fc Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 21 Sep 2022 15:34:00 +0200 Subject: [PATCH 1/4] When a file is removed from the phone. Put the remote one in the remote trash --- .../foundation/e/drive/FileObservers/FileEventListener.java | 5 +++-- app/src/main/java/foundation/e/drive/models/SyncWrapper.java | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 24191867..43266bee 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/models/SyncWrapper.java b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java index a1984972..240352ea 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; -- GitLab From 28cce24cb18fb17607d7806628969e361ce138b7 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 26 Sep 2022 11:44:11 +0200 Subject: [PATCH 2/4] Add request to remove unscannable media from SyncedFileState databaase. bump version number to 1.2.4 Also, rewrite method name (add 's' at the end) for the method which remove hidden files from SyncedFileState database --- app/build.gradle | 2 +- .../java/foundation/e/drive/database/DbHelper.java | 5 +++-- .../e/drive/database/SyncedFileStateDAO.java | 13 +++++++++++-- .../foundation/e/drive/models/SyncedFileState.java | 8 -------- .../e/drive/receivers/BootCompletedReceiver.java | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index db4f90bc..648bfa2b 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/database/DbHelper.java b/app/src/main/java/foundation/e/drive/database/DbHelper.java index c0d2d9cb..54708046 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.deleteUnscannableMediaFiles(); 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 9f93de59..c7522735 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,22 @@ 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 removed + * @return number of deleted input + */ + public int deleteUnscannableMediaFiles() { + return mDB.delete(TABLE_NAME, IS_MEDIA_TYPE + " =1 AND "+SCANNABLE+" =0", 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/SyncedFileState.java b/app/src/main/java/foundation/e/drive/models/SyncedFileState.java index 7104feb8..38ee3331 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 6ec31479..779a3f6a 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); } -- GitLab From d02629ab5c62b26faf16298878740bdc5abe25e8 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 27 Sep 2022 09:54:16 +0000 Subject: [PATCH 3/4] Apply 1 suggestion(s) to 1 file(s) --- .../java/foundation/e/drive/database/SyncedFileStateDAO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c7522735..a2433dcb 100644 --- a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java +++ b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java @@ -119,7 +119,7 @@ class SyncedFileStateDAO { * @return number of deleted input */ public int deleteUnscannableMediaFiles() { - return mDB.delete(TABLE_NAME, IS_MEDIA_TYPE + " =1 AND "+SCANNABLE+" =0", null); + return mDB.delete(TABLE_NAME, IS_MEDIA_TYPE + " =1 AND " + SCANNABLE + " =0", null); } /** -- GitLab From d7e756a69d9cbd6f175f71a0f70b33b0b2176e29 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 3 Oct 2022 11:49:59 +0200 Subject: [PATCH 4/4] replace database deletion of unscannable file by force rescan on device only --- .../java/foundation/e/drive/database/DbHelper.java | 2 +- .../e/drive/database/SyncedFileStateDAO.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) 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 54708046..e0356834 100644 --- a/app/src/main/java/foundation/e/drive/database/DbHelper.java +++ b/app/src/main/java/foundation/e/drive/database/DbHelper.java @@ -369,7 +369,7 @@ public final class DbHelper extends SQLiteOpenHelper { public static void cleanSyncedFileStateTableAfterUpdate(Context context) throws SQLiteException { SyncedFileStateDAO dao = openSyncedFileStateDAO(context, true); dao.deleteHiddenFileStates(); - dao.deleteUnscannableMediaFiles(); + 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 a2433dcb..5503578c 100644 --- a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java +++ b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java @@ -115,11 +115,16 @@ class SyncedFileStateDAO { /** * 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 removed + * 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 deleteUnscannableMediaFiles() { - return mDB.delete(TABLE_NAME, IS_MEDIA_TYPE + " =1 AND " + SCANNABLE + " =0", null); + 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); } /** -- GitLab