import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.files.OwnCloudFileObserver;
+import com.owncloud.android.files.OwnCloudFileObserver.FileObserverStatusListener;
+import com.owncloud.android.ui.activity.ConflictsResolveActivity;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.os.IBinder;
import android.util.Log;
-public class FileObserverService extends Service {
+public class FileObserverService extends Service implements FileObserverStatusListener {
public final static String KEY_FILE_CMD = "KEY_FILE_CMD";
public final static String KEY_CMD_ARG = "KEY_CMD_ARG";
observer.setAccount(account);
observer.setStorageManager(storage);
observer.setOCFile(storage.getFileByPath(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH))));
+ observer.addObserverStatusListener(this);
observer.startWatching();
mObservers.add(observer);
Log.d(TAG, "Started watching file " + path);
new FileDataStorageManager(account, getContentResolver());
observer.setStorageManager(storage);
observer.setOCFile(storage.getFileByLocalPath(path));
+ observer.addObserverStatusListener(this);
DownloadCompletedReceiver receiver = new DownloadCompletedReceiver(path, observer);
registerReceiver(receiver, new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE));
mDownloadReceivers.remove(r);
}
}
-
+
+ @Override
+ public void OnObservedFileStatusUpdate(String localPath, String remotePath, Account account, Status status) {
+ switch (status) {
+ case CONFLICT:
+ {
+ Intent i = new Intent(getApplicationContext(), ConflictsResolveActivity.class);
+ i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
+ i.putExtra("remotepath", remotePath);
+ i.putExtra("localpath", localPath);
+ i.putExtra("account", account);
+ startActivity(i);
+ break;
+ }
+ case SENDING_TO_UPLOADER:
+ case INCORRECT_MASK:
+ break;
+ default:
+ Log.wtf(TAG, "Unhandled status " + status);
+ }
+ }
+
private class DownloadCompletedReceiver extends BroadcastReceiver {
String mPath;
OwnCloudFileObserver mObserver;