Merge remote-tracking branch 'origin/develop' into check_account_existance_in_gallery
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 17 Jun 2013 10:28:42 +0000 (12:28 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 17 Jun 2013 10:28:42 +0000 (12:28 +0200)
AndroidManifest.xml
res/layout/video_layout.xml
res/values/styles.xml
src/com/owncloud/android/ui/activity/FileActivity.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/com/owncloud/android/ui/preview/PreviewImageActivity.java
src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java
src/com/owncloud/android/ui/preview/PreviewVideoActivity.java

index ee9ecaf..d5cae03 100644 (file)
@@ -95,7 +95,7 @@
                        
         <activity      android:name="com.owncloud.android.ui.preview.PreviewVideoActivity"
                                        android:label="@string/app_name"
-                                       android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
+                                       android:theme="@style/Theme.ownCloud.Fullscreen" >
                </activity>        
 
         <service
index 8781ad8..dfa29f7 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout   xmlns:android="http://schemas.android.com/apk/res/android"
-                               android:layout_width="fill_parent"
-                               android:layout_height="fill_parent" >
+                               android:layout_width="match_parent"
+                               android:layout_height="match_parent" >
 
        <VideoView  android:id="@+id/videoPlayer"
                                android:layout_width="wrap_content"
index 161f5d3..13d0ed2 100644 (file)
@@ -17,7 +17,7 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<resources>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
        <style name="Animations" />
 
        <!-- Default ownCloud app style -->
        <style name="Theme.ownCloud.noActionBar" parent="style/Theme.Sherlock.Light.NoActionBar">
       <item name="android:actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
       <item name="actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
-  </style>
+    </style>
+       
+       <style name="Theme.ownCloud.Fullscreen" parent="style/Theme.Sherlock.NoActionBar">
+      <item name="android:actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
+      <item name="actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
+      <item name="android:windowFullscreen">true</item>
+    </style>
+       
        
-
        <style name="Theme.ownCloud.Widget.ActionBar" parent="style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/main_header_bg</item>
        <item name="background">@drawable/main_header_bg</item>
index d645d6e..52f5c2b 100644 (file)
@@ -60,6 +60,12 @@ public abstract class FileActivity extends SherlockFragmentActivity {
     /** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud {@link Account} */
     private boolean mRedirectingToSetupAccount = false;
     
+    /** Flag to signal when the value of mAccount was set */ 
+    private boolean mAccountWasSet;
+    
+    /** Flag to signal when the value of mAccount was restored from a saved state */ 
+    private boolean mAccountWasRestored;
+    
 
     /**
      * Loads the cownCloud {@link Account} and main {@link OCFile} to be handled by the instance of 
@@ -80,9 +86,14 @@ public abstract class FileActivity extends SherlockFragmentActivity {
             mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
         }
 
+        Account oldAccount = mAccount;
         grantValidAccount();
         if (mAccount != null) {
-            onAccountSet(savedInstanceState != null);
+            mAccountWasSet = true;
+            mAccountWasRestored = (savedInstanceState != null && mAccount.equals(oldAccount));
+        } else {
+            mAccountWasSet = false;
+            mAccountWasRestored = false;
         }
     }
 
@@ -99,11 +110,15 @@ public abstract class FileActivity extends SherlockFragmentActivity {
         Account oldAccount = mAccount;
         grantValidAccount();
         if (mAccount != null && !mAccount.equals(oldAccount)) {
-            onAccountSet(false);
+            mAccountWasSet = true;
+            mAccountWasRestored = false;
+        } else {
+            mAccountWasSet = false;
+            mAccountWasRestored = false;
         }
     }
+
     
-        
     /**
      *  Validates the ownCloud {@link Account} associated to the Activity any time it is restarted.
      * 
@@ -126,6 +141,16 @@ public abstract class FileActivity extends SherlockFragmentActivity {
     }
     
     
+    @Override 
+    protected void onStart() {
+        // maybe better in onPostCreate() ?
+        super.onStart();
+        if (mAccountWasSet) {
+            onAccountSet(mAccountWasRestored);
+        }
+    }
+    
+    
     /**
      * Launches the account creation activity. To use when no ownCloud account is available
      */
@@ -214,7 +239,7 @@ public abstract class FileActivity extends SherlockFragmentActivity {
                         FileActivity.this.onAccountSet(false);
                     }
                 } catch (OperationCanceledException e) {
-                    Log_OC.e(TAG, "Account creation canceled");
+                    Log_OC.d(TAG, "Account creation canceled");
                     
                 } catch (Exception e) {
                     Log_OC.e(TAG, "Account creation finished in exception: ", e);
@@ -224,7 +249,7 @@ public abstract class FileActivity extends SherlockFragmentActivity {
                 Log_OC.e(TAG, "Account creation callback with null bundle");
             }
             if (mAccount == null) {
-                finish();
+                moveTaskToBack(true);
             }
         }
         
index 9896a92..a70e266 100644 (file)
@@ -137,9 +137,9 @@ public class FileDisplayActivity extends FileActivity implements
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         Log_OC.d(TAG, "onCreate() start");
-        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+        super.onCreate(savedInstanceState);
         
-        super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account is valid
+        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
         
         mHandler = new Handler();
 
@@ -176,26 +176,12 @@ public class FileDisplayActivity extends FileActivity implements
         mRightFragmentContainer = findViewById(R.id.right_fragment_container);
         if (savedInstanceState == null) {
             createMinFragments();
-            if (!isRedirectingToSetupAccount()) {
-                initFragmentsWithFile();
-            }
         }
         
         // Action bar setup
         mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
-        OCFile currFile = getFile();
-        if (mStorageManager != null) {
-            while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
-                if (currFile.isDirectory()) {
-                    mDirectories.add(currFile.getFileName());
-                }
-                currFile = mStorageManager.getFileById(currFile.getParentId());
-            }
-        }
-        mDirectories.add(OCFile.PATH_SEPARATOR);
-        ActionBar actionBar = getSupportActionBar();
-        actionBar.setHomeButtonEnabled(true);   // mandatory since Android ICS, according to the official documentation
-        setSupportProgressBarIndeterminateVisibility(false);        // always AFTER setContentView(...) ; to workaround bug in its implementation
+        getSupportActionBar().setHomeButtonEnabled(true);       // mandatory since Android ICS, according to the official documentation
+        setSupportProgressBarIndeterminateVisibility(false);    // always AFTER setContentView(...) ; to work around bug in its implementation
         
         Log_OC.d(TAG, "onCreate() end");
     }
