Merge pull request #73 from s17t/master
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 14 Jan 2013 10:23:03 +0000 (02:23 -0800)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 14 Jan 2013 10:23:03 +0000 (02:23 -0800)
Minor changes

src/com/owncloud/android/Uploader.java
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/files/services/FileDownloader.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/operations/RemoteOperationResult.java
src/com/owncloud/android/ui/activity/UploadFilesActivity.java
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

index 138f68e..e19a972 100644 (file)
@@ -325,58 +325,24 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
         mFile = mStorageManager.getFileByPath(full_path);\r
         if (mFile != null) {\r
             Vector<OCFile> files = mStorageManager.getDirectoryContent(mFile);\r
-            if (files.size() > 0) {\r
-                List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();\r
-                for (OCFile f : files) {\r
-                    HashMap<String, Object> h = new HashMap<String, Object>();\r
-                    if (f.isDirectory()) {\r
-                        h.put("dirname", f.getFileName());\r
-                        data.add(h);\r
-                    }\r
+            List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();\r
+            for (OCFile f : files) {\r
+                HashMap<String, Object> h = new HashMap<String, Object>();\r
+                if (f.isDirectory()) {\r
+                    h.put("dirname", f.getFileName());\r
+                    data.add(h);\r
                 }\r
-                SimpleAdapter sa = new SimpleAdapter(this,\r
-                                                     data,\r
-                                                     R.layout.uploader_list_item_layout,\r
-                                                     new String[] {"dirname"},\r
-                                                     new int[] {R.id.textView1});\r
-                setListAdapter(sa);\r
-                Button btn = (Button) findViewById(R.id.uploader_choose_folder);\r
-                btn.setOnClickListener(this);\r
-                getListView().setOnItemClickListener(this);\r
             }\r
-        }\r
-        /*\r
-        mCursor = managedQuery(ProviderMeta.ProviderTableMeta.CONTENT_URI, null, ProviderTableMeta.FILE_NAME\r
-                + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", new String[] { "/", mAccount.name }, null);\r
-\r
-        if (mCursor.moveToFirst()) {\r
-            mCursor = managedQuery(\r
-                    ProviderMeta.ProviderTableMeta.CONTENT_URI,\r
-                    null,\r
-                    ProviderTableMeta.FILE_CONTENT_TYPE + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND "\r
-                            + ProviderTableMeta.FILE_PARENT + "=?",\r
-                    new String[] { "DIR", mAccount.name,\r
-                            mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID)) }, null);\r
-\r
-            ListView lv = getListView();\r
-            lv.setOnItemClickListener(this);\r
-            SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.uploader_list_item_layout, mCursor,\r
-                    new String[] { ProviderTableMeta.FILE_NAME }, new int[] { R.id.textView1 });\r
-            setListAdapter(sca);\r
+            SimpleAdapter sa = new SimpleAdapter(this,\r
+                                                data,\r
+                                                R.layout.uploader_list_item_layout,\r
+                                                new String[] {"dirname"},\r
+                                                new int[] {R.id.textView1});\r
+            setListAdapter(sa);\r
             Button btn = (Button) findViewById(R.id.uploader_choose_folder);\r
             btn.setOnClickListener(this);\r
-            /*\r
-             * disable this until new server interaction service wont be created\r
-             * // insert create new directory for multiple items uploading if\r
-             * (getIntent().getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {\r
-             * Button createDirBtn = new Button(this);\r
-             * createDirBtn.setId(android.R.id.button1);\r
-             * createDirBtn.setText(R.string.uploader_btn_create_dir_text);\r
-             * createDirBtn.setOnClickListener(this); ((LinearLayout)\r
-             * findViewById(R.id.linearLayout1)).addView( createDirBtn,\r
-             * LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); }\r
-             *\r
-        }*/\r
+            getListView().setOnItemClickListener(this);\r
+        }\r
     }\r
 \r
     private boolean prepareStreamsToUpload() {\r
index 50baf17..987e291 100644 (file)
@@ -46,9 +46,9 @@ public class FileDataStorageManager implements DataStorageManager {
     private ContentResolver mContentResolver;
     private ContentProviderClient mContentProvider;
     private Account mAccount;
-
+    
     private static String TAG = "FileDataStorageManager";
-
+    
     public FileDataStorageManager(Account account, ContentResolver cr) {
         mContentProvider = null;
         mContentResolver = cr;
@@ -69,9 +69,21 @@ public class FileDataStorageManager implements DataStorageManager {
             file = createFileInstance(c);
         }
         c.close();
+        if (file == null && OCFile.PATH_SEPARATOR.equals(path)) {
+            return createRootDir(); // root should always exist
+        }
         return file;
     }
+
     
+    private OCFile createRootDir() {
+        OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
+        file.setMimetype("DIR");
+        file.setParentId(DataStorageManager.ROOT_PARENT_ID);
+        saveFile(file);
+        return file;
+    }
+
     @Override
     public OCFile getFileById(long id) {
         Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
@@ -476,9 +488,9 @@ public class FileDataStorageManager implements DataStorageManager {
                         }
                     }
                 }
-                if (removeDBData) {
-                    removeFile(dir, true);
-                }
+            }
+            if (removeDBData) {
+                removeFile(dir, true);
             }
         }
     }
