/** * Unregisters a local file from being observed for changes. * * @param localPath Absolute path in the local file system to the target file. */ private void removeObservedFile(String localPath) { File file = new File(localPath); String parentPath = file.getParent(); FolderObserver observer = mFolderObserversMap.get(parentPath); if (observer != null) { observer.stopWatching(file.getName()); if (observer.isEmpty()) { mFolderObserversMap.remove(parentPath); Log_OC.d(TAG, "Observer removed for parent folder " + parentPath + "/"); } } else { Log_OC.d(TAG, "No observer to remove for path " + localPath); } }
@Override public void onReceive(Context context, Intent intent) { Log_OC.d(TAG, "Received broadcast intent " + intent); File downloadedFile = new File(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); String parentPath = downloadedFile.getParent(); FolderObserver observer = mFolderObserversMap.get(parentPath); if (observer != null) { if (intent.getAction().equals(FileDownloader.getDownloadFinishMessage()) && downloadedFile.exists()) { // no matter if the download was successful or not; the // file could be down anyway due to a former download or upload observer.startWatching(downloadedFile.getName()); Log_OC.d(TAG, "Resuming observance of " + downloadedFile.getAbsolutePath()); } else if (intent.getAction().equals(FileDownloader.getDownloadAddedMessage())) { observer.stopWatching(downloadedFile.getName()); Log_OC.d(TAG, "Pausing observance of " + downloadedFile.getAbsolutePath()); } } else { Log_OC.d(TAG, "No observer for path " + downloadedFile.getAbsolutePath()); } }