/** * Registers a local file to be observed for changes. * * @param localPath Absolute path in the local file system to the file to be observed. * @param account OwnCloud account associated to the local file. */ private void addObservedFile(String localPath, Account account) { File file = new File(localPath); String parentPath = file.getParent(); FolderObserver observer = mFolderObserversMap.get(parentPath); if (observer == null) { observer = new FolderObserver(parentPath, account, getApplicationContext()); mFolderObserversMap.put(parentPath, observer); Log_OC.d(TAG, "Observer added for parent folder " + parentPath + "/"); } observer.startWatching(file.getName()); Log_OC.d(TAG, "Added " + localPath + " to list of observed children"); }
@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()); } }