index b01d61e..7872c36 100644 (file)
@@ -198,6 +198,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
          * @param file          A file that could be in the queue of downloads.\r
          */\r
         public boolean isDownloading(Account account, OCFile file) {\r
+            if (account == null || file == null) return false;\r
             String targetKey = buildRemoteName(account, file);\r
             synchronized (mPendingDownloads) {\r
                 if (file.isDirectory()) {\r
index 0887ac1..0a03346 100644 (file)
@@ -324,6 +324,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
          * @param file          A file that could be in the queue of pending uploads
          */
         public boolean isUploading(Account account, OCFile file) {
+            if (account == null || file == null) return false;
             String targetKey = buildRemoteName(account, file);
             synchronized (mPendingUploads) {
                 if (file.isDirectory()) {
index cae4569..6470338 100644 (file)
@@ -45,7 +45,7 @@ import com.owncloud.android.network.CertificateCombinedException;
 public class RemoteOperationResult implements Serializable {
     
     /** Generated - should be refreshed every time the class changes!! */
-    private static final long serialVersionUID = 5336333154035462033L;
+    private static final long serialVersionUID = -7805531062432602444L;
 
     
     public enum ResultCode { 
@@ -79,7 +79,6 @@ public class RemoteOperationResult implements Serializable {
     private int mHttpCode = -1;
     private Exception mException = null;
     private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
-    private Object mExtraData = null;
     
     public RemoteOperationResult(ResultCode code) {
         mCode = code;
@@ -177,14 +176,6 @@ public class RemoteOperationResult implements Serializable {
         return mCode == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED;
     }
     
-    public void setExtraData(Object data) {
-        mExtraData = data;
-    }
-    
-    public Object getExtraData() {
-        return mExtraData;
-    }
-    
     private CertificateCombinedException getCertificateCombinedException(Exception e) {
         CertificateCombinedException result = null;
         if (e instanceof CertificateCombinedException) {
index 3487d70..f2c36af 100644 (file)
@@ -140,7 +140,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
                 break;
             }
             default:
-                retval = onOptionsItemSelected(item);
+                retval = super.onOptionsItemSelected(item);
         }
         return retval;
     }
@@ -314,7 +314,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements
         protected Boolean doInBackground(Void... params) {
             String[] checkedFilePaths = mFileListFragment.getCheckedFilePaths();
             long total = 0;
-            for (int i=0; i < checkedFilePaths.length ; i++) {
+            for (int i=0; checkedFilePaths != null && i < checkedFilePaths.length ; i++) {
                 String localPath = checkedFilePaths[i];
                 File localFile = new File(localPath);
                 total += localFile.length();
index 5197d67..2c43278 100644 (file)
@@ -155,10 +155,6 @@ public class FileDetailFragment extends SherlockFragment implements
         mAccount = ocAccount;\r
         mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment \r
         mLayout = R.layout.file_details_empty;\r
-        \r
-        if(fileToDetail != null && ocAccount != null) {\r
-            mLayout = R.layout.file_details_fragment;\r
-        }\r
     }\r
     \r
     \r
@@ -179,6 +175,10 @@ public class FileDetailFragment extends SherlockFragment implements
             mAccount = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_ACCOUNT);\r
         }\r
         \r
+        if(mFile != null && mAccount != null) {\r
+            mLayout = R.layout.file_details_fragment;\r
+        }\r
+        \r
         View view = null;\r
         view = inflater.inflate(mLayout, container, false);\r
         mView = view;\r
@@ -461,7 +461,7 @@ public class FileDetailFragment extends SherlockFragment implements
      * @return  True when the fragment was created with the empty layout.\r
      */\r
     public boolean isEmpty() {\r
-        return mLayout == R.layout.file_details_empty;\r
+        return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null);\r
     }\r
 \r
     \r
@@ -736,14 +736,14 @@ public class FileDetailFragment extends SherlockFragment implements
                 if (mFile.getRemotePath().equals(uploadRemotePath) ||\r
                     renamedInUpload) {\r
                     if (uploadWasFine) {\r
-                        mFile = mStorageManager.getFileByPath(mFile.getRemotePath());\r
+                        mFile = mStorageManager.getFileByPath(uploadRemotePath);\r
                     }\r
                     if (renamedInUpload) {\r
                         String newName = (new File(uploadRemotePath)).getName();\r
                         Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG);\r
                         msg.show();\r
-                        getSherlockActivity().removeStickyBroadcast(intent);    // not the best place to do this; a small refactorization of BroadcastReceivers should be done\r
                     }\r
+                    getSherlockActivity().removeStickyBroadcast(intent);    // not the best place to do this; a small refactorization of BroadcastReceivers should be done\r
                     updateFileDetails(false);    // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
                 }\r
             }\r