2525import com .owncloud .android .MainApp ;
2626import com .owncloud .android .db .ProviderMeta ;
2727import com .owncloud .android .lib .common .utils .Log_OC ;
28- import com .owncloud .android .lib .resources .files .model .ServerFileInterface ;
2928
3029import java .io .File ;
3130import java .util .ArrayList ;
@@ -61,6 +60,7 @@ public SyncedFolderProvider(ContentResolver contentResolver, AppPreferences pref
6160 mContentResolver = contentResolver ;
6261 this .preferences = preferences ;
6362 this .clock = clock ;
63+ SyncedFolderObserver .INSTANCE .start (dao );
6464 }
6565
6666 /**
@@ -84,23 +84,19 @@ public long storeSyncedFolder(SyncedFolder syncedFolder) {
8484 }
8585 }
8686
87- public static boolean isAutoUploadFolder (SyncedFolderProvider syncedFolderProvider , ServerFileInterface file , User user ) {
88- return syncedFolderProvider != null && syncedFolderProvider .findByRemotePathAndAccount (file .getRemotePath (), user );
89- }
90-
9187 public int countEnabledSyncedFolders () {
9288 int count = 0 ;
9389 Cursor cursor = mContentResolver .query (
94- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
95- null ,
96- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ENABLED + " = ?" ,
97- new String []{"1" },
98- null
99- );
90+ ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
91+ null ,
92+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ENABLED + " = ?" ,
93+ new String []{"1" },
94+ null
95+ );
10096
10197 if (cursor != null ) {
102- count = cursor .getCount ();
103- cursor .close ();
98+ count = cursor .getCount ();
99+ cursor .close ();
104100 }
105101
106102 return count ;
@@ -154,12 +150,12 @@ public int updateSyncedFolderEnabled(long id, Boolean enabled) {
154150
155151 int result = 0 ;
156152 Cursor cursor = mContentResolver .query (
157- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
158- null ,
159- ProviderMeta .ProviderTableMeta ._ID + "=?" ,
160- new String []{String .valueOf (id )},
161- null
162- );
153+ ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
154+ null ,
155+ ProviderMeta .ProviderTableMeta ._ID + "=?" ,
156+ new String []{String .valueOf (id )},
157+ null
158+ );
163159
164160 if (cursor != null && cursor .getCount () == 1 ) {
165161 while (cursor .moveToNext ()) {
@@ -177,7 +173,7 @@ public int updateSyncedFolderEnabled(long id, Boolean enabled) {
177173 Log_OC .e (TAG , "Sync folder db cursor for ID=" + id + " in NULL." );
178174 } else {
179175 Log_OC .e (TAG , cursor .getCount () + " items for id=" + id + " available in sync folder database. " +
180- "Expected 1. Failed to update sync folder db." );
176+ "Expected 1. Failed to update sync folder db." );
181177 }
182178 }
183179
@@ -226,10 +222,10 @@ public SyncedFolder getSyncedFolderByID(Long syncedFolderID) {
226222 */
227223 public int deleteSyncFoldersForAccount (User user ) {
228224 return mContentResolver .delete (
229- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
230- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ACCOUNT + " = ?" ,
231- new String []{String .valueOf (user .getAccountName ())}
232- );
225+ ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
226+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ACCOUNT + " = ?" ,
227+ new String []{String .valueOf (user .getAccountName ())}
228+ );
233229 }
234230
235231 /**
@@ -284,10 +280,10 @@ public void updateAutoUploadPaths(Context context) {
284280 */
285281 public int deleteSyncedFoldersNotInList (List <Long > ids ) {
286282 int result = mContentResolver .delete (
287- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
288- ProviderMeta .ProviderTableMeta ._ID + " NOT IN (?)" ,
289- new String []{String .valueOf (ids )}
290- );
283+ ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
284+ ProviderMeta .ProviderTableMeta ._ID + " NOT IN (?)" ,
285+ new String []{String .valueOf (ids )}
286+ );
291287
292288 if (result > 0 ) {
293289 preferences .setLegacyClean (true );
@@ -301,10 +297,10 @@ public int deleteSyncedFoldersNotInList(List<Long> ids) {
301297 */
302298 public int deleteSyncedFolder (long id ) {
303299 return mContentResolver .delete (
304- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
305- ProviderMeta .ProviderTableMeta ._ID + " = ?" ,
306- new String []{String .valueOf (id )}
307- );
300+ ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
301+ ProviderMeta .ProviderTableMeta ._ID + " = ?" ,
302+ new String []{String .valueOf (id )}
303+ );
308304 }
309305
310306 public AppPreferences getPreferences () {
@@ -323,11 +319,11 @@ public int updateSyncFolder(SyncedFolder syncedFolder) {
323319 ContentValues cv = createContentValuesFromSyncedFolder (syncedFolder );
324320
325321 return mContentResolver .update (
326- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
327- cv ,
328- ProviderMeta .ProviderTableMeta ._ID + "=?" ,
329- new String []{String .valueOf (syncedFolder .getId ())}
330- );
322+ ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
323+ cv ,
324+ ProviderMeta .ProviderTableMeta ._ID + "=?" ,
325+ new String []{String .valueOf (syncedFolder .getId ())}
326+ );
331327 }
332328
333329 /**
@@ -341,33 +337,33 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
341337 if (cursor != null ) {
342338 long id = cursor .getLong (cursor .getColumnIndexOrThrow (ProviderMeta .ProviderTableMeta ._ID ));
343339 String localPath = cursor .getString (cursor .getColumnIndexOrThrow (
344- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_LOCAL_PATH ));
340+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_LOCAL_PATH ));
345341 String remotePath = cursor .getString (cursor .getColumnIndexOrThrow (
346- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_REMOTE_PATH ));
342+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_REMOTE_PATH ));
347343 boolean wifiOnly = cursor .getInt (cursor .getColumnIndexOrThrow (
348- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_WIFI_ONLY )) == 1 ;
344+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_WIFI_ONLY )) == 1 ;
349345 boolean chargingOnly = cursor .getInt (cursor .getColumnIndexOrThrow (
350- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_CHARGING_ONLY )) == 1 ;
346+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_CHARGING_ONLY )) == 1 ;
351347 boolean existing = cursor .getInt (cursor .getColumnIndexOrThrow (
352- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_EXISTING )) == 1 ;
348+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_EXISTING )) == 1 ;
353349 boolean subfolderByDate = cursor .getInt (cursor .getColumnIndexOrThrow (
354- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_SUBFOLDER_BY_DATE )) == 1 ;
350+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_SUBFOLDER_BY_DATE )) == 1 ;
355351 String accountName = cursor .getString (cursor .getColumnIndexOrThrow (
356- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ACCOUNT ));
352+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ACCOUNT ));
357353 int uploadAction = cursor .getInt (cursor .getColumnIndexOrThrow (
358- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_UPLOAD_ACTION ));
354+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_UPLOAD_ACTION ));
359355 int nameCollisionPolicy = cursor .getInt (cursor .getColumnIndexOrThrow (
360356 ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_NAME_COLLISION_POLICY ));
361357 boolean enabled = cursor .getInt (cursor .getColumnIndexOrThrow (
362- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ENABLED )) == 1 ;
358+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ENABLED )) == 1 ;
363359 long enabledTimestampMs = cursor .getLong (cursor .getColumnIndexOrThrow (
364- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ENABLED_TIMESTAMP_MS ));
360+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ENABLED_TIMESTAMP_MS ));
365361 MediaFolderType type = MediaFolderType .getById (cursor .getInt (cursor .getColumnIndexOrThrow (
366- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_TYPE )));
362+ ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_TYPE )));
367363 boolean hidden = cursor .getInt (cursor .getColumnIndexOrThrow (
368364 ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_HIDDEN )) == 1 ;
369365 SubFolderRule subFolderRule = SubFolderRule .values ()[cursor .getInt (
370- cursor .getColumnIndexOrThrow (ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_SUBFOLDER_RULE ))];
366+ cursor .getColumnIndexOrThrow (ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_SUBFOLDER_RULE ))];
371367 boolean excludeHidden = cursor .getInt (cursor .getColumnIndexOrThrow (
372368 ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_EXCLUDE_HIDDEN )) == 1 ;
373369 long lastScanTimestampMs = cursor .getLong (cursor .getColumnIndexOrThrow (
@@ -423,48 +419,4 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
423419 cv .put (ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_LAST_SCAN_TIMESTAMP_MS , syncedFolder .getLastScanTimestampMs ());
424420 return cv ;
425421 }
426-
427- /**
428- * method to check if sync folder for the remote path exist in table or not
429- *
430- * @param remotePath to be check
431- * @param user for which we are looking
432- * @return <code>true</code> if exist, <code>false</code> otherwise
433- */
434- public boolean findByRemotePathAndAccount (String remotePath , User user ) {
435- if (user == null ) {
436- return false ;
437- }
438-
439- boolean result = false ;
440-
441- //if path ends with / then remove the last / to work the query right way
442- //because the sub folders of synced folders will not have the slash at the end
443- if (remotePath .endsWith ("/" )) {
444- remotePath = remotePath .substring (0 , remotePath .length () - 1 );
445- }
446-
447- Cursor cursor = mContentResolver .query (
448- ProviderMeta .ProviderTableMeta .CONTENT_URI_SYNCED_FOLDERS ,
449- null ,
450- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_REMOTE_PATH + " LIKE ? AND " +
451- ProviderMeta .ProviderTableMeta .SYNCED_FOLDER_ACCOUNT + " =? " ,
452- new String []{"%" + remotePath + "%" , user .getAccountName ()},
453- null );
454-
455- if (cursor != null && cursor .getCount () >= 1 ) {
456- result = true ;
457- } else {
458- if (cursor == null ) {
459- Log_OC .e (TAG , "Sync folder db cursor for remote path = " + remotePath + " in NULL." );
460- }
461- }
462-
463- if (cursor != null ) {
464- cursor .close ();
465- }
466-
467- return result ;
468-
469- }
470422}
0 commit comments