Merge pull request #268 from owncloud/fix_fails_in_uploads_after_fall_and_rise_of_net...
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / preview / PreviewImageActivity.java
index 9ce0588..50cab7e 100644 (file)
@@ -16,8 +16,6 @@
  */
 package com.owncloud.android.ui.preview;
 
-import android.app.Dialog;
-import android.app.ProgressDialog;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
@@ -105,7 +103,10 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     }
 
     private void initViewPager() {
-        OCFile parentFolder = mStorageManager.getFileById(getFile().getParentId());
+        // get parent from path
+        String parentPath = getFile().getRemotePath().substring(0, getFile().getRemotePath().lastIndexOf(getFile().getFileName()));
+        OCFile parentFolder = mStorageManager.getFileByPath(parentPath);
+        //OCFile parentFolder = mStorageManager.getFileById(getFile().getParentId());
         if (parentFolder == null) {
             // should not be necessary
             parentFolder = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
@@ -153,7 +154,7 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
                     Log_OC.d(TAG, "Simulating reselection of current page after connection of download binder");
                     onPageSelected(mViewPager.getCurrentItem());
                 }
-                    
+
             } else if (component.equals(new ComponentName(PreviewImageActivity.this, FileUploader.class))) {
                 Log_OC.d(TAG, "Upload service connected");
                 mUploaderBinder = (FileUploaderBinder) service;
@@ -241,27 +242,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         finish();
     }
     
-    
-//    @Override
-//    protected Dialog onCreateDialog(int id) {
-//        Dialog dialog = null;
-//        switch (id) {
-//        case DIALOG_SHORT_WAIT: {
-//            ProgressDialog working_dialog = new ProgressDialog(this);
-//            working_dialog.setMessage(getResources().getString(
-//                    R.string.wait_a_moment));
-//            working_dialog.setIndeterminate(true);
-//            working_dialog.setCancelable(false);
-//            dialog = working_dialog;
-//            break;
-//        }
-//        default:
-//            dialog = null;
-//        }
-//        return dialog;
-//    }
-    
-    
     /**
      * Show loading dialog 
      */
@@ -451,8 +431,12 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
             if (!file.isImage()) {
                 throw new IllegalArgumentException("Non-image file passed as argument");
             }
-            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
-            file = mStorageManager.getFileById(file.getFileId()); 
+            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());            
+            
+            // Update file according to DB file, if it is possible
+            if (file.getFileId() > DataStorageManager.ROOT_PARENT_ID)            
+                file = mStorageManager.getFileById(file.getFileId());
+            
             if (file != null) {
                 /// Refresh the activity according to the Account and OCFile set
                 setFile(file);  // reset after getting it fresh from mStorageManager