X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/91bc3fdb1eb923053b469b94e5b200482f522010..b0ab3ce0872d2702e82b5979dddaa5a897be340b:/src/com/owncloud/android/syncadapter/FileSyncAdapter.java diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 5f59475a..1e833753 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -26,11 +26,15 @@ import org.apache.http.HttpStatus; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; +import org.json.JSONObject; +import com.owncloud.android.AccountUtils; import com.owncloud.android.R; +import com.owncloud.android.authenticator.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; +import com.owncloud.android.utils.OwnCloudVersion; import android.accounts.Account; import android.app.Notification; @@ -90,11 +94,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { mDelaysIndex = 0; mDelaysCount = 0; */ - - + Log.d(TAG, "syncing owncloud account " + account.name); sendStickyBroadcast(true, null); // message to signal the start to the UI + + updateOCVersion(); String uri = getUri().toString(); PropFindMethod query = null; @@ -114,7 +119,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { fetchData(uri, syncResult, file.getFileId()); } } - + } else { syncResult.stats.numAuthExceptions++; } @@ -207,9 +212,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { .getModificationTimestamp()) { Intent intent = new Intent(this.getContext(), FileDownloader.class); intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount()); - intent.putExtra(FileDownloader.EXTRA_FILE_PATH, file.getRemotePath()); + intent.putExtra(FileDownloader.EXTRA_FILE, file); + /*intent.putExtra(FileDownloader.EXTRA_FILE_PATH, file.getRemotePath()); intent.putExtra(FileDownloader.EXTRA_REMOTE_PATH, file.getRemotePath()); - intent.putExtra(FileDownloader.EXTRA_FILE_SIZE, file.getFileLength()); + intent.putExtra(FileDownloader.EXTRA_FILE_SIZE, file.getFileLength());*/ file.setKeepInSync(true); getContext().startService(intent); } @@ -342,5 +348,32 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { } } - + private void updateOCVersion() { + String statUrl = getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_BASE_URL); + statUrl += AccountUtils.STATUS_PATH; + + try { + String result = getClient().getResultAsString(statUrl); + if (result != null) { + try { + JSONObject json = new JSONObject(result); + if (json != null && json.getString("version") != null) { + OwnCloudVersion ocver = new OwnCloudVersion(json.getString("version")); + if (ocver.isVersionValid()) { + getAccountManager().setUserData(getAccount(), AccountAuthenticator.KEY_OC_VERSION, ocver.toString()); + Log.d(TAG, "Got new OC version " + ocver.toString()); + } else { + Log.w(TAG, "Invalid version number received from server: " + json.getString("version")); + } + } + } catch (Throwable e) { + Log.w(TAG, "Couldn't parse version response", e); + } + } else { + Log.w(TAG, "Problem while getting ocversion from server"); + } + } catch (Exception e) { + Log.e(TAG, "Problem getting response from server", e); + } + } }