Merge remote-tracking branch 'origin/master' into cancel_in_upload
authorDavid A. Velasco <dvelasco@solidgear.es>
Thu, 11 Oct 2012 09:40:15 +0000 (11:40 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Thu, 11 Oct 2012 09:40:15 +0000 (11:40 +0200)
Conflicts:
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

src/com/owncloud/android/db/DbHandler.java
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java
src/com/owncloud/android/syncadapter/FileSyncAdapter.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/eu/alefzero/webdav/WebdavClient.java

index ecc4098..01518ba 100644 (file)
@@ -69,8 +69,8 @@ public class DbHandler {
      */\r
     public boolean removeIUPendingFile(String localPath, String accountName) {\r
         return mDB.delete(TABLE_INSTANT_UPLOAD,\r
-                          "path = ? and account = ?",\r
-                          new String[]{ localPath, accountName }) != 0;\r
+                          "path = ?",\r
+                          new String[]{ localPath }) != 0;\r
         \r
     }\r
     \r
index f0c6004..3c07238 100644 (file)
@@ -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"));
index e55d618..1e83375 100644 (file)
@@ -26,11 +26,15 @@ import org.apache.http.HttpStatus;
 import org.apache.jackrabbit.webdav.DavException;\r
 import org.apache.jackrabbit.webdav.MultiStatus;\r
 import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;\r
+import org.json.JSONObject;\r
 \r
+import com.owncloud.android.AccountUtils;\r
 import com.owncloud.android.R;\r
+import com.owncloud.android.authenticator.AccountAuthenticator;\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.utils.OwnCloudVersion;\r
 \r
 import android.accounts.Account;\r
 import android.app.Notification;\r
@@ -90,11 +94,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         mDelaysIndex = 0;\r
         mDelaysCount = 0;\r
         */\r
-        \r
-        \r
+\r
         Log.d(TAG, "syncing owncloud account " + account.name);\r
 \r
         sendStickyBroadcast(true, null);  // message to signal the start to the UI\r
+        \r
+        updateOCVersion();\r
 \r
         String uri = getUri().toString();\r
         PropFindMethod query = null;\r
@@ -114,7 +119,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                         fetchData(uri, syncResult, file.getFileId());\r
                     }\r
                 }\r
-                \r
+\r
             } else {\r
                 syncResult.stats.numAuthExceptions++;\r
             }\r
@@ -343,5 +348,32 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         }\r
     }\r
 \r
-    \r
+    private void updateOCVersion() {\r
+        String statUrl = getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_BASE_URL);\r
+        statUrl += AccountUtils.STATUS_PATH;\r
+        \r
+        try {\r
+            String result = getClient().getResultAsString(statUrl);\r
+            if (result != null) {\r
+                try {\r
+                    JSONObject json = new JSONObject(result);\r
+                    if (json != null && json.getString("version") != null) {\r
+                        OwnCloudVersion ocver = new OwnCloudVersion(json.getString("version"));\r
+                        if (ocver.isVersionValid()) {\r
+                            getAccountManager().setUserData(getAccount(), AccountAuthenticator.KEY_OC_VERSION, ocver.toString());\r
+                            Log.d(TAG, "Got new OC version " + ocver.toString());\r
+                        } else {\r
+                            Log.w(TAG, "Invalid version number received from server: " + json.getString("version"));\r
+                        }\r
+                    }\r
+                } catch (Throwable e) {\r
+                    Log.w(TAG, "Couldn't parse version response", e);\r
+                }\r
+            } else {\r
+                Log.w(TAG, "Problem while getting ocversion from server");\r
+            }\r
+        } catch (Exception e) {\r
+            Log.e(TAG, "Problem getting response from server", e);\r
+        }\r
+    }\r
 }\r
index b320297..b6393a5 100644 (file)
@@ -967,13 +967,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
                 return;\r
             }\r
             // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS\r
-            mFileList.listDirectory();\r
+            if (mFileList != null)\r
+                mFileList.listDirectory();\r
             if (mDualPane) {\r
                 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
                 if (fragment != null)\r
                     fragment.updateFileDetails();\r
             }\r
-            \r
         }\r
 \r
         @Override\r
index a65e2d7..4f6e66b 100644 (file)
@@ -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();
+        }
     }
     
     
index a451b3e..6f98f50 100644 (file)
@@ -336,5 +336,20 @@ public class WebdavClient extends HttpClient {
     public Uri getBaseUri() {\r
         return mUri;\r
     }\r
+\r
+    public String getResultAsString(String targetUrl) {\r
+        String getResult = null;\r
+        try {\r
+            GetMethod get = new GetMethod(targetUrl);\r
+            int status = executeMethod(get);\r
+            if (status == HttpStatus.SC_OK) {\r
+                getResult = get.getResponseBodyAsString();\r
+            }\r
+        } catch (Exception e) {\r
+            Log.e(TAG, "Error while getting requested file: " + targetUrl, e);\r
+            getResult = null;\r
+        }\r
+        return getResult;\r
+    }\r
     \r
 }\r