@@ -226,17 +212,28 @@ public class FileDisplayActivity extends FileActivity implements
             }
             if (file == null) {
                 // fall back to root folder
-                file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);  // never should return null
+                file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);  // never returns null
             }
             setFile(file);
-            
-            if (findViewById(android.R.id.content) != null && !stateWasRecovered) {
+            mDirectories.clear();
+            OCFile fileIt = file;
+            while(fileIt != null && fileIt.getFileName() != OCFile.PATH_SEPARATOR) {
+                if (fileIt.isDirectory()) {
+                    mDirectories.add(fileIt.getFileName());
+                }
+                fileIt = mStorageManager.getFileById(fileIt.getParentId());
+            }
+            mDirectories.add(OCFile.PATH_SEPARATOR);
+            if (!stateWasRecovered) {
                 Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
                 initFragmentsWithFile();
+                
             } else {
-                Log_OC.e(TAG, "Fragment initializacion ignored in onAccountChanged due to lack of CONTENT VIEW");
+                updateFragmentsVisibility(!file.isDirectory());
+                updateNavigationElementsInActionBar(file.isDirectory() ? null : file);
             }
             
+            
         } else {
             Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
         }
@@ -252,11 +249,24 @@ public class FileDisplayActivity extends FileActivity implements
 
     private void initFragmentsWithFile() {
         if (getAccount() != null && getFile() != null) {
+            /// First fragment
+            OCFileListFragment listOfFiles = getListOfFilesFragment(); 
+            if (listOfFiles != null) {
+                listOfFiles.listDirectory(getCurrentDir());   
+            } else {
+                Log.e(TAG, "Still have a chance to lose the initializacion of list fragment >(");
+            }
+            
             /// Second fragment
             OCFile file = getFile(); 
             Fragment secondFragment = chooseInitialSecondFragment(file);
             if (secondFragment != null) {
                 setSecondFragment(secondFragment);
+                updateFragmentsVisibility(true);
+                updateNavigationElementsInActionBar(file);
+                
+            } else {
+                cleanSecondFragment();
             }
             
         } else {
@@ -352,8 +362,9 @@ public class FileDisplayActivity extends FileActivity implements
             FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
             tr.remove(second);
             tr.commit();
-            updateFragmentsVisibility(false);
         }
+        updateFragmentsVisibility(false);
+        updateNavigationElementsInActionBar(null);
     }
     
     protected void refeshListOfFilesFragment() {
@@ -578,7 +589,6 @@ public class FileDisplayActivity extends FileActivity implements
             setFile(listOfFiles.getCurrentFile());
         }
         cleanSecondFragment();
