import java.io.File;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import com.owncloud.android.MainApp;
private static String TAG = FileObserverService.class.getSimpleName();
private static Map<String, OwnCloudFileObserver> mObserversMap;
- //private static Map<String, OwnCloudFileObserver> mObserverParentsMap;
+ private static Map<String, OwnCloudFileObserver> mObserverParentsMap;
private static DownloadCompletedReceiver mDownloadReceiver;
registerReceiver(mDownloadReceiver, filter);
mObserversMap = new HashMap<String, OwnCloudFileObserver>();
- //mObserverParentsMap = new HashMap<String, OwnCloudFileObserver>();
+ mObserverParentsMap = new HashMap<String, OwnCloudFileObserver>();
}
Log_OC.d(TAG, "onDestroy - FINISHING OBSERVATION");
unregisterReceiver(mDownloadReceiver);
+
+ Iterator<OwnCloudFileObserver> it = mObserversMap.values().iterator();
+ while (it.hasNext()) {
+ it.next().stopWatching();
+ }
mObserversMap.clear();
- mObserversMap = null;
- //mObserverParentsMap = null;
+ mObserversMap = null;
+
+ it = mObserverParentsMap.values().iterator();
+ while (it.hasNext()) {
+ it.next().stopWatching();
+ }
+ mObserverParentsMap.clear();
+ mObserverParentsMap = null;
super.onDestroy();
}
}
}
- /*
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());
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);
+ }
+ }
+
}
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();