<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>\r
</receiver>\r
- <!-- receiver android:name=".files.BootupBroadcastReceiver">\r
+ <receiver android:name=".files.BootupBroadcastReceiver">\r
<intent-filter>\r
<action android:name="android.intent.action.BOOT_COMPLETED"/>\r
</intent-filter>\r
- </receiver -->\r
- <!-- service android:name=".files.services.FileObserverService"/ -->\r
+ </receiver>\r
+ <service android:name=".files.services.FileObserverService"/>
</application>\r
\r
</manifest>
return mPath;
}
+ public String getRemotePath() {
+ return mFile.getRemotePath();
+ }
+
@Override
public void onEvent(int event, String path) {
- if ((event | mMask) == 0) {
+ Log.d(TAG, "Got file modified with event " + event + " and path " + path);
+ if ((event & mMask) == 0) {
Log.wtf(TAG, "Incorrect event " + event + " sent for file " + path +
" with registered for " + mMask + " and original path " +
mPath);
public final static int CMD_INIT_OBSERVED_LIST = 1;
public final static int CMD_ADD_OBSERVED_FILE = 2;
public final static int CMD_DEL_OBSERVED_FILE = 3;
+ public final static int CMD_ADD_DOWNLOADING_FILE = 4;
private static String TAG = "FileObserverService";
private static List<OwnCloudFileObserver> mObservers;
case CMD_DEL_OBSERVED_FILE:
removeObservedFile(intent.getStringExtra(KEY_CMD_ARG));
break;
+ case CMD_ADD_DOWNLOADING_FILE:
+ addDownloadingFile(intent.getStringExtra(KEY_CMD_ARG));
+ break;
default:
Log.wtf(TAG, "Incorrect key given");
}
return Service.START_STICKY;
}
-
+
private void initializeObservedList() {
if (mObservers != null) return; // nothing to do here
mObservers = new ArrayList<OwnCloudFileObserver>();
String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
OwnCloudFileObserver observer =
new OwnCloudFileObserver(path, OwnCloudFileObserver.CHANGES_ONLY);
- observer.setContext(getBaseContext());
+ observer.setContext(getApplicationContext());
observer.setAccount(account);
observer.setStorageManager(storage);
observer.setOCFile(storage.getFileByPath(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH))));
}
Log.d(TAG, "Stopped watching " + path);
}
+
+ private void addDownloadingFile(String remotePath) {
+ OwnCloudFileObserver observer = null;
+ for (OwnCloudFileObserver o : mObservers) {
+ if (o.getRemotePath().equals(remotePath)) {
+ observer = o;
+ break;
+ }
+ }
+ if (observer == null) {
+ Log.e(TAG, "Couldn't find observer for remote file " + remotePath);
+ return;
+ }
+ observer.stopWatching();
+ DownloadCompletedReceiver dcr = new DownloadCompletedReceiver(observer.getPath(), observer);
+ registerReceiver(dcr, new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE));
+ }
+
private static void addReceiverToList(DownloadCompletedReceiver r) {
synchronized(mReceiverListLock) {
import com.owncloud.android.datamodel.FileDataStorageManager;\r
import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\r
+import com.owncloud.android.files.services.FileObserverService;\r
import com.owncloud.android.utils.OwnCloudVersion;\r
\r
import android.accounts.Account;\r
getStorageManager().getFileByPath(file.getRemotePath()).keepInSync() &&\r
file.getModificationTimestamp() > getStorageManager().getFileByPath(file.getRemotePath())\r
.getModificationTimestamp()) {\r
- Intent intent = new Intent(this.getContext(), FileDownloader.class);\r
+ // first disable observer so we won't get file upload right after download\r
+ Log.d(TAG, "Disabling observation of remote file" + file.getRemotePath());\r
+ Intent intent = new Intent(getContext(), FileObserverService.class);\r
+ intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_ADD_DOWNLOADING_FILE);\r
+ intent.putExtra(FileObserverService.KEY_CMD_ARG, file.getRemotePath());\r
+ getContext().startService(intent);\r
+ intent = new Intent(this.getContext(), FileDownloader.class);\r
intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());\r
intent.putExtra(FileDownloader.EXTRA_FILE, file);\r
file.setKeepInSync(true);\r
import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
+import com.owncloud.android.files.services.FileObserverService;\r
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
}\r
\r
// file observer\r
- /*Intent observer_intent = new Intent(this, FileObserverService.class);\r
+ Intent observer_intent = new Intent(this, FileObserverService.class);\r
observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);\r
startService(observer_intent);\r
- */\r
+ \r
\r
/// USER INTERFACE\r
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);\r
import com.owncloud.android.datamodel.FileDataStorageManager;\r
import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\r
+import com.owncloud.android.files.services.FileObserverService;\r
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
} else {\r
mContainerActivity.onFileStateChanged(); // put inside 'else' to not call it twice (here, and in the virtual click on fdDownloadBtn)\r
}\r
- /*\r
+ \r
Intent intent = new Intent(getActivity().getApplicationContext(),\r
FileObserverService.class);\r
intent.putExtra(FileObserverService.KEY_FILE_CMD,\r
FileObserverService.CMD_ADD_OBSERVED_FILE:\r
FileObserverService.CMD_DEL_OBSERVED_FILE));\r
intent.putExtra(FileObserverService.KEY_CMD_ARG, mFile.getStoragePath());\r
+ Log.e(TAG, "starting observer service");\r
getActivity().startService(intent);\r
- */\r
+ \r
break;\r
}\r
case R.id.fdRenameBtn: {\r