-        updateNavigationElementsInActionBar(null);
     }
 
     @Override
@@ -589,14 +599,7 @@ public class FileDisplayActivity extends FileActivity implements
         outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
         Log_OC.d(TAG, "onSaveInstanceState() end");
     }
-    
-    @Override
-    protected void onStart() {
-        super.onStart();
-        FileFragment second = getSecondFragment();
-        updateFragmentsVisibility(second != null);
-        updateNavigationElementsInActionBar((second == null) ? null : second.getFile());
-    }
+
     
     @Override
     protected void onResume() {
@@ -619,12 +622,6 @@ public class FileDisplayActivity extends FileActivity implements
         mDownloadFinishReceiver = new DownloadFinishReceiver();
         registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
     
-        // List current directory
-        OCFileListFragment listOfFiles = getListOfFilesFragment(); 
-        if (listOfFiles != null) {
-            listOfFiles.listDirectory(getCurrentDir());   // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
-        }
-    
         Log_OC.d(TAG, "onResume() end");
     }
 
@@ -930,7 +927,6 @@ public class FileDisplayActivity extends FileActivity implements
     public void onBrowsedDownTo(OCFile directory) {
         pushDirname(directory);
         cleanSecondFragment();
-        updateNavigationElementsInActionBar(null);
     }
     
     /**
@@ -1000,9 +996,9 @@ public class FileDisplayActivity extends FileActivity implements
     /**
      * TODO
      */
-    private void updateNavigationElementsInActionBar(OCFile currentFile) {
+    private void updateNavigationElementsInActionBar(OCFile chosenFile) {
         ActionBar actionBar = getSupportActionBar(); 
-        if (currentFile == null || mDualPane) {
+        if (chosenFile == null || mDualPane) {
             // only list of files - set for browsing through folders
             OCFile currentDir = getCurrentDir();
             actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0);
@@ -1013,7 +1009,7 @@ public class FileDisplayActivity extends FileActivity implements
         } else {
             actionBar.setDisplayHomeAsUpEnabled(true);
             actionBar.setDisplayShowTitleEnabled(true);
-            actionBar.setTitle(currentFile.getFileName());
+            actionBar.setTitle(chosenFile.getFileName());
             actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
         }
     }
@@ -1023,15 +1019,6 @@ public class FileDisplayActivity extends FileActivity implements
      * {@inheritDoc}
      */
     @Override
-    public OCFile getInitialDirectory() {
-        return getCurrentDir();
-    }
-    
-    
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     public void onFileStateChanged() {
         refeshListOfFilesFragment();
     }
@@ -1329,12 +1316,11 @@ public class FileDisplayActivity extends FileActivity implements
         if (file != null) {
             if (file.isDirectory()) {
                 return file;
-            } else {
+            } else if (mStorageManager != null) {
                 return mStorageManager.getFileById(file.getParentId());
             }
-        } else {
-            return null;
         }
+        return null;
     }
 
 }
