From: David A. Velasco Date: Thu, 11 Oct 2012 09:40:15 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/master' into cancel_in_upload X-Git-Tag: oc-android-1.4.3~155 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b0ab3ce0872d2702e82b5979dddaa5a897be340b?hp=5fc7cd13e7e561ef528e12d2fa088b58e35e00d0 Merge remote-tracking branch 'origin/master' into cancel_in_upload Conflicts: src/com/owncloud/android/ui/activity/FileDisplayActivity.java --- diff --git a/src/com/owncloud/android/db/DbHandler.java b/src/com/owncloud/android/db/DbHandler.java index ecc40980..01518bac 100644 --- a/src/com/owncloud/android/db/DbHandler.java +++ b/src/com/owncloud/android/db/DbHandler.java @@ -69,8 +69,8 @@ public class DbHandler { */ public boolean removeIUPendingFile(String localPath, String accountName) { return mDB.delete(TABLE_INSTANT_UPLOAD, - "path = ? and account = ?", - new String[]{ localPath, accountName }) != 0; + "path = ?", + new String[]{ localPath }) != 0; } diff --git a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java index f0c6004c..3c072382 100644 --- a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java +++ b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java @@ -50,6 +50,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + Log.d(TAG, "Received: " + intent.getAction()); if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) { handleConnectivityAction(context, intent); } else if (intent.getAction().equals(NEW_PHOTO_ACTION)) { @@ -86,7 +87,9 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { return; } - Cursor c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); + Cursor c = context.getContentResolver().query(intent.getData(), + CONTENT_PROJECTION, + null, null, null); if (!c.moveToFirst()) { Log.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); @@ -98,6 +101,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { String mime_type = c.getString(c.getColumnIndex(Media.MIME_TYPE)); c.close(); + Log.e(TAG, file_path+""); if (!isOnline(context) || (instantUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) { @@ -114,7 +118,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { // On the other hand this might be only for dynamicly registered // broadcast receivers, needs investigation. IntentFilter filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); - context.registerReceiver(this, filter); + context.getApplicationContext().registerReceiver(this, filter); Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); @@ -140,6 +144,8 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { DbHandler db = new DbHandler(context); Cursor c = db.getAwaitingFiles(); if (c.moveToFirst()) { + IntentFilter filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); + context.getApplicationContext().registerReceiver(this, filter); do { String account_name = c.getString(c.getColumnIndex("account")); String file_path = c.getString(c.getColumnIndex("path")); diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index e55d6186..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++; } @@ -343,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); + } + } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index b3202976..b6393a51 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -967,13 +967,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements return; } // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS - mFileList.listDirectory(); + if (mFileList != null) + mFileList.listDirectory(); if (mDualPane) { FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); if (fragment != null) fragment.updateFileDetails(); } - } @Override diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index a65e2d7c..4f6e66bd 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -172,28 +172,30 @@ public class OCFileListFragment extends FragmentListView { */ public void listDirectory(OCFile directory) { DataStorageManager storageManager = mContainerActivity.getStorageManager(); + if (storageManager != null) { - // Check input parameters for null - if(directory == null){ - if(mFile != null){ - directory = mFile; - } else { - directory = storageManager.getFileByPath("/"); - if (directory == null) return; // no files, wait for sync + // Check input parameters for null + if(directory == null){ + if(mFile != null){ + directory = mFile; + } else { + directory = storageManager.getFileByPath("/"); + if (directory == null) return; // no files, wait for sync + } } - } - // If that's not a directory -> List its parent - if(!directory.isDirectory()){ - Log.w(TAG, "You see, that is not a directory -> " + directory.toString()); - directory = storageManager.getFileById(directory.getParentId()); - } + // If that's not a directory -> List its parent + if(!directory.isDirectory()){ + Log.w(TAG, "You see, that is not a directory -> " + directory.toString()); + directory = storageManager.getFileById(directory.getParentId()); + } - mFile = directory; - mAdapter.swapDirectory(mFile); - mList.setSelectionFromTop(0, 0); - mList.invalidate(); + mFile = directory; + mAdapter.swapDirectory(mFile); + mList.setSelectionFromTop(0, 0); + mList.invalidate(); + } } diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index a451b3ee..6f98f500 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -336,5 +336,20 @@ public class WebdavClient extends HttpClient { public Uri getBaseUri() { return mUri; } + + public String getResultAsString(String targetUrl) { + String getResult = null; + try { + GetMethod get = new GetMethod(targetUrl); + int status = executeMethod(get); + if (status == HttpStatus.SC_OK) { + getResult = get.getResponseBodyAsString(); + } + } catch (Exception e) { + Log.e(TAG, "Error while getting requested file: " + targetUrl, e); + getResult = null; + } + return getResult; + } }