Non-previewable file is opened after successful donwload
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
index 0c274c8..1c5cb38 100644 (file)
@@ -116,7 +116,6 @@ public class FileDisplayActivity extends FileActivity implements
     private OCFileListFragment mFileList;
     
     private boolean mDualPane;
-    private boolean mBackFromCreatingFirstAccount;
     
     public static final int DIALOG_SHORT_WAIT = 0;
     private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
@@ -135,7 +134,7 @@ public class FileDisplayActivity extends FileActivity implements
     private boolean mStarted;
 
     @Override
-    public void onCreate(Bundle savedInstanceState) {
+    protected void onCreate(Bundle savedInstanceState) {
         Log_OC.d(TAG, "onCreate() start");
         super.onCreate(savedInstanceState);
         
@@ -195,8 +194,6 @@ public class FileDisplayActivity extends FileActivity implements
         actionBar.setListNavigationCallbacks(mDirectories, this);
         setSupportProgressBarIndeterminateVisibility(false);        // always AFTER setContentView(...) ; to workaround bug in its implementation
         
-        mBackFromCreatingFirstAccount = false;
-        
         Log_OC.d(TAG, "onCreate() end");
     }
 
@@ -216,17 +213,15 @@ public class FileDisplayActivity extends FileActivity implements
         if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {
             FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
             if (mChosenFile != null) {
-                if (PreviewMediaFragment.canBePreviewed(mChosenFile)) {
-                    if (mChosenFile.isDown()) {
-                        int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
-                        boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
-                        transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mChosenFile, getAccount(), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
-                    } else {
-                        transaction.replace(R.id.file_details_container, new FileDetailFragment(mChosenFile, getAccount()), FileDetailFragment.FTAG);
+                if (!mChosenFile.isDown()) {
+                    transaction.replace(R.id.file_details_container, new FileDetailFragment(mChosenFile, getAccount()), FileDetailFragment.FTAG);
+                    if (getIntent().getBooleanExtra(EXTRA_WAITING_TO_PREVIEW, false)) {
                         mWaitingToPreview = mChosenFile;
                     }
-                } else {
-                    transaction.replace(R.id.file_details_container, new FileDetailFragment(mChosenFile, getAccount()), FileDetailFragment.FTAG);
+                } else if (PreviewMediaFragment.canBePreviewed(mChosenFile)) {
+                    int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
+                    boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
+                    transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mChosenFile, getAccount(), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
                 }
                 mChosenFile = null;
                 
@@ -239,7 +234,7 @@ public class FileDisplayActivity extends FileActivity implements
     
     
     @Override
-    public void onStart() {
+    protected void onStart() {
         super.onStart();
         if (mNewConfigurationChangeToApplyOnStart != null) {
             checkConfigurationChange(mNewConfigurationChangeToApplyOnStart);
@@ -249,7 +244,7 @@ public class FileDisplayActivity extends FileActivity implements
     }
     
     @Override
-    public void onStop() {
+    protected void onStop() {
         super.onStop();
         mStarted = false;
     }
@@ -270,15 +265,15 @@ public class FileDisplayActivity extends FileActivity implements
         } else {
             finish();
             Intent intent = new Intent(this, FileDisplayActivity.class);
-            intent.putExtra(FileDetailFragment.EXTRA_FILE, getFile());
-            intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getAccount());
+            intent.putExtra(EXTRA_FILE, getFile());
+            intent.putExtra(EXTRA_ACCOUNT, getAccount());
             startActivity(intent);
         }
     }
 
 
     @Override
-    public void onDestroy() {
+    protected void onDestroy() {
         super.onDestroy();
         if (mDownloadConnection != null)
             unbindService(mDownloadConnection);
@@ -356,7 +351,7 @@ public class FileDisplayActivity extends FileActivity implements
     /**
      * Called, when the user selected something for uploading
      */
-    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         
         if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
@@ -482,7 +477,7 @@ public class FileDisplayActivity extends FileActivity implements
             if (fragment != null) {
                 OCFile file = fragment.getFile();
                 if (file != null) {
-                    outState.putParcelable(FileActivity.EXTRA_FILE, file);
+                    outState.putParcelable(EXTRA_FILE, file);
                 }
             }
         }
@@ -733,13 +728,6 @@ public class FileDisplayActivity extends FileActivity implements
                 setFile(currentDir);
                 
                 setSupportProgressBarIndeterminateVisibility(inProgress);
-                if (mBackFromCreatingFirstAccount) {
-                    // awful patch to fix problem with visibility of progress circle with the first refresh of the first account
-                    // TODO - kill this Activity when the first account has to be created instead of stack the account creation on it
-                    getSupportActionBar().hide();
-                    getSupportActionBar().show();
-                    mBackFromCreatingFirstAccount = false;
-                }
                 removeStickyBroadcast(intent);
                 
             }
@@ -838,9 +826,15 @@ public class FileDisplayActivity extends FileActivity implements
                 //  update the right panel 
                 if (success && waitedPreview) {
                     mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId());   // update the file from database, for the local storage path
-                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-                    transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, getAccount(), 0, true), FileDetailFragment.FTAG);
-                    transaction.commit();
+                    if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
+                        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+                        transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, getAccount(), 0, true), FileDetailFragment.FTAG);
+                        transaction.commit();
+                    } else {
+                        detailsFragment.updateFileDetails(false, (success));
+                        openFile(mWaitingToPreview);
+                        
+                    }
                     mWaitingToPreview = null;
                     
                 } else {
@@ -886,42 +880,47 @@ public class FileDisplayActivity extends FileActivity implements
      */
     @Override
     public void onFileClick(OCFile file, boolean onOrientationChange) {
-        if (file != null && PreviewImageFragment.canBePreviewed(file)) {
-            // preview image - it handles the download, if needed
-            startPreviewImage(file);
-            
-        } else if (file != null && PreviewMediaFragment.canBePreviewed(file)) {
-            if (file.isDown()) {
-                // general preview
-                if (!onOrientationChange) {
-                    startMediaPreview(file, 0, true, onOrientationChange);
-                } else {
-                    int startPlaybackPosition = 0;
-                    boolean autoplay = true;
-                    Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-                    if (fragment != null && file.isVideo()) {
-                        PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
-                        startPlaybackPosition = videoFragment.getPosition();
-                        autoplay = videoFragment.isPlaying();
+        if (file != null) {
+            if (PreviewImageFragment.canBePreviewed(file)) {
+                // preview image - it handles the download, if needed
+                startPreviewImage(file);
+                
+            } else if (PreviewMediaFragment.canBePreviewed(file)) {
+                if (file.isDown()) {
+                    // general preview
+                    if (!onOrientationChange) {
+                        startMediaPreview(file, 0, true, onOrientationChange);
+                    } else {
+                        int startPlaybackPosition = 0;
+                        boolean autoplay = true;
+                        Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+                        if (fragment != null && file.isVideo()) {
+                            PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
+                            startPlaybackPosition = videoFragment.getPosition();
+                            autoplay = videoFragment.isPlaying();
+                        }
+                        startMediaPreview(file, startPlaybackPosition, autoplay, onOrientationChange);
                     }
-                    startMediaPreview(file, startPlaybackPosition, autoplay, onOrientationChange);
+                    
+                } else {
+                    // automatic download, preview on finish
+                    startDownloadForPreview(file, onOrientationChange);
+                    
                 }
                 
+            } else if (file.isDown()) {
+                // details view
+                startDetails(file, onOrientationChange);
             } else {
-                // automatic download, preview on finish
                 startDownloadForPreview(file, onOrientationChange);
-                
             }
-        } else {
-            // details view
-            startDetails(file, onOrientationChange);
         }
     }
 
     private void startPreviewImage(OCFile file) {
         Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
-        showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
-        showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getAccount());
+        showDetailsIntent.putExtra(EXTRA_FILE, file);
+        showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
         startActivity(showDetailsIntent);
     }
     
@@ -933,8 +932,8 @@ public class FileDisplayActivity extends FileActivity implements
             
         } else {
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getAccount());
+            showDetailsIntent.putExtra(EXTRA_FILE, file);
+            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
             showDetailsIntent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, startPlaybackPosition);
             showDetailsIntent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, autoplay);
             startActivity(showDetailsIntent);
@@ -951,8 +950,8 @@ public class FileDisplayActivity extends FileActivity implements
             
         } else {
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getAccount());
+            showDetailsIntent.putExtra(EXTRA_FILE, file);
+            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
             startActivity(showDetailsIntent);
         }
     }
@@ -965,8 +964,8 @@ public class FileDisplayActivity extends FileActivity implements
             transaction.commit();
         } else {
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getAccount());
+            showDetailsIntent.putExtra(EXTRA_FILE, file);
+            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
             startActivity(showDetailsIntent);
         }
     }
@@ -1263,8 +1262,8 @@ public class FileDisplayActivity extends FileActivity implements
             
         } else {
             Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
-            showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getAccount());
+            showDetailsIntent.putExtra(EXTRA_FILE, file);
+            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
             showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
             startActivity(showDetailsIntent);
         }