index 80f5358..b05ba28 100644 (file)
@@ -51,19 +51,14 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     private Context mContext;\r
     private OCFile mFile = null;\r
     private Vector<OCFile> mFiles = null;\r
-    private DataStorageManager mStorageManager;\r
+    private DataStorageManager mStorageManager = null;\r
     private Account mAccount;\r
     private TransferServiceGetter mTransferServiceGetter;\r
 \r
-    public FileListListAdapter(OCFile file, DataStorageManager storage_man,\r
-            Context context, TransferServiceGetter transferServiceGetter) {\r
-        mStorageManager = storage_man;\r
+    public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter) {\r
         mContext = context;\r
         mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
         mTransferServiceGetter = transferServiceGetter;\r
-        swapDirectory(file, mStorageManager);\r
-        /*mFile = file;\r
-        mFiles = mStorageManager.getDirectoryContent(mFile);*/\r
     }\r
 \r
     @Override\r
index 35b3774..015ebaa 100644 (file)
@@ -94,7 +94,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         Log_OC.e(TAG, "onActivityCreated() start");
-        mAdapter = new FileListListAdapter(mContainerActivity.getInitialDirectory(), mContainerActivity.getStorageManager(), getActivity(), mContainerActivity);
+        mAdapter = new FileListListAdapter(getActivity(), mContainerActivity);
         setListAdapter(mAdapter);
         
         registerForContextMenu(getListView());
@@ -124,7 +124,6 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         if (file != null) {
             if (file.isDirectory()) { 
                 // update state and view of this fragment
-                mFile = file;
                 listDirectory(file);
                 // then, notify parent activity to let it update its state and view, and other fragments
                 mContainerActivity.onBrowsedDownTo(file);
@@ -388,14 +387,6 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         
         
         /**
-         * Callback method invoked when the parent activity is fully created to get the directory to list firstly.
-         * 
-         * @return  Directory to list firstly. Can be NULL.
-         */
-        public OCFile getInitialDirectory();
-        
-        
-        /**
          * Callback method invoked when a the 'transfer state' of a file changes.
          * 
          * This happens when a download or upload is started or ended for a file.
index a41f6eb..b9ede07 100644 (file)
@@ -16,7 +16,6 @@
  */
 package com.owncloud.android.ui.preview;
 
-import android.accounts.Account;
 import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.content.BroadcastReceiver;
@@ -33,7 +32,6 @@ import android.view.View;
 import android.view.View.OnTouchListener;
 
 import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.actionbarsherlock.view.MenuItem;
 import com.actionbarsherlock.view.Window;
 import com.owncloud.android.datamodel.DataStorageManager;
@@ -46,13 +44,12 @@ import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.FileFragment;
-
 import com.owncloud.android.AccountUtils;
 import com.owncloud.android.Log_OC;
 import com.owncloud.android.R;
 
 /**
- *  Used as an utility to preview image files contained in an ownCloud account.
+ *  Holds a swiping galley where image files contained in an ownCloud directory are shown
  *  
  *  @author David A. Velasco
  */
@@ -65,9 +62,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
     
-    private OCFile mFile;
-    private OCFile mParentFolder;  
-    private Account mAccount;
     private DataStorageManager mStorageManager;
     
     private ViewPager mViewPager; 
@@ -88,53 +82,35 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
-        mAccount = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
-        if (mFile == null) {
-            throw new IllegalStateException("Instanced with a NULL OCFile");
-        }
-        if (mAccount == null) {
-            throw new IllegalStateException("Instanced with a NULL ownCloud Account");
-        }
-        if (!mFile.isImage()) {
-            throw new IllegalArgumentException("Non-image file passed as argument");
-        }
         requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
         setContentView(R.layout.preview_image_activity);
-    
+        
         ActionBar actionBar = getSupportActionBar();
         actionBar.setDisplayHomeAsUpEnabled(true);
-        actionBar.setTitle(mFile.getFileName());
         actionBar.hide();
         
         mFullScreen = true;
-        
-        mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
-        mParentFolder = mStorageManager.getFileById(mFile.getParentId());
-        if (mParentFolder == null) {
-            // should not be necessary
-            mParentFolder = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
-        }
-
         if (savedInstanceState != null) {
             mRequestWaitingForBinder = savedInstanceState.getBoolean(KEY_WAITING_FOR_BINDER);
         } else {
             mRequestWaitingForBinder = false;
         }
-        
-        createViewPager();
-
     }
 
-    private void createViewPager() {
-        mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), mParentFolder, mAccount, mStorageManager);
+    private void initViewPager() {
+        OCFile parentFolder = mStorageManager.getFileById(getFile().getParentId());
+        if (parentFolder == null) {
+            // should not be necessary
+            parentFolder = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
+        }
+        mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), parentFolder, getAccount(), mStorageManager);
         mViewPager = (ViewPager) findViewById(R.id.fragmentPager);
