From: David A. Velasco Date: Fri, 27 Jun 2014 10:06:49 +0000 (+0200) Subject: Testing observance on parent folders to deal with apps that replace a favorite file... X-Git-Tag: oc-android-1.7.0_signed~256^2~6 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/66477906202ab05630ab4d8f9bd4ceb2787848a7 Testing observance on parent folders to deal with apps that replace a favorite file (delete it) when updating it --- diff --git a/src/com/owncloud/android/files/services/FileObserverService.java b/src/com/owncloud/android/files/services/FileObserverService.java index cb72cc47..ab3d4f36 100644 --- a/src/com/owncloud/android/files/services/FileObserverService.java +++ b/src/com/owncloud/android/files/services/FileObserverService.java @@ -69,7 +69,7 @@ public class FileObserverService extends Service { private static String TAG = FileObserverService.class.getSimpleName(); private static Map mObserversMap; - //private static Map mObserverParentsMap; + private static Map mObserverParentsMap; private static DownloadCompletedReceiver mDownloadReceiver; @@ -125,7 +125,7 @@ public class FileObserverService extends Service { registerReceiver(mDownloadReceiver, filter); mObserversMap = new HashMap(); - //mObserverParentsMap = new HashMap(); + mObserverParentsMap = new HashMap(); } @@ -142,7 +142,12 @@ public class FileObserverService extends Service { mObserversMap.clear(); mObserversMap = null; - //mObserverParentsMap = null; + it = mObserverParentsMap.values().iterator(); + while (it.hasNext()) { + it.next().stopWatching(); + } + mObserverParentsMap.clear(); + mObserverParentsMap = null; super.onDestroy(); } @@ -243,21 +248,18 @@ public class FileObserverService extends Service { } } - /* String parentPath = (new File(localPath)).getParent(); - OwnCloudFileObserver observerParent = - new OwnCloudFileObserver( parentPath, - account, - getApplicationContext()); - mObserverParentsMap.put(parentPath, observer); - - if (new File(localPath).exists()) { - observer.startWatching(); - Log_OC.d(TAG, "Started watching file " + localPath); - observerParent.startWatching(); - Log_OC.d(TAG, "Started watching parent file " + parentPath); + OwnCloudFileObserver observerParent = mObserverParentsMap.get(parentPath); + if (observerParent == null) { + observerParent = new OwnCloudFileObserver( + parentPath, account, getApplicationContext() + ); + mObserverParentsMap.put(parentPath, observer); + if (new File(parentPath).exists()) { + observerParent.startWatching(); + Log_OC.d(TAG, "Started watching parent folder " + parentPath); + } } - */ } while (cursorOnKeptInSync.moveToNext()); @@ -299,32 +301,35 @@ public class FileObserverService extends Service { OwnCloudFileObserver observer = mObserversMap.get(localPath); if (observer == null) { /// the local file was never registered to observe before - observer = new OwnCloudFileObserver( localPath, - account, - getApplicationContext(), - mHandler); + observer = new OwnCloudFileObserver( + localPath, account, getApplicationContext() + ); mObserversMap.put(localPath, observer); Log_OC.d(TAG, "Observer added for path " + localPath); - /* - String parentPath = (new File(localPath)).getParent(); - OwnCloudFileObserver observerParent = - new OwnCloudFileObserver( parentPath, - account, - getApplicationContext()); - mObserverParentsMap.put(parentPath, observer); - */ - if (file.isDown()) { observer.startWatching(); Log_OC.d(TAG, "Started watching " + localPath); - /*observerParent.startWatching(); - Log_OC.d(TAG, "Started watching parent file " + parentPath);*/ } // else - the observance can't be started on a file not already down; // mDownloadReceiver will get noticed when the download of the file finishes } + String parentPath = (new File(localPath)).getParent(); + OwnCloudFileObserver observerParent = mObserverParentsMap.get(parentPath); + if (observerParent == null) { + observerParent = new OwnCloudFileObserver( + parentPath, account, getApplicationContext() + ); + mObserverParentsMap.put(parentPath, observerParent); + Log_OC.d(TAG, "Observer added for parent folder " + localPath); + + if (file.isDown()) { + observerParent.startWatching(); + Log_OC.d(TAG, "Started watching parent folder " + parentPath); + } + } + } @@ -381,16 +386,12 @@ public class FileObserverService extends Service { String downloadPath = intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH); OwnCloudFileObserver observer = mObserversMap.get(downloadPath); if (observer != null) { - /*String parentPath = (new File(downloadPath)).getParent(); - OwnCloudFileObserver observerParent = mObserverParentsMap.get(parentPath); */ if (intent.getAction().equals(FileDownloader.getDownloadFinishMessage()) && new File(downloadPath).exists()) { // no matter is the download was be successful or not; the file could be down, // anyway due to a former download or upload observer.startWatching(); Log_OC.d(TAG, "Resuming observance of " + downloadPath); - /*observerParent.startWatching(); - Log_OC.d(TAG, "Watching parent again " + parentPath); */ } else if (intent.getAction().equals(FileDownloader.getDownloadAddedMessage())) { observer.stopWatching();