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 77a584215841ca7b7989086be17cfbbb4f34ca0e..f83a57fd27dcfc849716d274d4510beed58819f0 100644 --- a/app/src/main/java/foundation/e/drive/database/DbHelper.java +++ b/app/src/main/java/foundation/e/drive/database/DbHelper.java @@ -160,11 +160,11 @@ public final class DbHelper extends SQLiteOpenHelper { * @return empty list if DB opening failed, either return the list of SyncedFileState */ public static List getSyncedFileStatesByFolders(Context context, List ids) {//Connect to DB - SyncedFileStateDAO dao = openSyncedFileStateDAO(context, false); - if(dao == null){ + final SyncedFileStateDAO dao = openSyncedFileStateDAO(context, false); + if (dao == null) { return new ArrayList<>(); } - List result = dao.getBySyncedFolderID(ids); + final List result = dao.getBySyncedFolderIds(ids); dao.close(); return result; } 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 fffc4da0d4163e0f65060d3bcb0d4f81959e1318..1249eb20fde456e51a2d8f19636948453ffb3478 100644 --- a/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java +++ b/app/src/main/java/foundation/e/drive/database/SyncedFileStateDAO.java @@ -141,37 +141,43 @@ class SyncedFileStateDAO { } /** - * Fetch many SyncedFileState by its localPath - * @param syncedFolderids List of path to filter. Need to be directory path - * @return List List of SyncedFileState filtered on syncedFolder ID. + * Fetch every syncedFileState for subfile of directories identified by syncedFolder's id. + * + * @param syncedFolderids List of SyncedFolderIds + * @return List List of SyncedFileState filtered on syncedFolder ID. The result is an empty list + * if list of syncedFolderIds is null or empty */ - List getBySyncedFolderID(List syncedFolderids) { + List getBySyncedFolderIds(final List syncedFolderids) { + final List result = new ArrayList<>(); + if (syncedFolderids == null || syncedFolderids.isEmpty()) { + Log.e(TAG, "getBySyncedFolderIds with empty list as parameter"); + return result; + } + String query = "Select " - +SyncedFileStateContract._ID+", " - +FILE_NAME+", " - +LOCAL_PATH+", " - +REMOTE_PATH+", " - +LAST_ETAG+", " - +LOCAL_LAST_MODIFIED+", " + + SyncedFileStateContract._ID + ", " + + FILE_NAME + ", " + + LOCAL_PATH + ", " + + REMOTE_PATH + ", " + + LAST_ETAG + ", " + + LOCAL_LAST_MODIFIED + ", " + SYNCEDFOLDER_ID+", " + IS_MEDIA_TYPE+", " + SCANNABLE - +" FROM " - +TABLE_NAME; - if (syncedFolderids.size() > 0) { - query+=" WHERE "; - - for (int i = -1, idsSize = syncedFolderids.size(); ++i < idsSize; ) { - query += SYNCEDFOLDER_ID + " = " + syncedFolderids.get(i); - if (i < idsSize - 1) { - query += " OR "; - } + + " FROM " + + TABLE_NAME + + " WHERE "; + + for (int i = -1, idsSize = syncedFolderids.size(); ++i < idsSize; ) { + query += SYNCEDFOLDER_ID + " = " + syncedFolderids.get(i); + if (i < idsSize - 1) { + query += " OR "; } } + Log.d(TAG+"_getBySyncedFolderID(...)", query); - Cursor cursor = mDB.rawQuery(query, null); + final Cursor cursor = mDB.rawQuery(query, null); cursor.moveToFirst(); - List result = new ArrayList<>(); while(!cursor.isAfterLast() ) { result.add( cursorToSyncedFileState(cursor) ); cursor.moveToNext();