-        int position = mPreviewImagePagerAdapter.getFilePosition(mFile);
+        int position = mPreviewImagePagerAdapter.getFilePosition(getFile());
         position = (position >= 0) ? position : 0;
         mViewPager.setAdapter(mPreviewImagePagerAdapter); 
         mViewPager.setOnPageChangeListener(this);
         mViewPager.setCurrentItem(position);
-        if (position == 0 && !mFile.isDown()) {
+        if (position == 0 && !getFile().isDown()) {
             // this is necessary because mViewPager.setCurrentItem(0) just after setting the adapter does not result in a call to #onPageSelected(0) 
             mRequestWaitingForBinder = true;
         }
@@ -320,9 +296,9 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         if (mDownloaderBinder == null) {
             Log_OC.d(TAG, "requestForDownload called without binder to download service");
             
-        } else if (!mDownloaderBinder.isDownloading(mAccount, file)) {
+        } else if (!mDownloaderBinder.isDownloading(getAccount(), file)) {
             Intent i = new Intent(this, FileDownloader.class);
-            i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
+            i.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
             i.putExtra(FileDownloader.EXTRA_FILE, file);
             startService(i);
         }
@@ -385,7 +361,7 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         public void onReceive(Context context, Intent intent) {
             String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
             String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
-            if (mAccount.name.equals(accountName) && 
+            if (getAccount().name.equals(accountName) && 
                     downloadedRemotePath != null) {
 
                 OCFile file = mStorageManager.getFileByPath(downloadedRemotePath);
@@ -436,7 +412,33 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
 
     @Override
     protected void onAccountSet(boolean stateWasRecovered) {
-        // TODO
+        if (getAccount() != null) {
+            OCFile file = getFile();
+            /// Validate handled file  (first image to preview)
+            if (file == null) {
+                throw new IllegalStateException("Instanced with a NULL OCFile");
+            }
+            if (!file.isImage()) {
+                throw new IllegalArgumentException("Non-image file passed as argument");
+            }
+            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+            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
+                getSupportActionBar().setTitle(getFile().getFileName());
+                //if (!stateWasRecovered) {
+                    initViewPager();
+                //}
+
+            } else {
+                // handled file not in the current Account
+                finish();
+            }
+            
+        } else {
+            Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
+        }
     }
     
     
index a253624..3db62e9 100644 (file)
@@ -40,8 +40,6 @@ import com.owncloud.android.ui.fragment.FileFragment;
 //public class PreviewImagePagerAdapter extends PagerAdapter {
 public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
     
-    private static final String TAG = PreviewImagePagerAdapter.class.getSimpleName();
-            
     private Vector<OCFile> mImageFiles;
     private Account mAccount;
     private Set<Object> mObsoleteFragments;
@@ -51,14 +49,6 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
     
     private Map<Integer, FileFragment> mCachedFragments;
 
-    /*
-    private final FragmentManager mFragmentManager;
-    private FragmentTransaction mCurTransaction = null;
-    private ArrayList<Fragment.SavedState> mSavedState = new ArrayList<Fragment.SavedState>();
-    private ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
-    private Fragment mCurrentPrimaryItem = null;
-    */
-
     /**
      * Constructor.
      * 
@@ -188,8 +178,6 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
         return mDownloadErrors.contains(Integer.valueOf(position));
     }
 
-
-    
     /* -*
      * Called when a change in the shown pages is going to start being made.
      * 
index 7ea9f52..366dd9f 100644 (file)
@@ -61,6 +61,7 @@ import com.owncloud.android.operations.OnRemoteOperationListener;
 import com.owncloud.android.operations.RemoteOperation;
 import com.owncloud.android.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
@@ -477,8 +478,8 @@ public class PreviewMediaFragment extends FileFragment implements
     
     private void startFullScreenVideo() {
         Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
-        i.putExtra(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
-        i.putExtra(PreviewVideoActivity.EXTRA_FILE, getFile());
+        i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
+        i.putExtra(FileActivity.EXTRA_FILE, getFile());
         i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
         mVideoPreview.pause();
         i.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPreview.getCurrentPosition());
@@ -661,7 +662,6 @@ public class PreviewMediaFragment extends FileFragment implements
                                                             mStorageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
-            boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
             getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         }
     }
@@ -716,7 +716,6 @@ public class PreviewMediaFragment extends FileFragment implements
     }
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
         getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         
         if (result.isSuccess()) {
index 3cbff7d..f315cc4 100644 (file)
@@ -18,7 +18,6 @@
 package com.owncloud.android.ui.preview;
 
 import android.accounts.Account;
-import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -28,15 +27,17 @@ import android.media.MediaPlayer.OnErrorListener;
 import android.media.MediaPlayer.OnPreparedListener;
 import android.net.Uri;
 import android.os.Bundle;
-import android.view.MotionEvent;
 import android.widget.MediaController;
 import android.widget.VideoView;
 
 import com.owncloud.android.AccountUtils;
 import com.owncloud.android.Log_OC;
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.DataStorageManager;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.media.MediaService;
+import com.owncloud.android.ui.activity.FileActivity;
 
 /**
  *  Activity implementing a basic video player.
@@ -48,14 +49,8 @@ import com.owncloud.android.media.MediaService;
  *  
  *  @author David A. Velasco
  */
-public class PreviewVideoActivity extends Activity implements OnCompletionListener, OnPreparedListener, OnErrorListener {
+public class PreviewVideoActivity extends FileActivity implements OnCompletionListener, OnPreparedListener, OnErrorListener {
 
-    /** Key to receive an {@link OCFile} to play as an extra value in an {@link Intent} */
-    public static final String EXTRA_FILE = "FILE";
-    
-    /** Key to receive the ownCloud {@link Account} where the file to play is saved as an extra value in an {@link Intent} */
-    public static final String EXTRA_ACCOUNT = "ACCOUNT";
-    
     /** Key to receive a flag signaling if the video should be started immediately */
     public static final String EXTRA_AUTOPLAY = "AUTOPLAY";
     
@@ -64,8 +59,8 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     
     private static final String TAG = PreviewVideoActivity.class.getSimpleName();
 
-    private OCFile mFile;                       // video file to play
-    private Account mAccount;                   // ownCloud account holding mFile
+    private DataStorageManager mStorageManager;
+    
     private int mSavedPlaybackPosition;         // in the unit time handled by MediaPlayer.getCurrentPosition()
     private boolean mAutoplay;                  // when 'true', the playback starts immediately with the activity
     private VideoView mVideoPlayer;             // view to play the file; both performs and show the playback
@@ -90,14 +85,10 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     
         if (savedInstanceState == null) {
             Bundle extras = getIntent().getExtras();
-            mFile = extras.getParcelable(EXTRA_FILE);
-            mAccount = extras.getParcelable(EXTRA_ACCOUNT);
             mSavedPlaybackPosition = extras.getInt(EXTRA_START_POSITION);
             mAutoplay = extras.getBoolean(EXTRA_AUTOPLAY);
             
         } else {
-            mFile = savedInstanceState.getParcelable(EXTRA_FILE);
-            mAccount = savedInstanceState.getParcelable(EXTRA_ACCOUNT);
             mSavedPlaybackPosition = savedInstanceState.getInt(EXTRA_START_POSITION);
             mAutoplay = savedInstanceState.getBoolean(EXTRA_AUTOPLAY);
         }
@@ -111,29 +102,6 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
           
         // keep the screen on while the playback is performed (prevents screen off by battery save)
         mVideoPlayer.setKeepScreenOn(true);
-        
-        if (mFile != null) {
-            if (mFile.isDown()) {
-                mVideoPlayer.setVideoPath(mFile.getStoragePath());
-                
-            } else if (mAccount != null) {
-                // not working now
-                String url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath();
-                mVideoPlayer.setVideoURI(Uri.parse(url));
-                
-            } else {
-                onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
-            }
-            
-            // create and prepare control panel for the user
-            mMediaController = new MediaController(this);
-            mMediaController.setMediaPlayer(mVideoPlayer);
-            mMediaController.setAnchorView(mVideoPlayer);
-            mVideoPlayer.setMediaController(mMediaController);
-            
-        } else {
-            onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_nothing_to_play);
-        }
     }    
     
     
@@ -144,8 +112,6 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         Log_OC.e(TAG, "ACTIVITY\t\tonSaveInstanceState");
-        outState.putParcelable(PreviewVideoActivity.EXTRA_FILE, mFile);
-        outState.putParcelable(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
         outState.putInt(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPlayer.getCurrentPosition());
         outState.putBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY , mVideoPlayer.isPlaying());
     }
@@ -162,39 +128,6 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     }
 
     
-    @Override
-    public void onResume() {
-        super.onResume();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonResume");
-    }
-
-    
-    @Override
-    public void onStart() {
-        super.onStart();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonStart");
-    }
-    
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-        Log_OC.e(TAG, "ACTIVITY\t\tonDestroy");
-    }
-    
-    @Override
-    public void onStop() {
-        super.onStop();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonStop");
-    }
-    
-    
-    @Override
-    public void onPause() {
-        super.onPause();
-        Log_OC.e(TAG, "ACTIVTIY\t\tonPause");
-    }
-    
-    
     /** 
      * Called when the file is ready to be played.
      * 
@@ -258,25 +191,43 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen
     }
     
     
-    /**  
-     * Screen touches trigger the appearance of the control panel for a limited time.
-     *
-     * {@inheritDoc}
-     */
     @Override
-    public boolean onTouchEvent (MotionEvent ev){ 
-        /*if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-            if (mMediaController.isShowing()) {
-                mMediaController.hide();
+    protected void onAccountSet(boolean stateWasRecovered) {
+        if (getAccount() != null) {
+            OCFile file = getFile();
+            /// Validate handled file  (first image to preview)
+            if (file == null) {
+                throw new IllegalStateException("Instanced with a NULL OCFile");
+            }
+            if (!file.isVideo()) {
+                throw new IllegalArgumentException("Non-video file passed as argument");
+            }
+            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+            file = mStorageManager.getFileById(file.getFileId()); 
+            if (file != null) {
+                if (file.isDown()) {
+                    mVideoPlayer.setVideoPath(file.getStoragePath());
+                    
+                } else {
+                    // not working now
+                    String url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
+                    mVideoPlayer.setVideoURI(Uri.parse(url));
+                }
+                
+                // create and prepare control panel for the user
+                mMediaController = new MediaController(this);
+                mMediaController.setMediaPlayer(mVideoPlayer);
+                mMediaController.setAnchorView(mVideoPlayer);
+                mVideoPlayer.setMediaController(mMediaController);
+                
             } else {
-                mMediaController.show(MediaService.MEDIA_CONTROL_SHORT_LIFE);
+                finish();
             }
-            return true;        
         } else {
-            return false;
-        }*/
-        return false;
-    }
+            Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
+            finish();
+        }
+   }
 
 
 }
\ No newline at end of file