Merge pull request #186 from owncloud/fixed_contradicted_messages_in_login_view
authorDavid A. Velasco <dvelasco@owncloud.com>
Wed, 19 Jun 2013 15:02:50 +0000 (08:02 -0700)
committerDavid A. Velasco <dvelasco@owncloud.com>
Wed, 19 Jun 2013 15:02:50 +0000 (08:02 -0700)
Fixed contradicted messages in login view

40 files changed:
.classpath
AndroidManifest.xml
lint.xml [new file with mode: 0644]
oc_jb_workaround/.classpath
oc_jb_workaround/project.properties
res/drawable/btn_cancel.png [new file with mode: 0644]
res/layout-large-land/files.xml [deleted file]
res/layout/file_details_empty.xml
res/layout/file_details_fragment.xml
res/layout/file_download_fragment.xml
res/layout/files.xml
res/layout/list_fragment.xml
res/menu/file_actions_menu.xml
res/values-large-land/bools.xml [new file with mode: 0644]
res/values-large/bools.xml [deleted file]
res/values/bools.xml
res/values/strings.xml
src/com/owncloud/android/AccountUtils.java
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/files/FileHandler.java [new file with mode: 0644]
src/com/owncloud/android/files/services/FileDownloader.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/media/MediaService.java
src/com/owncloud/android/ui/FragmentListView.java [deleted file]
src/com/owncloud/android/ui/activity/FileActivity.java
src/com/owncloud/android/ui/activity/FileDetailActivity.java [deleted file]
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java [new file with mode: 0644]
src/com/owncloud/android/ui/fragment/FileDetailFragment.java
src/com/owncloud/android/ui/fragment/FileFragment.java
src/com/owncloud/android/ui/fragment/LocalFileListFragment.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/com/owncloud/android/ui/preview/FileDownloadFragment.java
src/com/owncloud/android/ui/preview/PreviewImageActivity.java
src/com/owncloud/android/ui/preview/PreviewImageFragment.java
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java
tests/.classpath
tests/.settings/org.eclipse.jdt.core.prefs
tests/project.properties

index d57ec02..2731f9c 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
index b047f91..ee9ecaf 100644 (file)
@@ -50,7 +50,7 @@
         <activity
             android:name=".ui.activity.FileDisplayActivity"
             android:label="@string/app_name"
-            android:configChanges="orientation|screenSize">
+            >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
         <service android:name=".files.services.FileUploader" />
         <service android:name=".media.MediaService" />
         
-        <activity android:name=".ui.activity.FileDetailActivity" android:configChanges="orientation|screenSize"/>
         <activity android:name=".ui.activity.PinCodeActivity" />
         <activity android:name=".extensions.ExtensionsAvailableActivity"></activity>
         <activity android:name=".extensions.ExtensionsListActivity"></activity>
diff --git a/lint.xml b/lint.xml
new file mode 100644 (file)
index 0000000..ee0eead
--- /dev/null
+++ b/lint.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+</lint>
\ No newline at end of file
index d57ec02..96e9275 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
index 9b84a6b..a3ee5ab 100644 (file)
@@ -11,4 +11,4 @@
 #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
 
 # Project target.
-target=android-16
+target=android-17
diff --git a/res/drawable/btn_cancel.png b/res/drawable/btn_cancel.png
new file mode 100644 (file)
index 0000000..0a339bd
Binary files /dev/null and b/res/drawable/btn_cancel.png differ
diff --git a/res/layout-large-land/files.xml b/res/layout-large-land/files.xml
deleted file mode 100644 (file)
index d874bf5..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>\r
-<!--\r
-  ownCloud Android client application\r
-\r
-  Copyright (C) 2011  Bartek Przybylski\r
-  Copyright (C) 2012-2013 ownCloud Inc.\r
-\r
-  This program is free software: you can redistribute it and/or modify\r
-  it under the terms of the GNU General Public License version 2,\r
-  as published by the Free Software Foundation.\r
-\r
-  This program is distributed in the hope that it will be useful,\r
-  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-  GNU General Public License for more details.\r
-\r
-  You should have received a copy of the GNU General Public License\r
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.\r\r
--->\r
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="fill_parent"\r
-    android:background="@color/owncloud_white"\r
-    android:orientation="horizontal" >\r
-\r
-    <LinearLayout\r
-        android:id="@+id/file_list_container"\r
-        android:layout_width="0dp"\r
-        android:layout_height="fill_parent"\r
-        android:layout_weight="1" >\r
-\r
-        <fragment\r
-            android:id="@+id/fileList"\r
-            android:layout_width="fill_parent"\r
-            android:layout_height="fill_parent"\r
-            class="com.owncloud.android.ui.fragment.OCFileListFragment" >\r
-\r
-            <!-- Preview: layout=@layout/list_layout -->\r
-        </fragment>\r
-    </LinearLayout>\r
-\r
-    <LinearLayout android:id="@+id/file_details_container"\r
-        android:layout_width="0dp"\r
-        android:layout_height="fill_parent"\r
-        android:layout_weight="2" >\r
-\r
-        <!-- Preview: layout=@layout/file_details_empty -->\r
-    </LinearLayout>\r
-\r
-</LinearLayout>\r
index 3a205bd..56438e9 100644 (file)
@@ -18,8 +18,8 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
 <LinearLayout 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"
     android:background="#F7F7F7"
     android:orientation="vertical" >
 
index ec75646..db41532 100644 (file)
@@ -19,8 +19,9 @@
 -->
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fdScrollView"
-       android:layout_width="fill_parent"
-       android:layout_height="fill_parent" >
+       android:layout_width="match_parent"
+       android:layout_height="match_parent"
+       >
 
        <RelativeLayout
                android:layout_width="match_parent"
                                android:id="@+id/fdProgressBlock"
                                        android:layout_width="match_parent"
                                        android:layout_height="wrap_content"
-                                       android:gravity="center_horizontal"
+                                       android:gravity="center"
                                        android:layout_marginTop="12dp"
                                        android:layout_marginBottom="12dp"
                                        android:orientation="horizontal"
                                                android:indeterminateOnly="false" 
                                        />
                                                                                                
-                                       <Button
+                                       <ImageButton
                                                android:id="@+id/fdCancelBtn"
                                                android:layout_width="wrap_content"
                                                android:layout_height="wrap_content"
                                                android:layout_marginLeft="12dp"
-                                               android:text="@string/common_cancel" />
+                                               android:src="@drawable/btn_cancel"
+                                               android:background="@android:color/transparent"
+                                               />
                                                
                                </LinearLayout>
        
index 9c91c37..f881847 100644 (file)
                android:layout_marginBottom="15dp"
        />
        
-       <ProgressBar android:id="@+id/progressBar"
-               android:layout_width="match_parent" 
+    <LinearLayout
+        android:id="@+id/fdProgressBlock"
+               android:layout_width="match_parent"
                android:layout_height="wrap_content"
-               android:progressDrawable="@android:drawable/progress_horizontal"
-               android:indeterminate="false" 
-               android:indeterminateOnly="false" 
+               android:gravity="center"
+               android:layout_marginTop="12dp"
                android:layout_marginBottom="15dp"
-       />
-       
-       <Button
-               android:id="@+id/cancelBtn"
-               android:layout_width="wrap_content"
-               android:layout_height="wrap_content"
-               android:text="@string/common_cancel" 
-               android:layout_marginBottom="15dp"
-       />
-       
+               android:orientation="horizontal"
+               >
+                                       
+               <ProgressBar android:id="@+id/progressBar"
+                       android:layout_width="0dp" 
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1"
+                       android:progressDrawable="@android:drawable/progress_horizontal"
+                       android:indeterminate="false" 
+                       android:indeterminateOnly="false" 
+                       
+               />
+
+               <ImageButton
+                       android:id="@+id/cancelBtn"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:layout_marginLeft="12dp"
+                       android:src="@drawable/btn_cancel"
+                       android:background="@android:color/transparent"
+               />
+
+       </LinearLayout>
+                       
        <ImageView
                android:id="@+id/error_image"
                android:layout_width="wrap_content"
index 0e4fd8b..74a9e4b 100644 (file)
   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
  -->\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="fill_parent"\r
+    android:layout_width="match_parent"\r
+    android:layout_height="match_parent"\r
     android:background="@color/owncloud_white"\r
-    android:orientation="vertical"\r
-    android:id="@+id/file_list_view">\r
+    android:orientation="horizontal"\r
+    android:baselineAligned="false"\r
+    >\r
 \r
-    <fragment\r
-        android:id="@+id/fileList"\r
-        android:layout_width="fill_parent"\r
-        android:layout_height="fill_parent"\r
-        class="com.owncloud.android.ui.fragment.OCFileListFragment" >\r
-\r
-        <!-- Preview: layout=@layout/list_layout -->\r
-    </fragment>\r
-\r
-</LinearLayout>\r
+       <FrameLayout \r
+               android:layout_width="0dp"\r
+               android:layout_height="match_parent"\r
+               android:layout_weight="1"\r
+               android:id="@+id/left_fragment_container"\r
+           />\r
+       \r
+       <FrameLayout \r
+               android:layout_width="0dp"\r
+               android:layout_height="match_parent"\r
+               android:layout_weight="2"\r
+               android:id="@+id/right_fragment_container"\r
+           />\r
+       \r
+ </LinearLayout>
\ No newline at end of file
index 01b05df..00e6b41 100644 (file)
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-       android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:orientation="vertical" >
+       android:layout_width="0dp"
+       android:layout_height="match_parent"
+       android:layout_weight="1"
+       android:orientation="vertical" >
 
        <com.owncloud.android.ui.ExtendedListView
         android:id="@+id/list_root"
index 5c25fed..1aa2823 100644 (file)
@@ -19,7 +19,7 @@
 -->
 <menu  xmlns:android="http://schemas.android.com/apk/res/android">
     
-       <item   android:id="@+id/action_open_file_with"                 android:title="@string/filedetails_open"                        android:icon="@android:drawable/ic_menu_edit"                                   android:orderInCategory="1" />
+       <item   android:id="@+id/action_open_file_with"                 android:title="@string/actionbar_open_with"                     android:icon="@android:drawable/ic_menu_edit"                                   android:orderInCategory="1" />
        <item   android:id="@+id/action_download_file"                  android:title="@string/filedetails_download"            android:icon="@drawable/ic_action_download"                                             android:orderInCategory="1" />
     <item      android:id="@+id/action_sync_file"                              android:title="@string/filedetails_sync_file"           android:icon="@drawable/ic_action_refresh"                                              android:orderInCategory="1" />
        <item   android:id="@+id/action_cancel_download"                android:title="@string/common_cancel_download"          android:icon="@android:drawable/ic_menu_close_clear_cancel"             android:orderInCategory="1" />
diff --git a/res/values-large-land/bools.xml b/res/values-large-land/bools.xml
new file mode 100644 (file)
index 0000000..9feccd8
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  Copyright (C) 2012-2013 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<!-- Large screen, landscape orientation boolean values -->
+<resources>
+    <bool name="large_land_layout">true</bool>
+</resources>
\ No newline at end of file
diff --git a/res/values-large/bools.xml b/res/values-large/bools.xml
deleted file mode 100644 (file)
index e143605..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<!-- Large screen boolean values -->
-<resources>
-    <bool name="large_layout">true</bool>
-</resources>
\ No newline at end of file
index cecc571..1c8d68c 100644 (file)
@@ -18,5 +18,5 @@
 -->
 <!-- Default boolean values -->
 <resources>
-    <bool name="large_layout">false</bool>
+    <bool name="large_land_layout">false</bool>
 </resources>
\ No newline at end of file
index 2d6de4b..708fbfb 100644 (file)
     <string name="main_wrn_accsetup">There is no account set up on your device. In order to use this App, you need to create one.</string>
     <string name="about_android">%1$s Android App</string>
     <string name="about_version">version %1$s</string>
-    <string name="actionbar_sync">Refresh</string>
+    <string name="actionbar_sync">Refresh account</string>
     <string name="actionbar_upload">Upload</string>
     <string name="actionbar_upload_from_apps">Content from other apps</string>
     <string name="actionbar_upload_files">Files</string>
+    <string name="actionbar_open_with">Open with</string>
     <string name="actionbar_mkdir">Create directory</string>
     <string name="actionbar_search">Search</string>
     <string name="actionbar_settings">Settings</string>
@@ -79,9 +80,8 @@
     <string name="filedetails_created">Created:</string>
     <string name="filedetails_modified">Modified:</string>
     <string name="filedetails_download">Download</string>
-    <string name="filedetails_sync_file">Refresh</string>
+    <string name="filedetails_sync_file">Refresh file</string>
     <string name="filedetails_redownload">Redownload</string>
-    <string name="filedetails_open">Open</string>
     <string name="filedetails_renamed_in_upload_msg">File was renamed to %1$s during upload</string>
     <string name="common_yes">Yes</string>
     <string name="common_no">No</string>
index a1d39ae..7297ee1 100644 (file)
@@ -37,12 +37,13 @@ public class AccountUtils {
     public static final String STATUS_PATH = "/status.php";\r
 \r
     /**\r
-     * Can be used to get the currently selected ownCloud account in the\r
-     * preferences\r
+     * Can be used to get the currently selected ownCloud {@link Account} in the\r
+     * application preferences.\r
      * \r
-     * @param context The current appContext\r
-     * @return The current account or first available, if none is available,\r
-     *         then null.\r
+     * @param   context     The current application {@link Context}\r
+     * @return              The ownCloud {@link Account} currently saved in preferences, or the first \r
+     *                      {@link Account} available, if valid (still registered in the system as ownCloud \r
+     *                      account). If none is available and valid, returns null.\r
      */\r
     public static Account getCurrentOwnCloudAccount(Context context) {\r
         Account[] ocAccounts = AccountManager.get(context).getAccountsByType(\r
@@ -54,6 +55,7 @@ public class AccountUtils {
         String accountName = appPreferences\r
                 .getString("select_oc_account", null);\r
 \r
+        // account validation: the saved account MUST be in the list of ownCloud Accounts known by the AccountManager\r
         if (accountName != null) {\r
             for (Account account : ocAccounts) {\r
                 if (account.name.equals(accountName)) {\r
@@ -64,7 +66,7 @@ public class AccountUtils {
         }\r
         \r
         if (defaultAccount == null && ocAccounts.length != 0) {\r
-            // we at least need to take first account as fallback\r
+            // take first account as fallback\r
             defaultAccount = ocAccounts[0];\r
         }\r
 \r
index c1ca605..3c34be6 100644 (file)
@@ -97,6 +97,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     private static final String KEY_PASSWORD_VISIBLE = "PASSWORD_VISIBLE";\r
     private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
     private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
+    private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED";\r
 \r
     private static final String OAUTH_MODE_ON = "on";\r
     private static final String OAUTH_MODE_OFF = "off";\r
@@ -109,8 +110,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     public static final byte ACTION_CREATE = 0;\r
     public static final byte ACTION_UPDATE_TOKEN = 1;\r
-\r
-\r
+    \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
 \r
@@ -141,6 +141,8 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     private TextView mOAuthAuthEndpointText;\r
     private TextView mOAuthTokenEndpointText;\r
+    \r
+    private boolean mRefreshButtonEnabled;\r
 \r
 \r
     /**\r
@@ -231,13 +233,16 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             // check if server check was interrupted by a configuration change\r
             if (savedInstanceState.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS, false)) {\r
                 checkOcServer();\r
-            }\r
+            }            \r
+            \r
+            // refresh button enabled\r
+            mRefreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED);\r
 \r
         }\r
 \r
         showServerStatus();\r
         showAuthStatus();\r
-        if (mServerIsChecked && !mServerIsValid) showRefreshButton();\r
+        if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();\r
         mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 \r
         if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
@@ -286,7 +291,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         });\r
         mPasswordInput.setOnFocusChangeListener(this);\r
         mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
-        mPasswordInput.setOnEditorActionListener(this);\r
+        mPasswordInput.setOnEditorActionListener(this);
         mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
             @Override\r
             public boolean onDrawableTouch(final MotionEvent event) {\r
@@ -295,7 +300,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 }\r
                 return true;\r
             }\r
-        });\r
+        });
     }\r
 \r
     /**\r
@@ -331,6 +336,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         if (mAccount != null) {\r
             outState.putParcelable(KEY_ACCOUNT, mAccount);\r
         }\r
+        \r
+        // refresh button enabled\r
+        outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, mRefreshButtonEnabled);\r
 \r
     }\r
 \r
@@ -407,6 +415,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         if (view.getId() == R.id.hostUrlInput) {   \r
             if (!hasFocus) {\r
                 onUrlInputFocusLost((TextView) view);\r
+                if (!mServerIsValid) {\r
+                    showRefreshButton();\r
+                }\r
             }\r
             else {\r
                 hideRefreshButton();\r
@@ -439,7 +450,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
 \r
     private void checkOcServer() {\r
-        String uri = mHostUrlInput.getText().toString().trim();\r
+        String uri = trimUrlWebdav(mHostUrlInput.getText().toString().trim());\r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
         mOkButton.setEnabled(false);\r
@@ -681,15 +692,33 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 } else {\r
                     url = "http://" + url;\r
                 }\r
-\r
             }\r
+\r
+            // OC-208: Add suffix remote.php/webdav to normalize (OC-34)            \r
+            url = trimUrlWebdav(url);\r
+\r
             if (url.endsWith("/")) {\r
                 url = url.substring(0, url.length() - 1);\r
             }\r
+\r
         }\r
+        Log_OC.d(TAG, "URL Normalize " + url);\r
         return (url != null ? url : "");\r
     }\r
 \r
+\r
+    private String trimUrlWebdav(String url){       \r
+        if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length());             \r
+        } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length());             \r
+        } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length());             \r
+        } \r
+        return (url != null ? url : "");\r
+    }\r
+    \r
+    \r
     /**\r
      * Chooses the right icon and text to show to the user for the received operation result.\r
      * \r
@@ -1166,10 +1195,12 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     private void showRefreshButton() {\r
         mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
+        mRefreshButtonEnabled = true;\r
     }\r
 \r
     private void hideRefreshButton() {\r
         mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+        mRefreshButtonEnabled = false;\r
     }\r
 \r
     /**\r
diff --git a/src/com/owncloud/android/files/FileHandler.java b/src/com/owncloud/android/files/FileHandler.java
new file mode 100644 (file)
index 0000000..2eb754d
--- /dev/null
@@ -0,0 +1,30 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.files;
+
+import com.owncloud.android.datamodel.OCFile;
+
+public interface FileHandler {
+
+    /**
+     * TODO
+     */
+    public void openFile(OCFile file);
+
+    
+}
index ff5e441..1ec5591 100644 (file)
@@ -38,7 +38,7 @@ import com.owncloud.android.operations.DownloadFileOperation;
 import com.owncloud.android.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
 
@@ -414,7 +414,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         if (PreviewImageFragment.canBePreviewed(download.getFile())) {
             showDetailsIntent = new Intent(this, PreviewImageActivity.class);
         } else {
-            showDetailsIntent = new Intent(this, FileDetailActivity.class);
+            showDetailsIntent = new Intent(this, FileDisplayActivity.class);
         }
         showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
         showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount());
@@ -485,7 +485,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
                     if (PreviewImageFragment.canBePreviewed(download.getFile())) {
                         showDetailsIntent = new Intent(this, PreviewImageActivity.class);
                     } else {
-                        showDetailsIntent = new Intent(this, FileDetailActivity.class);
+                        showDetailsIntent = new Intent(this, FileDisplayActivity.class);
                     }
                     showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
                     showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount());
index b41f870..2f66e30 100644 (file)
@@ -42,7 +42,6 @@ import com.owncloud.android.operations.RemoteOperation;
 import com.owncloud.android.operations.RemoteOperationResult;
 import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.ui.activity.FileDetailActivity;
 import com.owncloud.android.utils.OwnCloudVersion;
 
 import eu.alefzero.webdav.OnDatatransferProgressListener;
@@ -74,6 +73,7 @@ import com.owncloud.android.R;
 import com.owncloud.android.db.DbHandler;
 import com.owncloud.android.ui.activity.FailedUploadActivity;
 import com.owncloud.android.ui.activity.FileActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.InstantUploadActivity;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
@@ -703,8 +703,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         if (PreviewImageFragment.canBePreviewed(upload.getFile())) {
             showDetailsIntent = new Intent(this, PreviewImageActivity.class);
         } else {
-            showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
+            showDetailsIntent = new Intent(this, FileDisplayActivity.class);
         }
         showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
         showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
@@ -766,8 +765,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
             if (PreviewImageFragment.canBePreviewed(upload.getFile())) {
                 showDetailsIntent = new Intent(this, PreviewImageActivity.class); 
             } else {
-                showDetailsIntent = new Intent(this, FileDetailActivity.class); 
-                showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
+                showDetailsIntent = new Intent(this, FileDisplayActivity.class); 
             }
             showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
             showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
index d6ca096..992bc7d 100644 (file)
@@ -41,7 +41,7 @@ import com.owncloud.android.Log_OC;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 
 /**
  * Service that handles media playback, both audio and video. 
@@ -532,7 +532,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     @SuppressWarnings("deprecation")
     private void updateNotification(String content) {
         // TODO check if updating the Intent is really necessary
-        Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+        Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
         showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, mFile);
         showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
         showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -569,7 +569,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
 
         
         /// includes a pending intent in the notification showing the details view of the file
-        Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+        Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
         showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, mFile);
         showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
         showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/src/com/owncloud/android/ui/FragmentListView.java b/src/com/owncloud/android/ui/FragmentListView.java
deleted file mode 100644 (file)
index 43b2fc6..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012 Bartek Przybylski
- *   Copyright (C) 2012-2013 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.ui;
-
-import com.actionbarsherlock.app.SherlockFragment;
-import com.owncloud.android.R;
-import com.owncloud.android.ui.fragment.LocalFileListFragment;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.ListAdapter;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ListView;
-
-public class FragmentListView extends SherlockFragment implements
-        OnItemClickListener, OnItemLongClickListener {
-    protected ExtendedListView mList;
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-    }
-
-    public void setListAdapter(ListAdapter listAdapter) {
-        mList.setAdapter(listAdapter);
-        mList.invalidate();
-    }
-
-    public ListView getListView() {
-        return mList;
-    }
-    
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-            Bundle savedInstanceState) {
-        //mList = new ExtendedListView(getActivity());
-        View v = inflater.inflate(R.layout.list_fragment, null);
-        mList = (ExtendedListView)(v.findViewById(R.id.list_root));
-        mList.setOnItemClickListener(this);
-        mList.setOnItemLongClickListener(this);
-        //mList.setEmptyView(v.findViewById(R.id.empty_list_view));     // looks like it's not a cool idea 
-        mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
-        mList.setDividerHeight(1);
-        return v;
-    }
-
-    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
-    }
-
-    @Override
-    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
-            long arg3) {
-        return false;
-    }
-
-    
-    /**
-     * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
-     * the device is turned to other position. 
-     * 
-     * THe current policy is take as a reference the visible item in the center of the screen.  
-     * 
-     * @return      The position in the list of the visible item in the center of the screen.
-     */
-    protected int getReferencePosition() {
-        return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
-    }
-
-    
-    /**
-     * Sets the visible part of the list from the reference position.
-     * 
-     * @param   position    Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
-     */
-    protected void setReferencePosition(int position) {
-        mList.setAndCenterSelection(position);
-    }
-
-    
-}
index 6168879..d645d6e 100644 (file)
@@ -23,14 +23,20 @@ import android.accounts.AccountManager;
 import android.accounts.AccountManagerCallback;
 import android.accounts.AccountManagerFuture;
 import android.accounts.OperationCanceledException;
+import android.content.Intent;
+import android.net.Uri;
 import android.os.Bundle;
+import android.webkit.MimeTypeMap;
 
 import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.owncloud.android.AccountUtils;
 import com.owncloud.android.Log_OC;
+import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.datamodel.OCFile;
 
+import eu.alefzero.webdav.WebdavUtils;
+
 /**
  * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud {@link Account}s .
  * 
@@ -40,6 +46,7 @@ public abstract class FileActivity extends SherlockFragmentActivity {
 
     public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
     public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
+    public static final String EXTRA_WAITING_TO_PREVIEW = "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
     
     public static final String TAG = FileActivity.class.getSimpleName(); 
     
@@ -52,13 +59,19 @@ 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;
-
     
+
+    /**
+     * Loads the cownCloud {@link Account} and main {@link OCFile} to be handled by the instance of 
+     * the {@link FileActivity}.
+     * 
+     * Grants that a valid ownCloud {@link Account} is associated to the instance, or that the user 
+     * is requested to create a new one.
+     */
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        
-        /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
+
         if(savedInstanceState != null) {
             mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
             mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
@@ -66,38 +79,53 @@ public abstract class FileActivity extends SherlockFragmentActivity {
             mAccount = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
             mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
         }
-        
-        if (mAccount != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name)) {
-            onAccountChanged();
+
+        grantValidAccount();
+        if (mAccount != null) {
+            onAccountSet(savedInstanceState != null);
         }
     }
 
     
     /**
-     * Validate the ownCloud {@link Account} associated to the Activity any time it is 
-     * started, and if not valid tries to move to a different Account.
+     *  Since ownCloud {@link Account}s can be managed from the system setting menu, 
+     *  the existence of the {@link Account} associated to the instance must be checked 
+     *  every time it is restarted.
      */
     @Override
-    protected void onStart() {
-        Log_OC.e(TAG, "onStart en FileActivity");
-        super.onStart();
-        /// Validate account, and try to fix if wrong
-        if (mAccount == null || !AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name)) {
-            if (!AccountUtils.accountsAreSetup(getApplicationContext())) {
+    protected void onRestart() {
+        super.onRestart();
+        
+        Account oldAccount = mAccount;
+        grantValidAccount();
+        if (mAccount != null && !mAccount.equals(oldAccount)) {
+            onAccountSet(false);
+        }
+    }
+    
+        
+    /**
+     *  Validates the ownCloud {@link Account} associated to the Activity any time it is restarted.
+     * 
+     *  If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
+     * 
+     *  If no valid ownCloud {@link Account} exists, mAccount is set to NULL and the user is requested 
+     *  to create a new ownCloud {@link Account}.
+     */
+    private void grantValidAccount() {
+        boolean validAccount = (mAccount != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name));
+        if (!validAccount) {
+            // get most recently used account as default account
+            mAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+            if (mAccount == null) {
                 /// no account available: force account creation
-                mAccount = null;
                 createFirstAccount();
                 mRedirectingToSetupAccount = true;
-                
-            } else {
-                /// get 'last current account' as default account
-                mAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
-                onAccountChanged();
             }
         }
     }
     
-        
+    
     /**
      * Launches the account creation activity. To use when no ownCloud account is available
      */
@@ -183,7 +211,7 @@ public abstract class FileActivity extends SherlockFragmentActivity {
                     String type = result.getString(AccountManager.KEY_ACCOUNT_TYPE);
                     if (AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name)) {
                         FileActivity.this.mAccount = new Account(name, type);
-                        FileActivity.this.onAccountChanged();
+                        FileActivity.this.onAccountSet(false);
                     }
                 } catch (OperationCanceledException e) {
                     Log_OC.e(TAG, "Account creation canceled");
@@ -201,12 +229,48 @@ public abstract class FileActivity extends SherlockFragmentActivity {
         }
         
     }
-
-
+    
+    
     /**
      *  Called when the ownCloud {@link Account} associated to the Activity was just updated.
      * 
      *  Child classes must grant that state depending on the {@link Account} is updated.
      */
-    protected abstract void onAccountChanged();
+    protected abstract void onAccountSet(boolean stateWasRecovered);
+    
+    
+
+    public void openFile(OCFile file) {
+        if (file != null) {
+            String storagePath = file.getStoragePath();
+            String encodedStoragePath = WebdavUtils.encodePath(storagePath);
+            
+            Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
+            intentForSavedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
+            intentForSavedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+            
+            Intent intentForGuessedMimeType = null;
+            if (storagePath.lastIndexOf('.') >= 0) {
+                String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
+                if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
+                    intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
+                    intentForGuessedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), guessedMimeType);
+                    intentForGuessedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+                }
+            }
+            
+            Intent chooserIntent = null;
+            if (intentForGuessedMimeType != null) {
+                chooserIntent = Intent.createChooser(intentForGuessedMimeType, getString(R.string.actionbar_open_with));
+            } else {
+                chooserIntent = Intent.createChooser(intentForSavedMimeType, getString(R.string.actionbar_open_with));
+            }
+            
+            startActivity(chooserIntent);
+            
+        } else {
+            Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
+        }
+    }
+    
 }
diff --git a/src/com/owncloud/android/ui/activity/FileDetailActivity.java b/src/com/owncloud/android/ui/activity/FileDetailActivity.java
deleted file mode 100644 (file)
index 545e579..0000000
+++ /dev/null
@@ -1,481 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2011  Bartek Przybylski
- *   Copyright (C) 2012-2013 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package com.owncloud.android.ui.activity;
-
-import android.accounts.Account;
-import android.app.Dialog;
-import android.app.ProgressDialog;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.view.MenuItem;
-import com.owncloud.android.AccountUtils;
-import com.owncloud.android.Log_OC;
-import com.owncloud.android.R;
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader;
-import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
-import com.owncloud.android.files.services.FileUploader;
-import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.ui.fragment.FileDetailFragment;
-import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.ui.preview.PreviewMediaFragment;
-import com.owncloud.android.ui.preview.PreviewVideoActivity;
-
-/**
- * This activity displays the details of a file like its name, its size and so
- * on.
- * 
- * @author Bartek Przybylski
- * @author David A. Velasco
- */
-public class FileDetailActivity extends FileActivity implements FileFragment.ContainerActivity {
-    
-    public static final int DIALOG_SHORT_WAIT = 0;
-
-    public static final String TAG = FileDetailActivity.class.getSimpleName();
-    
-    public static final String EXTRA_MODE = "MODE";
-    public static final int MODE_DETAILS = 0;
-    public static final int MODE_PREVIEW = 1;
-
-    public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
-    
-    private FileDownloaderBinder mDownloaderBinder = null;
-    private ServiceConnection mDownloadConnection, mUploadConnection = null;
-    private FileUploaderBinder mUploaderBinder = null;
-    private boolean mWaitingToPreview;
-    
-    private FileDataStorageManager mStorageManager;
-    private DownloadFinishReceiver mDownloadFinishReceiver;
-
-    private Configuration mNewConfigurationChangeToApplyOnStart;
-
-    private boolean mStarted;
-
-    private boolean mDualPane;
-    
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        mStarted = false;
-        
-        // check if configuration is proper for this activity; tablets in landscape should pass the torch to FileDisplayActivity 
-        Configuration conf = getResources().getConfiguration();
-        mDualPane = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE && 
-                        (conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
-                    );
-
-        if (mDualPane) {
-            // only happens when notifications (downloads, uploads) are clicked at the notification bar
-            backToDisplayActivity(false);
-            
-        } else {
-            setContentView(R.layout.file_activity_details);
-        
-            ActionBar actionBar = getSupportActionBar();
-            actionBar.setDisplayHomeAsUpEnabled(true);
-    
-            if (savedInstanceState == null) {
-                mWaitingToPreview = false;
-                createChildFragment();
-            } else {
-                mWaitingToPreview = savedInstanceState.getBoolean(KEY_WAITING_TO_PREVIEW);
-            }
-            
-            mDownloadConnection = new DetailsServiceConnection();
-            bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
-            mUploadConnection = new DetailsServiceConnection();
-            bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);
-        }
-    }
-    
-    /**
-     * Creates the proper fragment depending upon the state of the handled {@link OCFile} and
-     * the requested {@link Intent}.
-     */
-    private void createChildFragment() {
-        int mode = getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW); 
-        
-        Fragment newFragment = null;
-        OCFile file = getFile();
-        Account account = getAccount();
-        if (PreviewMediaFragment.canBePreviewed(file) && mode == MODE_PREVIEW) {
-            if (file.isDown()) {
-                int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
-                boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
-                newFragment = new PreviewMediaFragment(file, account, startPlaybackPosition, autoplay);
-            
-            } else {
-                newFragment = new FileDetailFragment(file, account);
-                mWaitingToPreview = true;
-            }
-            
-        } else {
-            newFragment = new FileDetailFragment(file, account);
-        }
-        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-        ft.replace(R.id.fragment, newFragment, FileDetailFragment.FTAG);
-        ft.commit();
-    }
-    
-    @Override
-    public void onActivityResult (int requestCode, int resultCode, Intent data) {
-        Log_OC.e(TAG, "onActivityResult");
-        super.onActivityResult(requestCode, resultCode, data);
-    }
-
-    @Override
-    public void onConfigurationChanged (Configuration newConfig) {
-        super.onConfigurationChanged(newConfig);
-        if (mStarted) {
-            checkConfigurationChange(newConfig);
-        } else {
-            mNewConfigurationChangeToApplyOnStart = newConfig;
-        }
-    }
-    
-    
-    @Override
-    protected void onSaveInstanceState(Bundle outState) {
-        super.onSaveInstanceState(outState);
-        outState.putBoolean(KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
-    }
-    
-    
-    @Override
-    public void onStart() {
-        super.onStart();
-        Log_OC.e(TAG, "onStart");
-        if (mNewConfigurationChangeToApplyOnStart != null && !isRedirectingToSetupAccount()) {
-            checkConfigurationChange(mNewConfigurationChangeToApplyOnStart);
-            mNewConfigurationChangeToApplyOnStart = null;
-        }
-        mStarted = true;
-    }
-
-    private void checkConfigurationChange(Configuration newConfig) {
-        finish();
-        Intent intent = null;
-        OCFile file = getFile();
-        Account account = getAccount();
-        if ((newConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
-                && newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
-            
-            intent = new Intent(this, FileDisplayActivity.class);
-            intent.putExtra(EXTRA_FILE, file);
-            intent.putExtra(EXTRA_ACCOUNT, account);
-            intent.putExtra(EXTRA_MODE, getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW));
-            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-            Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-            if (fragment != null && file != null && fragment instanceof PreviewMediaFragment && file.isVideo()) {
-                PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
-                intent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, videoFragment.getPosition());
-                intent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, videoFragment.isPlaying());
-            }
-        
-        } else {
-            intent = new Intent(this, FileDetailActivity.class);
-            intent .putExtra(EXTRA_FILE, file);
-            intent .putExtra(EXTRA_ACCOUNT, account);
-            intent.putExtra(EXTRA_MODE, getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW));
-            Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-            if (fragment != null && file != null && fragment instanceof PreviewMediaFragment && file.isVideo()) {
-                PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
-                intent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, videoFragment.getPosition());
-                intent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, videoFragment.isPlaying());
-            }
-            // and maybe 'waiting to preview' flag
-        }
-        startActivity(intent);
-    }
-
-    @Override
-    public void onStop() {
-        super.onStop();
-        Log_OC.e(TAG, "onStop");
-        mStarted = false;
-    }
-    @Override
-    public void onPause() {
-        super.onPause();
-        Log_OC.e(TAG, "onPause");
-        if (mDownloadFinishReceiver != null) {
-            unregisterReceiver(mDownloadFinishReceiver);
-            mDownloadFinishReceiver = null;
-        }
-    }
-
-    
-    @Override
-    public void onResume() {
-        super.onResume();
-        Log_OC.e(TAG, "onResume");
-        // TODO this is probably unnecessary
-        Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-        if (fragment != null && fragment instanceof FileDetailFragment) {
-            ((FileDetailFragment) fragment).updateFileDetails(false, false);
-        }
-            
-        // Listen for download messages
-        IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_ADDED_MESSAGE);
-        downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
-        mDownloadFinishReceiver = new DownloadFinishReceiver();
-        registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
-    }
-    
-    
-    /** Defines callbacks for service binding, passed to bindService() */
-    private class DetailsServiceConnection implements ServiceConnection {
-
-        @Override
-        public void onServiceConnected(ComponentName component, IBinder service) {
-                
-            if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {
-                Log_OC.d(TAG, "Download service connected");
-                mDownloaderBinder = (FileDownloaderBinder) service;
-                if (mWaitingToPreview) {
-                    requestForDownload();
-                }
-                    
-            } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {
-                Log_OC.d(TAG, "Upload service connected");
-                mUploaderBinder = (FileUploaderBinder) service;
-            } else {
-                return;
-            }
-            
-            Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-            FileDetailFragment detailsFragment = (fragment instanceof FileDetailFragment) ? (FileDetailFragment) fragment : null;
-            if (detailsFragment != null) {
-                detailsFragment.listenForTransferProgress();
-                detailsFragment.updateFileDetails(mWaitingToPreview, false);   // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName component) {
-            if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {
-                Log_OC.d(TAG, "Download service disconnected");
-                mDownloaderBinder = null;
-            } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {
-                Log_OC.d(TAG, "Upload service disconnected");
-                mUploaderBinder = null;
-            }
-        }
-    };    
-    
-    
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-        Log_OC.e(TAG,  "onDestroy");
-        if (mDownloadConnection != null) {
-            unbindService(mDownloadConnection);
-            mDownloadConnection = null;
-        }
-        if (mUploadConnection != null) {
-            unbindService(mUploadConnection);
-            mUploadConnection = null;
-        }
-    }
-    
-    
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        boolean returnValue = false;
-        
-        switch(item.getItemId()){
-        case android.R.id.home:
-            backToDisplayActivity(true);
-            returnValue = true;
-            break;
-        default:
-            returnValue = super.onOptionsItemSelected(item);
-        }
-        
-        return returnValue;
-    }
-
-    @Override
-    public void onBackPressed() {
-        backToDisplayActivity(true);
-    }
-    
-    private void backToDisplayActivity(boolean moveToParent) {
-        Intent intent = new Intent(this, FileDisplayActivity.class);
-        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        OCFile targetFile = null;
-        OCFile file = getFile();
-        if (file != null) {
-            targetFile = moveToParent ? mStorageManager.getFileById(file.getParentId()) : file;
-        }
-        intent.putExtra(EXTRA_FILE, targetFile);
-        intent.putExtra(EXTRA_ACCOUNT, getAccount());
-        startActivity(intent);
-        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;
-    }
-    
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onFileStateChanged() {
-        // nothing to do here!
-    }
-
-    
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public FileDownloaderBinder getFileDownloaderBinder() {
-        return mDownloaderBinder;
-    }
-
-
-    @Override
-    public FileUploaderBinder getFileUploaderBinder() {
-        return mUploaderBinder;
-    }
-
-
-    @Override
-    public void showFragmentWithDetails(OCFile file) {
-        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-        transaction.replace(R.id.fragment, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG); 
-        transaction.commit();
-    }
-
-    
-    private void requestForDownload() {
-        if (!mDownloaderBinder.isDownloading(getAccount(), getFile())) {
-            Intent i = new Intent(this, FileDownloader.class);
-            i.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
-            i.putExtra(FileDownloader.EXTRA_FILE, getFile());
-            startService(i);
-        }
-    }
-
-    
-    /**
-     * Class waiting for broadcast events from the {@link FielDownloader} service.
-     * 
-     * Updates the UI when a download is started or finished, provided that it is relevant for the
-     * current file.
-     */
-    private class DownloadFinishReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            boolean sameAccount = isSameAccount(context, intent);
-            String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
-            boolean samePath = (getFile() != null && getFile().getRemotePath().equals(downloadedRemotePath));
-            
-            if (sameAccount && samePath) {
-                updateChildFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
-            }
-            
-            removeStickyBroadcast(intent);
-        }
-
-        private boolean isSameAccount(Context context, Intent intent) {
-            String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
-            return (accountName != null && accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name));
-        }
-    }
-
-
-    public void updateChildFragment(String downloadEvent, String downloadedRemotePath, boolean success) {
-        Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-        if (fragment != null && fragment instanceof FileDetailFragment) {
-            FileDetailFragment detailsFragment = (FileDetailFragment) fragment;
-            OCFile fileInFragment = detailsFragment.getFile();
-            if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
-                // this never should happen; fileInFragment should be always equals to mFile, that was compared to downloadedRemotePath in DownloadReceiver 
-                mWaitingToPreview = false;
-                
-            } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
-                // grants that the progress bar is updated
-                detailsFragment.listenForTransferProgress();
-                detailsFragment.updateFileDetails(true, false);
-                
-            } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {
-                //  refresh the details fragment 
-                if (success && mWaitingToPreview) {
-                    setFile(mStorageManager.getFileById(getFile().getFileId()));   // update the file from database, for the local storage path
-                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-                    transaction.replace(R.id.fragment, new PreviewMediaFragment(getFile(), getAccount(), 0, true), FileDetailFragment.FTAG);
-                    transaction.commit();
-                    mWaitingToPreview = false;
-                    
-                } else {
-                    detailsFragment.updateFileDetails(false, (success));
-                    // TODO error message if !success Â¿?
-                }
-            }
-        } // TODO else if (fragment != null && fragment )
-        
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onAccountChanged() {
-        mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
-        
-        FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-        if (fragment != null && mStorageManager.getFileById(fragment.getFile().getFileId()) == null) {
-            /// the account was forced to be changed; probably was deleted from system settings
-            backToDisplayActivity(false);
-        }
-    }
-
-}
index c62a28d..bcd62a3 100644 (file)
@@ -33,7 +33,6 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
-import android.content.res.Configuration;
 import android.content.res.Resources.NotFoundException;
 import android.database.Cursor;
 import android.net.Uri;
@@ -44,6 +43,7 @@ import android.preference.PreferenceManager;
 import android.provider.MediaStore;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
@@ -84,7 +84,6 @@ import com.owncloud.android.ui.fragment.FileDetailFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
-import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.ui.preview.PreviewMediaFragment;
 import com.owncloud.android.ui.preview.PreviewVideoActivity;
 
@@ -99,8 +98,6 @@ public class FileDisplayActivity extends FileActivity implements
     OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener, EditNameDialogListener {
     
     private ArrayAdapter<String> mDirectories;
-    //private OCFile mCurrentDir = null;
-    private OCFile mChosenFile = null;
 
     /** Access point to the cached database for the current ownCloud {@link Account} */
     private DataStorageManager mStorageManager = null;
@@ -113,42 +110,39 @@ public class FileDisplayActivity extends FileActivity implements
     private ServiceConnection mDownloadConnection = null, mUploadConnection = null;
     private RemoteOperationResult mLastSslUntrustedServerResult = null;
     
-    private OCFileListFragment mFileList;
-    
     private boolean mDualPane;
+    private View mLeftFragmentContainer;
+    private View mRightFragmentContainer;
+    
+    private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     
     public static final int DIALOG_SHORT_WAIT = 0;
     private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
     private static final int DIALOG_SSL_VALIDATOR = 2;
     private static final int DIALOG_CERT_NOT_SAVED = 3;
     
+    public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
+    
     private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
     private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
     
     private static final String TAG = FileDisplayActivity.class.getSimpleName();
 
+    private static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
+    private static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT";
+
     private OCFile mWaitingToPreview;
     private Handler mHandler;
-    
-    private Configuration mNewConfigurationChangeToApplyOnStart;
-    private boolean mStarted;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         Log_OC.d(TAG, "onCreate() start");
-        super.onCreate(savedInstanceState);
+        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+        
+        super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account is valid
         
-        mStarted = false;
         mHandler = new Handler();
 
-        /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
-        if(savedInstanceState != null) {
-            mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDetailActivity.KEY_WAITING_TO_PREVIEW);
-
-        } else {
-            mWaitingToPreview = null;
-        }
-        
         /// bindings to transference services
         mUploadConnection = new ListServiceConnection(); 
         mDownloadConnection = new ListServiceConnection();
@@ -160,38 +154,47 @@ public class FileDisplayActivity extends FileActivity implements
             requestPinCode();
         }
 
-        // file observer
+        /// file observer
         Intent observer_intent = new Intent(this, FileObserverService.class);
         observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);
         startService(observer_intent);
             
+        /// Load of saved instance state
+        if(savedInstanceState != null) {
+            mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
+
+        } else {
+            mWaitingToPreview = null;
+        }
+        
         /// USER INTERFACE
-        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
             
-        // Drop-down navigation 
-        mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
-        OCFile currFile = getFile();
-        while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
-            mDirectories.add(currFile.getFileName());
-            currFile = mStorageManager.getFileById(currFile.getParentId());
-        }
-        mDirectories.add(OCFile.PATH_SEPARATOR);
-
         // Inflate and set the layout view
         setContentView(R.layout.files);    
-        mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
-        mDualPane = (findViewById(R.id.file_details_container) != null);
-        if (mDualPane && savedInstanceState == null) {
-            initFileDetailsInDualPane();
+        mDualPane = getResources().getBoolean(R.bool.large_land_layout);
+        mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
+        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
-        actionBar.setDisplayHomeAsUpEnabled(getFile() != null && getFile().getParentId() != 0);
-        actionBar.setDisplayShowTitleEnabled(false);
-        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
-        actionBar.setListNavigationCallbacks(mDirectories, this);
         setSupportProgressBarIndeterminateVisibility(false);        // always AFTER setContentView(...) ; to workaround bug in its implementation
         
         Log_OC.d(TAG, "onCreate() end");
@@ -199,97 +202,219 @@ public class FileDisplayActivity extends FileActivity implements
 
     
     @Override
-    public void onConfigurationChanged (Configuration newConfig) {
-        super.onConfigurationChanged(newConfig);
-        if (mStarted) {
-            checkConfigurationChange(newConfig);
-        } else {
-            mNewConfigurationChangeToApplyOnStart = newConfig;
-        }
+    protected void onDestroy() {
+        super.onDestroy();
+        if (mDownloadConnection != null)
+            unbindService(mDownloadConnection);
+        if (mUploadConnection != null)
+            unbindService(mUploadConnection);
     }
     
     
-    private void initFileDetailsInDualPane() {
-        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);
-                        mWaitingToPreview = mChosenFile;
+    /**
+     *  Called when the ownCloud {@link Account} associated to the Activity was just updated.
+     */ 
+    @Override
+    protected void onAccountSet(boolean stateWasRecovered) {
+        if (getAccount() != null) {
+            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+            
+            /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
+            OCFile file = getFile();
+            if (file != null) {
+                if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
+                    // upload in progress - right now, files are not inserted in the local cache until the upload is successful
+                    if (mStorageManager.getFileById(file.getParentId()) == null) {
+                        file = null;    // not able to know the directory where the file is uploading
                     }
                 } else {
-                    transaction.replace(R.id.file_details_container, new FileDetailFragment(mChosenFile, getAccount()), FileDetailFragment.FTAG);
+                    file = mStorageManager.getFileByPath(file.getRemotePath());   // currentDir = null if not in the current Account
                 }
-                mChosenFile = null;
-                
+            }
+            if (file == null) {
+                // fall back to root folder
+                file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);  // never should return null
+            }
+            setFile(file);
+            
+            if (findViewById(android.R.id.content) != null && !stateWasRecovered) {
+                Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
+                initFragmentsWithFile();
             } else {
-                transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
+                Log_OC.e(TAG, "Fragment initializacion ignored in onAccountChanged due to lack of CONTENT VIEW");
             }
-            transaction.commit();
+            
+        } else {
+            Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
         }
     }
     
     
-    @Override
-    protected void onStart() {
-        super.onStart();
-        if (mNewConfigurationChangeToApplyOnStart != null) {
-            checkConfigurationChange(mNewConfigurationChangeToApplyOnStart);
-            mNewConfigurationChangeToApplyOnStart = null;
+    private void createMinFragments() {
+        OCFileListFragment listOfFiles = new OCFileListFragment();
+        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+        transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
+        transaction.commit();
+    }
+
+    private void initFragmentsWithFile() {
+        if (getAccount() != null && getFile() != null) {
+            /// Second fragment
+            OCFile file = getFile(); 
+            Fragment secondFragment = chooseInitialSecondFragment(file);
+            if (secondFragment != null) {
+                setSecondFragment(secondFragment);
+            }
+            
+        } else {
+            Log.wtf(TAG, "initFragments() called with invalid NULLs!");
+            if (getAccount() == null) {
+                Log.wtf(TAG, "\t account is NULL");
+            }
+            if (getFile() == null) {
+                Log.wtf(TAG, "\t file is NULL");
+            }
+        }
+    }
+
+    private Fragment chooseInitialSecondFragment(OCFile file) {
+        Fragment secondFragment = null;
+        if (file != null && !file.isDirectory()) {
+            if (file.isDown() && PreviewMediaFragment.canBePreviewed(file) 
+                    && file.getLastSyncDateForProperties() > 0  // temporal fix
+                    ) {
+                int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
+                boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
+                secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
+                
+            } else {
+                secondFragment = new FileDetailFragment(file, getAccount());
+            }
         }
-        mStarted = true;
+        return secondFragment;
     }
+
     
-    @Override
-    protected void onStop() {
-        super.onStop();
-        mStarted = false;
+    /**
+     * Replaces the second fragment managed by the activity with the received as
+     * a parameter.
+     * 
+     * Assumes never will be more than two fragments managed at the same time. 
+     * 
+     * @param fragment      New second Fragment to set.
+     */
+    private void setSecondFragment(Fragment fragment) {
+        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+        transaction.replace(R.id.right_fragment_container, fragment, TAG_SECOND_FRAGMENT);
+        transaction.commit();
     }
     
     
-    private void checkConfigurationChange(Configuration newConfig) {
-        FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-        if (fragment != null 
-                && fragment.getFile() != null 
-                && (newConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
-                && newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE) {
+    private void updateFragmentsVisibility(boolean existsSecondFragment) {
+        if (mDualPane) {
+            if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
+                mLeftFragmentContainer.setVisibility(View.VISIBLE);
+            }
+            if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
+                mRightFragmentContainer.setVisibility(View.VISIBLE);
+            }
+            
+        } else if (existsSecondFragment) {
+            if (mLeftFragmentContainer.getVisibility() != View.GONE) {
+                mLeftFragmentContainer.setVisibility(View.GONE);
+            }
+            if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
+                mRightFragmentContainer.setVisibility(View.VISIBLE);
+            }
             
-            onFileClick(fragment.getFile(), true);
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.remove((Fragment)fragment);
-            transaction.commit();
-        
         } else {
-            finish();
-            Intent intent = new Intent(this, FileDisplayActivity.class);
-            intent.putExtra(EXTRA_FILE, getFile());
-            intent.putExtra(EXTRA_ACCOUNT, getAccount());
-            startActivity(intent);
+            if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
+                mLeftFragmentContainer.setVisibility(View.VISIBLE);
+            }
+            if (mRightFragmentContainer.getVisibility() != View.GONE) {
+                mRightFragmentContainer.setVisibility(View.GONE);
+            }
         }
     }
 
-
-    @Override
-    protected void onDestroy() {
-        super.onDestroy();
-        if (mDownloadConnection != null)
-            unbindService(mDownloadConnection);
-        if (mUploadConnection != null)
-            unbindService(mUploadConnection);
+    
+    private OCFileListFragment getListOfFilesFragment() {
+        Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES);
+        if (listOfFiles != null) {
+            return (OCFileListFragment)listOfFiles;
+        }
+        Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
+        return null;
+    }
+    
+    protected FileFragment getSecondFragment() {
+        Fragment second = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT);
+        if (second != null) {
+            return (FileFragment)second;
+        }
+        return null;
     }
 
+    public void cleanSecondFragment() {
+        Fragment second = getSecondFragment();
+        if (second != null) {
+            FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
+            tr.remove(second);
+            tr.commit();
+            updateFragmentsVisibility(false);
+        }
+    }
     
+    protected void refeshListOfFilesFragment() {
+        OCFileListFragment fileListFragment = getListOfFilesFragment();
+        if (fileListFragment != null) { 
+            fileListFragment.listDirectory();
+        }
+    }
+
+    protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath, boolean success) {
+        FileFragment secondFragment = getSecondFragment();
+        boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
+        if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
+            FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
+            OCFile fileInFragment = detailsFragment.getFile();
+            if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
+                // the user browsed to other file ; forget the automatic preview 
+                mWaitingToPreview = null;
+                
+            } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
+                // grant that the right panel updates the progress bar
+                detailsFragment.listenForTransferProgress();
+                detailsFragment.updateFileDetails(true, false);
+                
+            } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {
+                //  update the right panel
+                boolean detailsFragmentChanged = false;
+                if (waitedPreview) {
+                    if (success) {
+                        mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId());   // update the file from database, for the local storage path
+                        if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
+                            startMediaPreview(mWaitingToPreview, 0, true);
+                            detailsFragmentChanged = true;
+                        } else {
+                            openFile(mWaitingToPreview);
+                        }
+                    }
+                    mWaitingToPreview = null;
+                }
+                if (!detailsFragmentChanged) {
+                    detailsFragment.updateFileDetails(false, (success));
+                }
+            }
+        }
+    }
+
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getSherlock().getMenuInflater();
-            inflater.inflate(R.menu.main_menu, menu);
-            
-            return true;
+        inflater.inflate(R.menu.main_menu, menu);
+        return true;
     }
 
     @Override
@@ -315,7 +440,10 @@ public class FileDisplayActivity extends FileActivity implements
                 break;
             }
             case android.R.id.home: {
-                if(getFile() != null && getFile().getParentId() != 0){
+                FileFragment second = getSecondFragment();
+                OCFile currentDir = getCurrentDir();
+                if((currentDir != null && currentDir.getParentId() != 0) || 
+                        (second != null && second.getFile() != null)) {
                     onBackPressed(); 
                 }
                 break;
@@ -389,7 +517,7 @@ public class FileDisplayActivity extends FileActivity implements
             startService(i);
             
         } else {
-            Log_OC.d("FileDisplay", "User clicked on 'Update' with no selection");
+            Log_OC.d(TAG, "User clicked on 'Update' with no selection");
             Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), Toast.LENGTH_LONG);
             t.show();
             return;
@@ -411,12 +539,12 @@ public class FileDisplayActivity extends FileActivity implements
                 filepath = filemanagerstring;
             
         } catch (Exception e) {
-            Log_OC.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
+            Log_OC.e(TAG, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
             e.printStackTrace();
             
         } finally {
             if (filepath == null) {
-                Log_OC.e("FileDisplay", "Couldnt resolve path to file");
+                Log_OC.e(TAG, "Couldnt resolve path to file");
                 Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);
                 t.show();
                 return;
@@ -442,55 +570,47 @@ public class FileDisplayActivity extends FileActivity implements
         startService(i);
     }
 
-
     @Override
     public void onBackPressed() {
-        if (mDirectories.getCount() <= 1) {
-            finish();
-            return;
-        }
-        popDirname();
-        mFileList.onNavigateUp();
-        setFile(mFileList.getCurrentFile());
-        
-        if (mDualPane) {
-            // Resets the FileDetailsFragment on Tablets so that it always displays
-            Fragment fileFragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-            if (fileFragment != null && (fileFragment instanceof PreviewMediaFragment || !((FileDetailFragment) fileFragment).isEmpty())) {
-                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-                transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment                
-                transaction.commit();
+        OCFileListFragment listOfFiles = getListOfFilesFragment(); 
+        if (mDualPane || getSecondFragment() == null) {
+            if (listOfFiles != null) {  // should never be null, indeed
+                if (mDirectories.getCount() <= 1) {
+                    finish();
+                    return;
+                }
+                popDirname();
+                listOfFiles.onBrowseUp();
             }
         }
-        
-        if(getFile().getParentId() == 0){
-            ActionBar actionBar = getSupportActionBar(); 
-            actionBar.setDisplayHomeAsUpEnabled(false);
-        } 
+        if (listOfFiles != null) {  // should never be null, indeed
+            setFile(listOfFiles.getCurrentFile());
+        }
+        cleanSecondFragment();
+        updateNavigationElementsInActionBar(null);
     }
 
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
-        Log_OC.d(TAG, "onSaveInstanceState() start");
+        Log_OC.e(TAG, "onSaveInstanceState() start");
         super.onSaveInstanceState(outState);
-        if (mDualPane) {
-            FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-            if (fragment != null) {
-                OCFile file = fragment.getFile();
-                if (file != null) {
-                    outState.putParcelable(EXTRA_FILE, file);
-                }
-            }
-        }
-        outState.putParcelable(FileDetailActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
+        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() {
-        Log_OC.d(TAG, "onResume() start");
         super.onResume();
+        Log_OC.e(TAG, "onResume() start");
 
         // Listen for sync messages
         IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);
@@ -509,7 +629,10 @@ public class FileDisplayActivity extends FileActivity implements
         registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
     
         // List current directory
-        mFileList.listDirectory(getFile());   // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
+        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");
     }
@@ -517,8 +640,8 @@ public class FileDisplayActivity extends FileActivity implements
     
     @Override
     protected void onPause() {
-        Log_OC.d(TAG, "onPause() start");
         super.onPause();
+        Log_OC.e(TAG, "onPause() start");
         if (mSyncBroadcastReceiver != null) {
             unregisterReceiver(mSyncBroadcastReceiver);
             mSyncBroadcastReceiver = null;
@@ -704,14 +827,14 @@ public class FileDisplayActivity extends FileActivity implements
             boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);
             String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
 
-            Log_OC.d("FileDisplay", "sync of account " + accountName + " is in_progress: " + inProgress);
+            Log_OC.d(TAG, "sync of account " + accountName + " is in_progress: " + inProgress);
 
             if (getAccount() != null && accountName.equals(getAccount().name)) {  
             
                 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); 
                  
                 boolean fillBlankRoot = false;
-                OCFile currentDir = getFile();
+                OCFile currentDir = getCurrentDir();
                 if (currentDir == null) {
                     currentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
                     fillBlankRoot = (currentDir != null);
@@ -721,8 +844,7 @@ public class FileDisplayActivity extends FileActivity implements
                         || fillBlankRoot ) {
                     if (!fillBlankRoot) 
                         currentDir = getStorageManager().getFileByPath(synchFolderRemotePath);
-                    OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
-                            .findFragmentById(R.id.fileList);
+                    OCFileListFragment fileListFragment = getListOfFilesFragment();
                     if (fileListFragment != null) {
                         fileListFragment.listDirectory(currentDir);
                     }
@@ -756,12 +878,10 @@ public class FileDisplayActivity extends FileActivity implements
             String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
             String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
             boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
-            boolean isDescendant = (getFile() != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(getFile().getRemotePath()));
+            OCFile currentDir = getCurrentDir();
+            boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
             if (sameAccount && isDescendant) {
-                OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
-                if (fileListFragment != null) { 
-                    fileListFragment.listDirectory();
-                }
+                refeshListOfFilesFragment();
             }
         }
         
@@ -782,17 +902,16 @@ public class FileDisplayActivity extends FileActivity implements
             boolean isDescendant = isDescendant(downloadedRemotePath);
             
             if (sameAccount && isDescendant) {
-                updateLeftPanel();
-                if (mDualPane) {
-                    updateRightPanel(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
-                }
+                refeshListOfFilesFragment();
+                refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
             }
             
             removeStickyBroadcast(intent);
         }
 
         private boolean isDescendant(String downloadedRemotePath) {
-            return (getFile() != null && downloadedRemotePath != null && downloadedRemotePath.startsWith(getFile().getRemotePath()));
+            OCFile currentDir = getCurrentDir();
+            return (currentDir != null && downloadedRemotePath != null && downloadedRemotePath.startsWith(currentDir.getRemotePath()));
         }
 
         private boolean isSameAccount(Context context, Intent intent) {
@@ -802,45 +921,6 @@ public class FileDisplayActivity extends FileActivity implements
     }
     
     
-    protected void updateLeftPanel() {
-        OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
-        if (fileListFragment != null) { 
-            fileListFragment.listDirectory();
-        }
-    }
-
-    protected void updateRightPanel(String downloadEvent, String downloadedRemotePath, boolean success) {
-        Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-        boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
-        if (fragment != null && fragment instanceof FileDetailFragment) {
-            FileDetailFragment detailsFragment = (FileDetailFragment) fragment;
-            OCFile fileInFragment = detailsFragment.getFile();
-            if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
-                // the user browsed to other file ; forget the automatic preview 
-                mWaitingToPreview = null;
-                
-            } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
-                // grant that the right panel updates the progress bar
-                detailsFragment.listenForTransferProgress();
-                detailsFragment.updateFileDetails(true, false);
-                
-            } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {
-                //  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();
-                    mWaitingToPreview = null;
-                    
-                } else {
-                    detailsFragment.updateFileDetails(false, (success));
-                }
-            }
-        }
-    }
-
-
     /**
      * {@inheritDoc}
      */
@@ -852,122 +932,108 @@ public class FileDisplayActivity extends FileActivity implements
 
     /**
      * {@inheritDoc}
+     * 
+     * Updates action bar and second fragment, if in dual pane mode.
      */
     @Override
-    public void onDirectoryClick(OCFile directory) {
+    public void onBrowsedDownTo(OCFile directory) {
         pushDirname(directory);
-        ActionBar actionBar = getSupportActionBar();
-        actionBar.setDisplayHomeAsUpEnabled(true);
-        
-        if (mDualPane) {
-            // Resets the FileDetailsFragment on Tablets so that it always displays
-            Fragment fileFragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-            if (fileFragment != null && (fileFragment instanceof PreviewMediaFragment || !((FileDetailFragment) fileFragment).isEmpty())) {
-                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-                transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment                
-                transaction.commit();
-            }
-        }
+        cleanSecondFragment();
+        updateNavigationElementsInActionBar(null);
     }
     
-    
     /**
-     * {@inheritDoc}
+     * Opens the image gallery showing the image {@link OCFile} received as parameter.
+     * 
+     * @param file                      Image {@link OCFile} to show.
      */
     @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();
-                    }
-                    startMediaPreview(file, startPlaybackPosition, autoplay, onOrientationChange);
-                }
-                
-            } else {
-                // automatic download, preview on finish
-                startDownloadForPreview(file, onOrientationChange);
-                
-            }
-        } else {
-            // details view
-            startDetails(file, onOrientationChange);
-        }
-    }
-
-    private void startPreviewImage(OCFile file) {
+    public void startImagePreview(OCFile file) {
         Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
         showDetailsIntent.putExtra(EXTRA_FILE, file);
         showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
         startActivity(showDetailsIntent);
     }
     
-    private void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay, boolean onOrientationChange) {
-        if (mDualPane && !onOrientationChange) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.replace(R.id.file_details_container, new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
-            transaction.commit();
-            
-        } else {
-            Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            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);
-        }
+    /**
+     * Stars the preview of an already down media {@link OCFile}.
+     * 
+     * @param file                      Media {@link OCFile} to preview.
+     * @param startPlaybackPosition     Media position where the playback will be started, in milliseconds.
+     * @param autoplay                  When 'true', the playback will start without user interactions.
+     */
+    @Override
+    public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
+        Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
+        setSecondFragment(mediaFragment);
+        updateFragmentsVisibility(true);
+        updateNavigationElementsInActionBar(file);
+        setFile(file);
     }
     
-    private void startDownloadForPreview(OCFile file, boolean onOrientationChange) {
-        if (mDualPane && !onOrientationChange) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.replace(R.id.file_details_container, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG);
-            transaction.commit();
-            mWaitingToPreview = file;
-            requestForDownload();
-            
-        } else {
-            Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(EXTRA_FILE, file);
-            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
-            startActivity(showDetailsIntent);
-        }
+    /**
+     * Requests the download of the received {@link OCFile} , updates the UI
+     * to monitor the download progress and prepares the activity to preview
+     * or open the file when the download finishes.
+     * 
+     * @param file          {@link OCFile} to download and preview.
+     */
+    @Override
+    public void startDownloadForPreview(OCFile file) {
+        Fragment detailFragment = new FileDetailFragment(file, getAccount());
+        setSecondFragment(detailFragment);
+        mWaitingToPreview = file;
+        requestForDownload();
+        updateFragmentsVisibility(true);
+        updateNavigationElementsInActionBar(file);
+        setFile(file);
     }
 
     
-    private void startDetails(OCFile file, boolean onOrientationChange) {
-        if (mDualPane && !file.isImage() && !onOrientationChange) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.replace(R.id.file_details_container, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG);
-            transaction.commit();
+    /**
+     * Shows the information of the {@link OCFile} received as a 
+     * parameter in the second fragment.
+     * 
+     * @param file          {@link OCFile} whose details will be shown
+     */
+    @Override
+    public void showDetails(OCFile file) {
+        Fragment detailFragment = new FileDetailFragment(file, getAccount());
+        setSecondFragment(detailFragment);
+        updateFragmentsVisibility(true);
+        updateNavigationElementsInActionBar(file);
+        setFile(file);
+    }
+    
+    
+    /**
+     * TODO
+     */
+    private void updateNavigationElementsInActionBar(OCFile currentFile) {
+        ActionBar actionBar = getSupportActionBar(); 
+        if (currentFile == null || mDualPane) {
+            // only list of files - set for browsing through folders
+            OCFile currentDir = getCurrentDir();
+            actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0);
+            actionBar.setDisplayShowTitleEnabled(false);
+            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+            actionBar.setListNavigationCallbacks(mDirectories, this);   // assuming mDirectories is updated
+            
         } else {
-            Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(EXTRA_FILE, file);
-            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
-            startActivity(showDetailsIntent);
+            actionBar.setDisplayHomeAsUpEnabled(true);
+            actionBar.setDisplayShowTitleEnabled(true);
+            actionBar.setTitle(currentFile.getFileName());
+            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
         }
     }
-
-
+    
+    
     /**
      * {@inheritDoc}
      */
     @Override
     public OCFile getInitialDirectory() {
-        return getFile();
+        return getCurrentDir();
     }
     
     
@@ -976,10 +1042,7 @@ public class FileDisplayActivity extends FileActivity implements
      */
     @Override
     public void onFileStateChanged() {
-        OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
-        if (fileListFragment != null) { 
-            fileListFragment.listDirectory();
-        }
+        refeshListOfFilesFragment();
     }
 
     
@@ -1020,15 +1083,15 @@ public class FileDisplayActivity extends FileActivity implements
                 return;
             }
             // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
-            if (mFileList != null)
-                mFileList.listDirectory();
-            if (mDualPane) {
-                Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-                if (fragment != null && fragment instanceof FileDetailFragment) {
-                    FileDetailFragment detailFragment = (FileDetailFragment)fragment;
-                    detailFragment.listenForTransferProgress();
-                    detailFragment.updateFileDetails(false, false);
-                }
+            OCFileListFragment listOfFiles = getListOfFilesFragment(); 
+            if (listOfFiles != null) {
+                listOfFiles.listDirectory();
+            }
+            FileFragment secondFragment = getSecondFragment();
+            if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
+                FileDetailFragment detailFragment = (FileDetailFragment)secondFragment;
+                detailFragment.listenForTransferProgress();
+                detailFragment.updateFileDetails(false, false);
             }
         }
 
@@ -1110,16 +1173,13 @@ public class FileDisplayActivity extends FileActivity implements
             Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
             OCFile removedFile = operation.getFile();
-            if (mDualPane) {
-                FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
-                if (details != null && removedFile.equals(details.getFile())) {
-                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-                    transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
-                    transaction.commit();
-                }
+            getSecondFragment();
+            FileFragment second = getSecondFragment();
+            if (second != null && removedFile.equals(second.getFile())) {
+                cleanSecondFragment();
             }
-            if (mStorageManager.getFileById(removedFile.getParentId()).equals(getFile())) {
-                mFileList.listDirectory();
+            if (mStorageManager.getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
+                refeshListOfFilesFragment();
             }
                 
         } else {
@@ -1141,7 +1201,7 @@ public class FileDisplayActivity extends FileActivity implements
     private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
         if (result.isSuccess()) {
             dismissDialog(DIALOG_SHORT_WAIT);
-            mFileList.listDirectory();
+            refeshListOfFilesFragment();
             
         } else {
             dismissDialog(DIALOG_SHORT_WAIT);
@@ -1168,13 +1228,13 @@ public class FileDisplayActivity extends FileActivity implements
         OCFile renamedFile = operation.getFile();
         if (result.isSuccess()) {
             if (mDualPane) {
-                FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+                FileFragment details = getSecondFragment();
                 if (details != null && details instanceof FileDetailFragment && renamedFile.equals(details.getFile()) ) {
                     ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
                 }
             }
-            if (mStorageManager.getFileById(renamedFile.getParentId()).equals(getFile())) {
-                mFileList.listDirectory();
+            if (mStorageManager.getFileById(renamedFile.getParentId()).equals(getCurrentDir())) {
+                refeshListOfFilesFragment();
             }
             
         } else {
@@ -1211,7 +1271,7 @@ public class FileDisplayActivity extends FileActivity implements
             
         } else {
             if (operation.transferWasRequested()) {
-                mFileList.listDirectory();
+                refeshListOfFilesFragment();
                 onTransferStateChanged(syncedFile, true, true);
                 
             } else {
@@ -1227,12 +1287,8 @@ public class FileDisplayActivity extends FileActivity implements
      */
     @Override
     public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
-        /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
-        if (fileListFragment != null) { 
-            fileListFragment.listDirectory();
-        }*/
         if (mDualPane) {
-            FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+            FileFragment details = getSecondFragment();
             if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) {
                 if (downloading || uploading) {
                     ((FileDetailFragment)details).updateFileDetails(file, getAccount());
@@ -1244,41 +1300,16 @@ public class FileDisplayActivity extends FileActivity implements
     }
 
 
-    @Override
-    public void showFragmentWithDetails(OCFile file) {
-        if (mDualPane) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.replace(R.id.file_details_container, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG); 
-            transaction.commit();
-            
-        } else {
-            Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
-            showDetailsIntent.putExtra(EXTRA_FILE, file);
-            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
-            showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
-            startActivity(showDetailsIntent);
-        }
-    }
-
     public void onDismiss(EditNameDialog dialog) {
         if (dialog.getResult()) {
             String newDirectoryName = dialog.getNewFilename().trim();
             Log_OC.d(TAG, "'create directory' dialog dismissed with new name " + newDirectoryName);
             if (newDirectoryName.length() > 0) {
-                String path;
-                if (getFile() == null) {
-                    // this is just a patch; we should ensure that mCurrentDir never is null
-                    if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) {
-                        OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
-                        mStorageManager.saveFile(file);
-                    }
-                    setFile(mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR));
-                }
-                path = FileDisplayActivity.this.getFile().getRemotePath();
+                String path = getCurrentDir().getRemotePath();
                 
                 // Create directory
                 path += newDirectoryName + OCFile.PATH_SEPARATOR;
-                RemoteOperation operation = new CreateFolderOperation(path, getFile().getFileId(), mStorageManager);
+                RemoteOperation operation = new CreateFolderOperation(path, getCurrentDir().getFileId(), mStorageManager);
                 operation.execute(  getAccount(), 
                                     FileDisplayActivity.this, 
                                     FileDisplayActivity.this, 
@@ -1300,44 +1331,19 @@ public class FileDisplayActivity extends FileActivity implements
             startService(i);
         }
     }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onAccountChanged() {
-        if (getAccount() != null) {
-            mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
-            
-            /// Check if the 'main' @OCFile handled by the Activity is a directory
-            OCFile currentDir = getFile();
-            if(currentDir != null && !currentDir.isDirectory()) {
-                mChosenFile = getFile();
-                currentDir = mStorageManager.getFileById(currentDir.getParentId());
-            }
-            
-            /// Check if currentDir and mChosenFile are in the current account, and update them
-            if (currentDir != null) {
-                currentDir = mStorageManager.getFileByPath(currentDir.getRemotePath());   // currentDir = null if not in the current Account
-            }
-            if (mChosenFile != null) {
-                if (mChosenFile.fileExists()) {
-                    mChosenFile = mStorageManager.getFileByPath(mChosenFile.getRemotePath());   // mChosenFile = null if not in the current Account
-                }   // else : keep mChosenFile with the received value; this is currently the case of an upload in progress, when the user presses the status notification in a landscape tablet
-            }
-            
-            /// Default to root if mCurrentDir was not found
-            if (currentDir == null) {
-                currentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);  // never returns null
+    
+    
+    private OCFile getCurrentDir() {
+        OCFile file = getFile();
+        if (file != null) {
+            if (file.isDirectory()) {
+                return file;
+            } else {
+                return mStorageManager.getFileById(file.getParentId());
             }
-            
-            setFile(currentDir);
-            
         } else {
-            Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
+            return null;
         }
     }
 
-    
 }
index 80f5358..907410f 100644 (file)
-/* ownCloud Android client application\r
- *   Copyright (C) 2011  Bartek Przybylski\r
- *   Copyright (C) 2012-2013 ownCloud Inc.\r
- *\r
- *   This program is free software: you can redistribute it and/or modify\r
- *   it under the terms of the GNU General Public License version 2,\r
- *   as published by the Free Software Foundation.\r
- *\r
- *   This program is distributed in the hope that it will be useful,\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *   GNU General Public License for more details.\r
- *\r
- *   You should have received a copy of the GNU General Public License\r
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- */\r
-package com.owncloud.android.ui.adapter;\r
-\r
-import java.util.Vector;\r
-\r
-import com.owncloud.android.AccountUtils;\r
-import com.owncloud.android.DisplayUtils;\r
-import com.owncloud.android.datamodel.DataStorageManager;\r
-import com.owncloud.android.datamodel.OCFile;\r
-import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
-import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
-import com.owncloud.android.ui.activity.TransferServiceGetter;\r
-\r
-import com.owncloud.android.R;\r
-\r
-import android.accounts.Account;\r
-import android.content.Context;\r
-import android.view.LayoutInflater;\r
-import android.view.View;\r
-import android.view.ViewGroup;\r
-import android.widget.BaseAdapter;\r
-import android.widget.ImageView;\r
-import android.widget.ListAdapter;\r
-import android.widget.ListView;\r
-import android.widget.TextView;\r
-\r
-/**\r
- * This Adapter populates a ListView with all files and folders in an ownCloud\r
- * instance.\r
- * \r
- * @author Bartek Przybylski\r
- * \r
- */\r
-public class FileListListAdapter extends BaseAdapter implements ListAdapter {\r
-    private Context mContext;\r
-    private OCFile mFile = null;\r
-    private Vector<OCFile> mFiles = null;\r
-    private DataStorageManager mStorageManager;\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
-        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
-    public boolean areAllItemsEnabled() {\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public boolean isEnabled(int position) {\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public int getCount() {\r
-        return mFiles != null ? mFiles.size() : 0;\r
-    }\r
-\r
-    @Override\r
-    public Object getItem(int position) {\r
-        if (mFiles == null || mFiles.size() <= position)\r
-            return null;\r
-        return mFiles.get(position);\r
-    }\r
-\r
-    @Override\r
-    public long getItemId(int position) {\r
-        if (mFiles == null || mFiles.size() <= position)\r
-            return 0;\r
-        return mFiles.get(position).getFileId();\r
-    }\r
-\r
-    @Override\r
-    public int getItemViewType(int position) {\r
-        return 0;\r
-    }\r
-\r
-    @Override\r
-    public View getView(int position, View convertView, ViewGroup parent) {\r
-        View view = convertView;\r
-        if (view == null) {\r
-            LayoutInflater inflator = (LayoutInflater) mContext\r
-                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r
-            view = inflator.inflate(R.layout.list_item, null);\r
-        }\r
-        if (mFiles != null && mFiles.size() > position) {\r
-            OCFile file = mFiles.get(position);\r
-            TextView fileName = (TextView) view.findViewById(R.id.Filename);\r
-            String name = file.getFileName();\r
-\r
-            fileName.setText(name);\r
-            ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);\r
-            fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));\r
-            ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);\r
-            FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();\r
-            FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();\r
-            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {\r
-                localStateView.setImageResource(R.drawable.downloading_file_indicator);\r
-                localStateView.setVisibility(View.VISIBLE);\r
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {\r
-                localStateView.setImageResource(R.drawable.uploading_file_indicator);\r
-                localStateView.setVisibility(View.VISIBLE);\r
-            } else if (file.isDown()) {\r
-                localStateView.setImageResource(R.drawable.local_file_indicator);\r
-                localStateView.setVisibility(View.VISIBLE);\r
-            } else {\r
-                localStateView.setVisibility(View.INVISIBLE);\r
-            }\r
-\r
-            \r
-            TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);\r
-            TextView lastModV = (TextView) view.findViewById(R.id.last_mod);\r
-            ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
-            \r
-            if (!file.isDirectory()) {\r
-                fileSizeV.setVisibility(View.VISIBLE);\r
-                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
-                lastModV.setVisibility(View.VISIBLE);\r
-                lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
-                // this if-else is needed even thoe fav icon is visible by default\r
-                // because android reuses views in listview\r
-                if (!file.keepInSync()) {\r
-                    view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
-                } else {\r
-                    view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);\r
-                }\r
-                \r
-                ListView parentList = (ListView)parent;\r
-                if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { \r
-                    checkBoxV.setVisibility(View.GONE);\r
-                } else {\r
-                    if (parentList.isItemChecked(position)) {\r
-                        checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);\r
-                    } else {\r
-                        checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);\r
-                    }\r
-                    checkBoxV.setVisibility(View.VISIBLE);\r
-                }\r
-                \r
-            } else {\r
-               fileSizeV.setVisibility(View.GONE);\r
-               lastModV.setVisibility(View.GONE);\r
-               checkBoxV.setVisibility(View.GONE);\r
-               view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
-            }\r
-        }\r
-\r
-        return view;\r
-    }\r
-\r
-    @Override\r
-    public int getViewTypeCount() {\r
-        return 1;\r
-    }\r
-\r
-    @Override\r
-    public boolean hasStableIds() {\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public boolean isEmpty() {\r
-        return (mFiles == null || mFiles.isEmpty());\r
-    }\r
-\r
-    /**\r
-     * Change the adapted directory for a new one\r
-     * @param directory                 New file to adapt. Can be NULL, meaning "no content to adapt".\r
-     * @param updatedStorageManager     Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)\r
-     */\r
-    public void swapDirectory(OCFile directory, DataStorageManager updatedStorageManager) {\r
-        mFile = directory;\r
-        if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {\r
-            mStorageManager = updatedStorageManager;\r
-            mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
-        }\r
-        if (mStorageManager != null) {\r
-            mFiles = mStorageManager.getDirectoryContent(mFile);\r
-        } else {\r
-            mFiles = null;\r
-        }\r
-        notifyDataSetChanged();\r
-    }\r
-    \r
-}\r
+
+/* ownCloud Android client application
+ *   Copyright (C) 2011  Bartek Przybylski
+ *   Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package com.owncloud.android.ui.adapter;
+
+import java.util.Vector;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import com.owncloud.android.AccountUtils;
+import com.owncloud.android.DisplayUtils;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.DataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.ui.activity.TransferServiceGetter;
+
+/**
+ * This Adapter populates a ListView with all files and folders in an ownCloud
+ * instance.
+ * 
+ * @author Bartek Przybylski
+ * 
+ */
+public class FileListListAdapter extends BaseAdapter implements ListAdapter {
+    private Context mContext;
+    private OCFile mFile = null;
+    private Vector<OCFile> mFiles = null;
+    private DataStorageManager mStorageManager;
+    private Account mAccount;
+    private TransferServiceGetter mTransferServiceGetter;
+    //total size of a directory (recursive)
+    private Long totalSizeOfDirectoriesRecursive = null;
+    private Long lastModifiedOfAllSubdirectories = null;
+    
+    public FileListListAdapter(OCFile file, DataStorageManager storage_man,
+            Context context, TransferServiceGetter transferServiceGetter) {
+        mStorageManager = storage_man;
+        mContext = context;
+        mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
+        mTransferServiceGetter = transferServiceGetter;
+        swapDirectory(file, mStorageManager);
+        /*mFile = file;
+        mFiles = mStorageManager.getDirectoryContent(mFile);*/
+    }
+
+    @Override
+    public boolean areAllItemsEnabled() {
+        return true;
+    }
+
+    @Override
+    public boolean isEnabled(int position) {
+        return true;
+    }
+
+    @Override
+    public int getCount() {
+        return mFiles != null ? mFiles.size() : 0;
+    }
+
+    @Override
+    public Object getItem(int position) {
+        if (mFiles == null || mFiles.size() <= position)
+            return null;
+        return mFiles.get(position);
+    }
+
+    @Override
+    public long getItemId(int position) {
+        if (mFiles == null || mFiles.size() <= position)
+            return 0;
+        return mFiles.get(position).getFileId();
+    }
+
+    @Override
+    public int getItemViewType(int position) {
+        return 0;
+    }
+
+    @Override
+    public View getView(int position, View convertView, ViewGroup parent) {
+        View view = convertView;
+        if (view == null) {
+            LayoutInflater inflator = (LayoutInflater) mContext
+                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+            view = inflator.inflate(R.layout.list_item, null);
+        }
+        if (mFiles != null && mFiles.size() > position) {
+            OCFile file = mFiles.get(position);
+            TextView fileName = (TextView) view.findViewById(R.id.Filename);
+            String name = file.getFileName();
+
+            fileName.setText(name);
+            ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
+            fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
+            ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
+            FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
+            FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
+            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
+                localStateView.setImageResource(R.drawable.downloading_file_indicator);
+                localStateView.setVisibility(View.VISIBLE);
+            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
+                localStateView.setImageResource(R.drawable.uploading_file_indicator);
+                localStateView.setVisibility(View.VISIBLE);
+            } else if (file.isDown()) {
+                localStateView.setImageResource(R.drawable.local_file_indicator);
+                localStateView.setVisibility(View.VISIBLE);
+            } else {
+                localStateView.setVisibility(View.INVISIBLE);
+            }
+
+            
+            TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
+            TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
+            ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
+            
+            if (!file.isDirectory()) {
+                fileSizeV.setVisibility(View.VISIBLE);
+                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
+                lastModV.setVisibility(View.VISIBLE);
+                lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
+                // this if-else is needed even thoe fav icon is visible by default
+                // because android reuses views in listview
+                if (!file.keepInSync()) {
+                    view.findViewById(R.id.imageView3).setVisibility(View.GONE);
+                } else {
+                    view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
+                }
+                
+                ListView parentList = (ListView)parent;
+                if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { 
+                    checkBoxV.setVisibility(View.GONE);
+                } else {
+                    if (parentList.isItemChecked(position)) {
+                        checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
+                    } else {
+                        checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
+                    }
+                    checkBoxV.setVisibility(View.VISIBLE);
+                }
+                
+            } 
+            else {
+               
+               getDirectorySizeNumber(file,true);
+               if (lastModifiedOfAllSubdirectories == null)
+               {
+                   lastModV.setVisibility(View.GONE);
+                   fileSizeV.setVisibility(View.GONE);
+               }
+               else
+               {
+                   lastModV.setVisibility(View.VISIBLE);
+                   lastModV.setText(DisplayUtils.unixTimeToHumanReadable(lastModifiedOfAllSubdirectories));
+                   fileSizeV.setVisibility(View.VISIBLE);
+                   fileSizeV.setText(DisplayUtils.bytesToHumanReadable((totalSizeOfDirectoriesRecursive == null) ? 0 : totalSizeOfDirectoriesRecursive));
+               }
+               checkBoxV.setVisibility(View.GONE);
+               view.findViewById(R.id.imageView3).setVisibility(View.GONE);
+            }
+        }
+
+        return view;
+    }
+
+    
+    /**
+     * - This method counts recursively all subdirectories and their files from the root directory. 
+     * - It also shows a timestamp of the last modificated file inside the root directory
+     * 
+     *   @param OCFile  : startDirectory
+     *   @param boolean :  counting starts from here ?
+     */
+    private void getDirectorySizeNumber(OCFile directory,boolean startOfRecursive) {
+        if (startOfRecursive) {
+            totalSizeOfDirectoriesRecursive = null;
+        }
+        Vector<OCFile> files  = mStorageManager.getDirectoryContent(directory);
+        for (OCFile file : files) {
+            if(!file.isDirectory()) {
+                if (totalSizeOfDirectoriesRecursive == null) {
+                    totalSizeOfDirectoriesRecursive = file.getFileLength();
+                    lastModifiedOfAllSubdirectories = file.getModificationTimestamp();
+                    continue;
+                }
+                
+                totalSizeOfDirectoriesRecursive += file.getFileLength();
+                if (lastModifiedOfAllSubdirectories < file.getModificationTimestamp()) {
+                    lastModifiedOfAllSubdirectories = file.getModificationTimestamp();
+                }
+            }
+            else {
+                this.getDirectorySizeNumber(file, false);
+            }
+        }
+    }
+    
+    
+    @Override
+    public int getViewTypeCount() {
+        return 1;
+    }
+
+    @Override
+    public boolean hasStableIds() {
+        return true;
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return (mFiles == null || mFiles.isEmpty());
+    }
+
+    /**
+     * Change the adapted directory for a new one
+     * @param directory                 New file to adapt. Can be NULL, meaning "no content to adapt".
+     * @param updatedStorageManager     Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
+     */
+    public void swapDirectory(OCFile directory, DataStorageManager updatedStorageManager) {
+        mFile = directory;
+        if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {
+            mStorageManager = updatedStorageManager;
+            mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
+        }
+        if (mStorageManager != null) {
+            mFiles = mStorageManager.getDirectoryContent(mFile);
+        } else {
+            mFiles = null;
+        }
+        notifyDataSetChanged();
+    }
+    
+}
\ No newline at end of file
diff --git a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java
new file mode 100644 (file)
index 0000000..3e519a8
--- /dev/null
@@ -0,0 +1,118 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012 Bartek Przybylski
+ *   Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui.fragment;
+
+import com.actionbarsherlock.app.SherlockFragment;
+import com.owncloud.android.Log_OC;
+import com.owncloud.android.R;
+import com.owncloud.android.ui.ExtendedListView;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ListAdapter;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ListView;
+
+/**
+ *  TODO extending SherlockListFragment instead of SherlockFragment 
+ */
+public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener {
+    
+    private static final String TAG = ExtendedListFragment.class.getSimpleName();
+
+    private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION"; 
+
+    protected ExtendedListView mList;
+    
+    public void setListAdapter(ListAdapter listAdapter) {
+        mList.setAdapter(listAdapter);
+        mList.invalidate();
+    }
+
+    public ListView getListView() {
+        return mList;
+    }
+    
+    
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        Log_OC.e(TAG, "onCreateView");
+        //mList = new ExtendedListView(getActivity());
+        View v = inflater.inflate(R.layout.list_fragment, null);
+        mList = (ExtendedListView)(v.findViewById(R.id.list_root));
+        mList.setOnItemClickListener(this);
+        //mList.setEmptyView(v.findViewById(R.id.empty_list_view));     // looks like it's not a cool idea 
+        mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
+        mList.setDividerHeight(1);
+
+        if (savedInstanceState != null) {
+            int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
+            setReferencePosition(referencePosition);
+        }
+        
+        return v;
+    }
+
+    
+    @Override
+    public void onSaveInstanceState(Bundle savedInstanceState) {
+        super.onSaveInstanceState(savedInstanceState);
+        Log_OC.e(TAG, "onSaveInstanceState()");
+        savedInstanceState.putInt(KEY_SAVED_LIST_POSITION, getReferencePosition());
+    }
+
+    
+    /**
+     * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
+     * the device is turned to other position. 
+     * 
+     * THe current policy is take as a reference the visible item in the center of the screen.  
+     * 
+     * @return      The position in the list of the visible item in the center of the screen.
+     */
+    protected int getReferencePosition() {
+        if (mList != null) {
+            return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
+        } else {
+            return 0;
+        }
+    }
+
+    
+    /**
+     * Sets the visible part of the list from the reference position.
+     * 
+     * @param   position    Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
+     */
+    protected void setReferencePosition(int position) {
+        if (mList != null) {
+            mList.setAndCenterSelection(position);
+        }
+    }
+
+    @Override
+    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+        // to be @overriden  
+    }
+
+    
+}
index 6d8039a..4c3bf67 100644 (file)
@@ -24,12 +24,10 @@ import java.util.List;
 
 import android.accounts.Account;
 import android.app.Activity;
-import android.content.ActivityNotFoundException;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.v4.app.FragmentTransaction;
@@ -37,14 +35,12 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
-import android.webkit.MimeTypeMap;
 import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.Toast;
 
-import com.actionbarsherlock.app.SherlockFragment;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
@@ -65,7 +61,6 @@ import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.dialog.EditNameDialog;
 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
@@ -73,7 +68,6 @@ import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
 import com.owncloud.android.R;
 
 import eu.alefzero.webdav.OnDatatransferProgressListener;
-import eu.alefzero.webdav.WebdavUtils;
 
 /**
  * This Fragment is used to display the details about a file.
@@ -81,16 +75,14 @@ import eu.alefzero.webdav.WebdavUtils;
  * @author Bartek Przybylski
  * @author David A. Velasco
  */
-public class FileDetailFragment extends SherlockFragment implements
+public class FileDetailFragment extends FileFragment implements
         OnClickListener, 
-        ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener,
-        FileFragment {
+        ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {
 
     private FileFragment.ContainerActivity mContainerActivity;
     
     private int mLayout;
     private View mView;
-    private OCFile mFile;
     private Account mAccount;
     private FileDataStorageManager mStorageManager;
     
@@ -101,7 +93,6 @@ public class FileDetailFragment extends SherlockFragment implements
     private RemoteOperation mLastRemoteOperation;
     
     private static final String TAG = FileDetailFragment.class.getSimpleName();
-    public static final String FTAG = "FileDetails"; 
     public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
     
 
@@ -111,7 +102,7 @@ public class FileDetailFragment extends SherlockFragment implements
      * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically. 
      */
     public FileDetailFragment() {
-        mFile = null;
+        super();
         mAccount = null;
         mStorageManager = null;
         mLayout = R.layout.file_details_empty;
@@ -127,7 +118,7 @@ public class FileDetailFragment extends SherlockFragment implements
      * @param ocAccount         An ownCloud account; needed to start downloads
      */
     public FileDetailFragment(OCFile fileToDetail, Account ocAccount) {
-        mFile = fileToDetail;
+        super(fileToDetail);
         mAccount = ocAccount;
         mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment 
         mLayout = R.layout.file_details_empty;
@@ -146,19 +137,20 @@ public class FileDetailFragment extends SherlockFragment implements
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
-        super.onCreateView(inflater, container, savedInstanceState);
+        //super.onCreateView(inflater, container, savedInstanceState);
         
         if (savedInstanceState != null) {
-            mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
+            setFile((OCFile)savedInstanceState.getParcelable(FileActivity.EXTRA_FILE));
             mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
         }
         
-        if(mFile != null && mAccount != null) {
+        if(getFile() != null && mAccount != null) {
             mLayout = R.layout.file_details_fragment;
         }
         
         View view = null;
-        view = inflater.inflate(mLayout, container, false);
+        //view = inflater.inflate(mLayout, container, false);
+        view = inflater.inflate(mLayout, null);
         mView = view;
         
         if (mLayout == R.layout.file_details_fragment) {
@@ -202,7 +194,7 @@ public class FileDetailFragment extends SherlockFragment implements
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
-        outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
+        outState.putParcelable(FileActivity.EXTRA_FILE, getFile());
         outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
     }
 
@@ -269,11 +261,12 @@ public class FileDetailFragment extends SherlockFragment implements
         
         List<Integer> toHide = new ArrayList<Integer>();
         List<Integer> toShow = new ArrayList<Integer>();
+        OCFile file = getFile();
         
         FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
-        boolean downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile);
+        boolean downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file);
         FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-        boolean uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile);
+        boolean uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile());
         
         if (downloading || uploading) {
             toHide.add(R.id.action_download_file);
@@ -288,7 +281,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 toShow.add(R.id.action_cancel_download);
             }
 
-        } else if (mFile != null && mFile.isDown()) {
+        } else if (file != null && file.isDown()) {
             toHide.add(R.id.action_download_file);
             toHide.add(R.id.action_cancel_download);
             toHide.add(R.id.action_cancel_upload);
@@ -298,7 +291,7 @@ public class FileDetailFragment extends SherlockFragment implements
             toShow.add(R.id.action_open_file_with);
             toShow.add(R.id.action_sync_file);
             
-        } else if (mFile != null) {
+        } else if (file != null) {
             toHide.add(R.id.action_open_file_with);
             toHide.add(R.id.action_cancel_download);
             toHide.add(R.id.action_cancel_upload);
@@ -344,7 +337,7 @@ public class FileDetailFragment extends SherlockFragment implements
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.action_open_file_with: {
-                openFile();
+                mContainerActivity.openFile(getFile());
                 return true;
             }
             case R.id.action_remove_file: {
@@ -386,8 +379,9 @@ public class FileDetailFragment extends SherlockFragment implements
     
     private void toggleKeepInSync() {
         CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
-        mFile.setKeepInSync(cb.isChecked());
-        mStorageManager.saveFile(mFile);
+        OCFile file = getFile();
+        file.setKeepInSync(cb.isChecked());
+        mStorageManager.saveFile(file);
         
         /// register the OCFile instance in the observer service to monitor local updates;
         /// if necessary, the file is download 
@@ -397,22 +391,23 @@ public class FileDetailFragment extends SherlockFragment implements
                    (cb.isChecked()?
                            FileObserverService.CMD_ADD_OBSERVED_FILE:
                            FileObserverService.CMD_DEL_OBSERVED_FILE));
-        intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
+        intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, file);
         intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
         getActivity().startService(intent);
         
-        if (mFile.keepInSync()) {
+        if (file.keepInSync()) {
             synchronizeFile();   // force an immediate synchronization
         }
     }
 
 
     private void removeFile() {
+        OCFile file = getFile();
         ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
                 R.string.confirmation_remove_alert,
-                new String[]{mFile.getFileName()},
-                mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
-                mFile.isDown() ? R.string.confirmation_remove_local : -1,
+                new String[]{file.getFileName()},
+                file.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
+                file.isDown() ? R.string.confirmation_remove_local : -1,
                 R.string.common_cancel);
         confDialog.setOnConfirmationListener(this);
         confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
@@ -420,116 +415,61 @@ public class FileDetailFragment extends SherlockFragment implements
 
 
     private void renameFile() {
-        String fileName = mFile.getFileName();
-        int extensionStart = mFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
+        OCFile file = getFile();
+        String fileName = file.getFileName();
+        int extensionStart = file.isDirectory() ? -1 : fileName.lastIndexOf(".");
         int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
         EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
         dialog.show(getFragmentManager(), "nameeditdialog");
     }
 
     private void synchronizeFile() {
+        OCFile file = getFile();
         FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
         FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
-            downloaderBinder.cancel(mAccount, mFile);
-            if (mFile.isDown()) {
+        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
+            downloaderBinder.cancel(mAccount, file);
+            if (file.isDown()) {
                 setButtonsForDown();
             } else {
                 setButtonsForRemote();
             }
 
-        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
-            uploaderBinder.cancel(mAccount, mFile);
-            if (!mFile.fileExists()) {
+        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
+            uploaderBinder.cancel(mAccount, file);
+            if (!file.fileExists()) {
                 // TODO make something better
-                if (getActivity() instanceof FileDisplayActivity) {
-                    // double pane
-                    FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
-                    transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment
-                    transaction.commit();
-                    mContainerActivity.onFileStateChanged();
-                } else {
-                    getActivity().finish();
-                }
+                ((FileDisplayActivity)getActivity()).cleanSecondFragment();
                 
-            } else if (mFile.isDown()) {
+            } else if (file.isDown()) {
                 setButtonsForDown();
             } else {
                 setButtonsForRemote();
             }
             
         } else {
-            mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());
+            mLastRemoteOperation = new SynchronizeFileOperation(file, null, mStorageManager, mAccount, true, false, getActivity());
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
             // update ui 
             boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-            getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
-            
-        }
-    }
-
-    /**
-     * Opens mFile.
-     */
-    private void openFile() {
-        
-        String storagePath = mFile.getStoragePath();
-        String encodedStoragePath = WebdavUtils.encodePath(storagePath);
-        try {
-            Intent i = new Intent(Intent.ACTION_VIEW);
-            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
-            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-            startActivity(i);
-            
-        } catch (Throwable t) {
-            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
-            boolean toastIt = true; 
-            String mimeType = "";
-            try {
-                Intent i = new Intent(Intent.ACTION_VIEW);
-                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
-                if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
-                    if (mimeType != null) {
-                        i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
-                    } else {
-                        // desperate try
-                        i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*");
-                    }
-                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-                    startActivity(i);
-                    toastIt = false;
-                }
-                
-            } catch (IndexOutOfBoundsException e) {
-                Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
-                
-            } catch (ActivityNotFoundException e) {
-                Log_OC.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
-                
-            } catch (Throwable th) {
-                Log_OC.e(TAG, "Unexpected problem when opening: " + storagePath, th);
-                
-            } finally {
-                if (toastIt) {
-                    Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
-                }
-            }
+            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
             
         }
     }
 
     @Override
     public void onConfirmation(String callerTag) {
+        OCFile file = getFile();
         if (callerTag.equals(FTAG_CONFIRMATION)) {
-            if (mStorageManager.getFileById(mFile.getFileId()) != null) {
-                mLastRemoteOperation = new RemoveFileOperation( mFile, 
+            if (mStorageManager.getFileById(file.getFileId()) != null) {
+                mLastRemoteOperation = new RemoveFileOperation( file, 
                                                                 true, 
                                                                 mStorageManager);
                 mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
                 
                 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-                getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+                getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
             }
         }
     }
@@ -537,11 +477,12 @@ public class FileDetailFragment extends SherlockFragment implements
     @Override
     public void onNeutral(String callerTag) {
         File f = null;
-        if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) {
+        OCFile file = getFile();
+        if (file.isDown() && (f = new File(file.getStoragePath())).exists()) {
             f.delete();
-            mFile.setStoragePath(null);
-            mStorageManager.saveFile(mFile);
-            updateFileDetails(mFile, mAccount);
+            file.setStoragePath(null);
+            mStorageManager.saveFile(file);
+            updateFileDetails(file, mAccount);
         }
     }
     
@@ -557,24 +498,17 @@ public class FileDetailFragment extends SherlockFragment implements
      * @return  True when the fragment was created with the empty layout.
      */
     public boolean isEmpty() {
-        return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null);
+        return (mLayout == R.layout.file_details_empty || getFile() == null || mAccount == null);
     }
 
     
     /**
-     * {@inheritDoc}
-     */
-    public OCFile getFile(){
-        return mFile;
-    }
-    
-    /**
      * Use this method to signal this Activity that it shall update its view.
      * 
      * @param file : An {@link OCFile}
      */
     public void updateFileDetails(OCFile file, Account ocAccount) {
-        mFile = file;
+        setFile(file);
         if (ocAccount != null && ( 
                 mStorageManager == null || 
                 (mAccount != null && !mAccount.equals(ocAccount))
@@ -603,30 +537,31 @@ public class FileDetailFragment extends SherlockFragment implements
         if (readyToShow()) {
             
             if (refresh && mStorageManager != null) {
-                mFile = mStorageManager.getFileByPath(mFile.getRemotePath());
+                setFile(mStorageManager.getFileByPath(getFile().getRemotePath()));
             }
+            OCFile file = getFile();
             
             // set file details
-            setFilename(mFile.getFileName());
-            setFiletype(mFile.getMimetype());
-            setFilesize(mFile.getFileLength());
+            setFilename(file.getFileName());
+            setFiletype(file.getMimetype());
+            setFilesize(file.getFileLength());
             if(ocVersionSupportsTimeCreated()){
-                setTimeCreated(mFile.getCreationTimestamp());
+                setTimeCreated(file.getCreationTimestamp());
             }
            
-            setTimeModified(mFile.getModificationTimestamp());
+            setTimeModified(file.getModificationTimestamp());
             
             CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);
-            cb.setChecked(mFile.keepInSync());
+            cb.setChecked(file.keepInSync());
 
             // configure UI for depending upon local state of the file
             //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-            if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {
+            if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
                 setButtonsForTransferring();
                 
-            } else if (mFile.isDown()) {
+            } else if (file.isDown()) {
                 
                 setButtonsForDown();
                 
@@ -644,7 +579,7 @@ public class FileDetailFragment extends SherlockFragment implements
      * @return  'True' when the fragment is ready to show details of a file
      */
     private boolean readyToShow() {
-        return (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment);        
+        return (getFile() != null && mAccount != null && mLayout == R.layout.file_details_fragment);        
     }
 
 
@@ -723,9 +658,9 @@ public class FileDetailFragment extends SherlockFragment implements
             progressText.setVisibility(View.VISIBLE);
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
+            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
                 progressText.setText(R.string.downloader_download_in_progress_ticker);
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
+            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
                 progressText.setText(R.string.uploader_upload_in_progress_ticker);
             }
         }
@@ -798,11 +733,11 @@ public class FileDetailFragment extends SherlockFragment implements
             if (!isEmpty() && accountName.equals(mAccount.name)) {
                 boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
                 String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
-                boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
-                if (mFile.getRemotePath().equals(uploadRemotePath) ||
+                boolean renamedInUpload = getFile().getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
+                if (getFile().getRemotePath().equals(uploadRemotePath) ||
                     renamedInUpload) {
                     if (uploadWasFine) {
-                        mFile = mStorageManager.getFileByPath(uploadRemotePath);
+                        setFile(mStorageManager.getFileByPath(uploadRemotePath));
                     }
                     if (renamedInUpload) {
                         String newName = (new File(uploadRemotePath)).getName();
@@ -821,13 +756,13 @@ public class FileDetailFragment extends SherlockFragment implements
         if (dialog.getResult()) {
             String newFilename = dialog.getNewFilename();
             Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
-            mLastRemoteOperation = new RenameFileOperation( mFile
+            mLastRemoteOperation = new RenameFileOperation( getFile()
                                                             mAccount, 
                                                             newFilename, 
                                                             new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-            getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         }
     }
     
@@ -852,22 +787,13 @@ public class FileDetailFragment extends SherlockFragment implements
     
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-        getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
-            if (inDisplayActivity) {
-                // double pane
-                FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
-                transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
-                transaction.commit();
-                mContainerActivity.onFileStateChanged();
-            } else {
-                getActivity().finish();
-            }
-                
+            ((FileDisplayActivity)getActivity()).cleanSecondFragment();
+
         } else {
             Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); 
             msg.show();
@@ -878,8 +804,7 @@ public class FileDetailFragment extends SherlockFragment implements
     }
     
     private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
-        boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-        getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         
         if (result.isSuccess()) {
             updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
@@ -901,13 +826,12 @@ public class FileDetailFragment extends SherlockFragment implements
     }
     
     private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
-        boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-        getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
-
+        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+        OCFile file = getFile();
         if (!result.isSuccess()) {
             if (result.getCode() == ResultCode.SYNC_CONFLICT) {
                 Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
-                i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile);
+                i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
                 i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
                 startActivity(i);
                 
@@ -916,7 +840,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 msg.show();
             }
             
-            if (mFile.isDown()) {
+            if (file.isDown()) {
                 setButtonsForDown();
                 
             } else {
@@ -931,7 +855,7 @@ public class FileDetailFragment extends SherlockFragment implements
             } else {
                 Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); 
                 msg.show();
-                if (mFile.isDown()) {
+                if (file.isDown()) {
                     setButtonsForDown();
                     
                 } else {
@@ -945,10 +869,10 @@ public class FileDetailFragment extends SherlockFragment implements
     public void listenForTransferProgress() {
         if (mProgressListener != null) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {
-                mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+                mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, getFile());
             }
             if (mContainerActivity.getFileUploaderBinder() != null) {
-                mContainerActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+                mContainerActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, getFile());
             }
         }
     }
@@ -957,10 +881,10 @@ public class FileDetailFragment extends SherlockFragment implements
     public void leaveTransferProgress() {
         if (mProgressListener != null) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {
-                mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
+                mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, getFile());
             }
             if (mContainerActivity.getFileUploaderBinder() != null) {
-                mContainerActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
+                mContainerActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, getFile());
             }
         }
     }
@@ -1000,110 +924,4 @@ public class FileDetailFragment extends SherlockFragment implements
 
     };
 
-    /*
-    // this is a temporary class for sharing purposes, it need to be replaced in transfer service
-    @SuppressWarnings("unused")
-    private class ShareRunnable implements Runnable {
-        private String mPath;
-
-        public ShareRunnable(String path) {
-            mPath = path;
-        }
-        
-        public void run() {
-            AccountManager am = AccountManager.get(getActivity());
-            Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
-            OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
-            String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
-
-            Log_OC.d("share", "sharing for version " + ocv.toString());
-
-            if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
-                String APPS_PATH = "/apps/files_sharing/";
-                String SHARE_PATH = "ajax/share.php";
-
-                String SHARED_PATH = "/apps/files_sharing/get.php?token=";
-                
-                final String WEBDAV_SCRIPT = "webdav.php";
-                final String WEBDAV_FILES_LOCATION = "/files/";
-                
-                WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext());
-                HttpConnectionManagerParams params = new HttpConnectionManagerParams();
-                params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
-
-                //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
-                //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-
-                PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
-
-                post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
-                post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
-                List<NameValuePair> formparams = new ArrayList<NameValuePair>();
-                Log_OC.d("share", mPath+"");
-                formparams.add(new BasicNameValuePair("sources",mPath));
-                formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
-                formparams.add(new BasicNameValuePair("permissions", "0"));
-                post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
-
-                int status;
-                try {
-                    PropFindMethod find = new PropFindMethod(url+"/");
-                    find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
-                    Log_OC.d("sharer", ""+ url+"/");
-                    
-                    for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
-                        Log_OC.d("sharer-h", a.getName() + ":"+a.getValue());
-                    }
-                    
-                    int status2 = wc.executeMethod(find);
-
-                    Log_OC.d("sharer", "propstatus "+status2);
-                    
-                    GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
-                    get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
-                    
-                    status2 = wc.executeMethod(get);
-
-                    Log_OC.d("sharer", "getstatus "+status2);
-                    Log_OC.d("sharer", "" + get.getResponseBodyAsString());
-                    
-                    for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
-                        Log_OC.d("sharer", a.getName() + ":"+a.getValue());
-                    }
-
-                    status = wc.executeMethod(post);
-                    for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
-                        Log_OC.d("sharer-h", a.getName() + ":"+a.getValue());
-                    }
-                    for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
-                        Log_OC.d("sharer", a.getName() + ":"+a.getValue());
-                    }
-                    String resp = post.getResponseBodyAsString();
-                    Log_OC.d("share", ""+post.getURI().toString());
-                    Log_OC.d("share", "returned status " + status);
-                    Log_OC.d("share", " " +resp);
-                    
-                    if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
-                        return;
-                     }
-
-                    JSONObject jsonObject = new JSONObject (resp);
-                    String jsonStatus = jsonObject.getString("status");
-                    if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
-                    
-                    String token = jsonObject.getString("data");
-                    String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token; 
-                    Log_OC.d("Actions:shareFile ok", "url: " + uri);   
-                    
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                
-            } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
-                
-            }
-        }
-    }
-    */
-    
 }
index 3054951..4c6f3e7 100644 (file)
 
 package com.owncloud.android.ui.fragment;
 
-import android.content.Intent;
 import android.support.v4.app.Fragment;
 
+import com.actionbarsherlock.app.SherlockFragment;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.FileHandler;
 import com.owncloud.android.ui.activity.TransferServiceGetter;
 
 /**
@@ -29,22 +30,49 @@ import com.owncloud.android.ui.activity.TransferServiceGetter;
  * @author David A. Velasco
  *
  */
-public interface FileFragment {
+public class FileFragment extends SherlockFragment {
+    
+    private OCFile mFile;
+
+
+    /**
+     * Creates an empty fragment.
+     * 
+     * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically. 
+     */
+    public FileFragment() {
+        mFile = null;
+    }
     
     /**
+     * Creates an instance for a given {@OCFile}.
+     * 
+     * @param file
+     */
+    public FileFragment(OCFile file) {
+        mFile = file;
+    }
+
+    /**
      * Getter for the hold {@link OCFile}
      * 
      * @return The {@link OCFile} hold
      */
-    public OCFile getFile();
+    public OCFile getFile() {
+        return mFile;
+    }
     
     
+    protected void setFile(OCFile file) {
+        mFile = file;
+    }
+
     /**
      * Interface to implement by any Activity that includes some instance of FileFragment
      * 
      * @author David A. Velasco
      */
-    public interface ContainerActivity extends TransferServiceGetter {
+    public interface ContainerActivity extends TransferServiceGetter, FileHandler {
 
         /**
          * Callback method invoked when the detail fragment wants to notice its container 
@@ -65,7 +93,7 @@ public interface FileFragment {
          * 
          * @param file      File to show details
          */
-        public void showFragmentWithDetails(OCFile file);
+        public void showDetails(OCFile file);
         
         
     }
index 4e6affa..24421fa 100644 (file)
@@ -19,7 +19,6 @@ package com.owncloud.android.ui.fragment;
 
 import java.io.File;
 
-import com.owncloud.android.ui.FragmentListView;
 import com.owncloud.android.ui.adapter.LocalFileListAdapter;
 
 import android.app.Activity;
@@ -42,9 +41,8 @@ import com.owncloud.android.R;
  * @author David A. Velasco
  * 
  */
-public class LocalFileListFragment extends FragmentListView {
+public class LocalFileListFragment extends ExtendedListFragment {
     private static final String TAG = "LocalFileListFragment";
-    private static final String SAVED_LIST_POSITION = "LIST_POSITION"; 
     
     /** Reference to the Activity which this fragment is attached to. For callbacks */
     private LocalFileListFragment.ContainerActivity mContainerActivity;
@@ -94,27 +92,10 @@ public class LocalFileListFragment extends FragmentListView {
         mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity());
         setListAdapter(mAdapter);
         
-        if (savedInstanceState != null) {
-            Log_OC.i(TAG, "savedInstanceState is not null");
-            int position = savedInstanceState.getInt(SAVED_LIST_POSITION);
-            setReferencePosition(position);
-        }
-        
         Log_OC.i(TAG, "onActivityCreated() stop");
     }
     
     
-    @Override
-    public void onSaveInstanceState(Bundle savedInstanceState) {
-        Log_OC.i(TAG, "onSaveInstanceState() start");
-        
-        savedInstanceState.putInt(SAVED_LIST_POSITION, getReferencePosition());
-        
-        
-        Log_OC.i(TAG, "onSaveInstanceState() stop");
-    }
-    
-    
     /**
      * Checks the file clicked over. Browses inside if it is a directory. Notifies the container activity in any case.
      */
index f0d074f..35b3774 100644 (file)
@@ -26,6 +26,7 @@ import com.owncloud.android.Log_OC;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.DataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.FileHandler;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.operations.OnRemoteOperationListener;
@@ -33,30 +34,24 @@ import com.owncloud.android.operations.RemoteOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.ui.FragmentListView;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.TransferServiceGetter;
 import com.owncloud.android.ui.adapter.FileListListAdapter;
 import com.owncloud.android.ui.dialog.EditNameDialog;
 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
 import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
-
-import eu.alefzero.webdav.WebdavUtils;
+import com.owncloud.android.ui.preview.PreviewImageFragment;
+import com.owncloud.android.ui.preview.PreviewMediaFragment;
 
 import android.accounts.Account;
 import android.app.Activity;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.view.ContextMenu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
-import android.webkit.MimeTypeMap;
 import android.widget.AdapterView;
-import android.widget.Toast;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 
 /**
@@ -65,9 +60,9 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
  * @author Bartek Przybylski
  * 
  */
-public class OCFileListFragment extends FragmentListView implements EditNameDialogListener, ConfirmationDialogFragmentListener {
-    private static final String TAG = "FileListFragment";
-    private static final String SAVED_LIST_POSITION = "LIST_POSITION"; 
+public class OCFileListFragment extends ExtendedListFragment implements EditNameDialogListener, ConfirmationDialogFragmentListener {
+    
+    private static final String TAG = OCFileListFragment.class.getSimpleName();
     
     private OCFileListFragment.ContainerActivity mContainerActivity;
     
@@ -83,6 +78,7 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
     @Override
     public void onAttach(Activity activity) {
         super.onAttach(activity);
+        Log_OC.e(TAG, "onAttach");
         try {
             mContainerActivity = (ContainerActivity) activity;
         } catch (ClassCastException e) {
@@ -96,52 +92,62 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
      */
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
-        Log_OC.i(TAG, "onActivityCreated() start");
-        
         super.onActivityCreated(savedInstanceState);
+        Log_OC.e(TAG, "onActivityCreated() start");
         mAdapter = new FileListListAdapter(mContainerActivity.getInitialDirectory(), mContainerActivity.getStorageManager(), getActivity(), mContainerActivity);
         setListAdapter(mAdapter);
         
-        if (savedInstanceState != null) {
-            Log_OC.i(TAG, "savedInstanceState is not null");
-            int position = savedInstanceState.getInt(SAVED_LIST_POSITION);
-            setReferencePosition(position);
-        }
-        
         registerForContextMenu(getListView());
         getListView().setOnCreateContextMenuListener(this);        
         
         mHandler = new Handler();
-        
-        Log_OC.i(TAG, "onActivityCreated() stop");
     }
     
-    
 
-    @Override
-    public void onSaveInstanceState(Bundle savedInstanceState) {
-        Log_OC.i(TAG, "onSaveInstanceState() start");
-        
-        savedInstanceState.putInt(SAVED_LIST_POSITION, getReferencePosition());
+    /**
+     * Call this, when the user presses the up button
+     */
+    public void onBrowseUp() {
+        OCFile parentDir = null;
         
-        Log_OC.i(TAG, "onSaveInstanceState() stop");
+        if(mFile != null){
+            DataStorageManager storageManager = mContainerActivity.getStorageManager();
+            parentDir = storageManager.getFileById(mFile.getParentId());
+            mFile = parentDir;
+        }
+        listDirectory(parentDir);
     }
     
-    
     @Override
     public void onItemClick(AdapterView<?> l, View v, int position, long id) {
         OCFile file = (OCFile) mAdapter.getItem(position);
         if (file != null) {
-            /// Click on a directory
-            if (file.getMimetype().equals("DIR")) {
-                // just local updates
+            if (file.isDirectory()) { 
+                // update state and view of this fragment
                 mFile = file;
                 listDirectory(file);
-                // any other updates are let to the container Activity
-                mContainerActivity.onDirectoryClick(file);
-            
-            } else {    /// Click on a file
-                mContainerActivity.onFileClick(file, false);
+                // then, notify parent activity to let it update its state and view, and other fragments
+                mContainerActivity.onBrowsedDownTo(file);
+                
+            } else { /// Click on a file
+                if (PreviewImageFragment.canBePreviewed(file)) {
+                    // preview image - it handles the download, if needed
+                    mContainerActivity.startImagePreview(file);
+                    
+                } else if (file.isDown()) {
+                    if (PreviewMediaFragment.canBePreviewed(file)) {
+                        // media preview
+                        mContainerActivity.startMediaPreview(file, 0, true);
+                    } else {
+                        // open with
+                        mContainerActivity.openFile(file);
+                    }
+                    
+                } else {
+                    // automatic download, preview on finish
+                    mContainerActivity.startDownloadForPreview(file);
+                }
+                    
             }
             
         } else {
@@ -181,26 +187,25 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
             
         } else {
             // contextual menu for regular files
+            
+            // new design: 'download' and 'open with' won't be available anymore in context menu
+            toHide.add(R.id.action_download_file);
+            toHide.add(R.id.action_open_file_with);
+            
             if (targetFile.isDown()) {
                 toHide.add(R.id.action_cancel_download);
                 toHide.add(R.id.action_cancel_upload);
-                toHide.add(R.id.action_download_file);
                 
             } else {
-                toHide.add(R.id.action_open_file_with);
                 toHide.add(R.id.action_sync_file);
             }
             if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
-                toHide.add(R.id.action_download_file);
                 toHide.add(R.id.action_cancel_upload);
-                toDisable.add(R.id.action_open_file_with);
                 toDisable.add(R.id.action_rename_file);
                 toDisable.add(R.id.action_remove_file);
                     
             } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
-                toHide.add(R.id.action_download_file);
                 toHide.add(R.id.action_cancel_download);
-                toDisable.add(R.id.action_open_file_with);
                 toDisable.add(R.id.action_rename_file);
                 toDisable.add(R.id.action_remove_file);
                     
@@ -265,53 +270,6 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
                 confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
                 return true;
             }
-            case R.id.action_open_file_with: {
-                String storagePath = mTargetFile.getStoragePath();
-                String encodedStoragePath = WebdavUtils.encodePath(storagePath);
-                try {
-                    Intent i = new Intent(Intent.ACTION_VIEW);
-                    i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mTargetFile.getMimetype());
-                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-                    startActivity(i);
-                    
-                } catch (Throwable t) {
-                    Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mTargetFile.getMimetype());
-                    boolean toastIt = true; 
-                    String mimeType = "";
-                    try {
-                        Intent i = new Intent(Intent.ACTION_VIEW);
-                        mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
-                        if (mimeType == null || !mimeType.equals(mTargetFile.getMimetype())) {
-                            if (mimeType != null) {
-                                i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
-                            } else {
-                                // desperate try
-                                i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*");
-                            }
-                            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-                            startActivity(i);
-                            toastIt = false;
-                        }
-                        
-                    } catch (IndexOutOfBoundsException e) {
-                        Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
-                        
-                    } catch (ActivityNotFoundException e) {
-                        Log_OC.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
-                        
-                    } catch (Throwable th) {
-                        Log_OC.e(TAG, "Unexpected problem when opening: " + storagePath, th);
-                        
-                    } finally {
-                        if (toastIt) {
-                            Toast.makeText(getActivity(), "There is no application to handle file " + mTargetFile.getFileName(), Toast.LENGTH_SHORT).show();
-                        }
-                    }
-                    
-                }
-                return true;
-            }
-            case R.id.action_download_file: 
             case R.id.action_sync_file: {
                 Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
                 RemoteOperation operation = new SynchronizeFileOperation(mTargetFile, null, mContainerActivity.getStorageManager(), account, true, false, getSherlockActivity());
@@ -340,7 +298,7 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
                 return true;
             }
             case R.id.action_see_details: {
-                ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mTargetFile);
+                ((FileFragment.ContainerActivity)getActivity()).showDetails(mTargetFile);
                 return true;
             }
             default:
@@ -350,20 +308,6 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
     
 
     /**
-     * Call this, when the user presses the up button
-     */
-    public void onNavigateUp() {
-        OCFile parentDir = null;
-        
-        if(mFile != null){
-            DataStorageManager storageManager = mContainerActivity.getStorageManager();
-            parentDir = storageManager.getFileById(mFile.getParentId());
-            mFile = parentDir;
-        }
-        listDirectory(parentDir);
-    }
-
-    /**
      * Use this to query the {@link OCFile} that is currently
      * being displayed by this fragment
      * @return The currently viewed OCFile
@@ -422,21 +366,20 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
      * 
      * @author David A. Velasco
      */
-    public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener {
+    public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener, FileHandler {
 
         /**
-         * Callback method invoked when a directory is clicked by the user on the files list
+         * Callback method invoked when a the user browsed into a different folder through the list of files
          *  
          * @param file
          */
-        public void onDirectoryClick(OCFile file);
+        public void onBrowsedDownTo(OCFile folder);
         
-        /**
-         * Callback method invoked when a file (non directory) is clicked by the user on the files list
-         *  
-         * @param file
-         */
-        public void onFileClick(OCFile file, boolean realClick);
+        public void startDownloadForPreview(OCFile file);
+
+        public void startMediaPreview(OCFile file, int i, boolean b);
+
+        public void startImagePreview(OCFile file);
 
         /**
          * Getter for the current DataStorageManager in the container activity
index 773350a..d3d5fe9 100644 (file)
@@ -27,12 +27,10 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
-import android.widget.Button;
+import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
-import com.actionbarsherlock.app.SherlockFragment;
-import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.ui.fragment.FileFragment;
@@ -47,7 +45,7 @@ import eu.alefzero.webdav.OnDatatransferProgressListener;
  * 
  * @author David A. Velasco
  */
-public class FileDownloadFragment extends SherlockFragment implements OnClickListener, FileFragment {
+public class FileDownloadFragment extends FileFragment implements OnClickListener {
 
     public static final String EXTRA_FILE = "FILE";
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
@@ -56,9 +54,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
     private FileFragment.ContainerActivity mContainerActivity;
     
     private View mView;
-    private OCFile mFile;
     private Account mAccount;
-    private FileDataStorageManager mStorageManager;
     
     public ProgressListener mProgressListener;
     private boolean mListening;
@@ -75,9 +71,8 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
      * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically. 
      */
     public FileDownloadFragment() {
-        mFile = null;
+        super();
         mAccount = null;
-        mStorageManager = null;
         mProgressListener = null;
         mListening = false;
         mIgnoreFirstSavedState = false;
@@ -95,9 +90,8 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
      * @param ignoreFirstSavedState     Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution 
      */
     public FileDownloadFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) {
-        mFile = fileToDetail;
+        super(fileToDetail);
         mAccount = ocAccount;
-        mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment 
         mProgressListener = null;
         mListening = false;
         mIgnoreFirstSavedState = ignoreFirstSavedState;
@@ -118,7 +112,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
         
         if (savedInstanceState != null) {
             if (!mIgnoreFirstSavedState) {
-                mFile = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE);
+                setFile((OCFile)savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE));
                 mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT);
                 mError = savedInstanceState.getBoolean(FileDownloadFragment.EXTRA_ERROR);
             } else {
@@ -133,7 +127,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
         ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.progressBar);
         mProgressListener = new ProgressListener(progressBar);
         
-        ((Button)mView.findViewById(R.id.cancelBtn)).setOnClickListener(this);
+        ((ImageButton)mView.findViewById(R.id.cancelBtn)).setOnClickListener(this);
         
         if (mError) {
             setButtonsForRemote();
@@ -167,7 +161,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         if (mAccount != null) {
-            mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
+            //mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
         }
     }
         
@@ -175,7 +169,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
-        outState.putParcelable(FileDownloadFragment.EXTRA_FILE, mFile);
+        outState.putParcelable(FileDownloadFragment.EXTRA_FILE, getFile());
         outState.putParcelable(FileDownloadFragment.EXTRA_ACCOUNT, mAccount);
         outState.putBoolean(FileDownloadFragment.EXTRA_ERROR, mError);
     }
@@ -224,8 +218,8 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
         switch (v.getId()) {
             case R.id.cancelBtn: {
                 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
-                if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
-                    downloaderBinder.cancel(mAccount, mFile);
+                if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
+                    downloaderBinder.cancel(mAccount, getFile());
                     getActivity().finish(); // :)
                     /*
                     leaveTransferProgress();
@@ -245,14 +239,6 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
 
     
     /**
-     * {@inheritDoc}
-     */
-    public OCFile getFile(){
-        return mFile;
-    }
-    
-    
-    /**
      * Updates the view depending upon the state of the downloading file.
      * 
      * @param   transferring    When true, the view must be updated assuming that the holded file is 
@@ -261,10 +247,10 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
     public void updateView(boolean transferring) {
         // configure UI for depending upon local state of the file
         FileDownloaderBinder downloaderBinder = (mContainerActivity == null) ? null : mContainerActivity.getFileDownloaderBinder();
-        if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile))) {
+        if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile()))) {
             setButtonsForTransferring();
             
-        } else if (mFile.isDown()) {
+        } else if (getFile().isDown()) {
             
             setButtonsForDown();
             
@@ -335,7 +321,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
     public void listenForTransferProgress() {
         if (mProgressListener != null && !mListening) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {
-                mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+                mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, getFile());
                 mListening = true;
                 setButtonsForTransferring();
             }
@@ -346,7 +332,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis
     public void leaveTransferProgress() {
         if (mProgressListener != null) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {
-                mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
+                mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, getFile());
                 mListening = false;
             }
         }
index 7a0fc75..a41f6eb 100644 (file)
@@ -44,7 +44,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.FileFragment;
 
 import com.owncloud.android.AccountUtils;
@@ -56,7 +56,7 @@ import com.owncloud.android.R;
  *  
  *  @author David A. Velasco
  */
-public class PreviewImageActivity extends SherlockFragmentActivity implements FileFragment.ContainerActivity, ViewPager.OnPageChangeListener, OnTouchListener {
+public class PreviewImageActivity extends FileActivity implements FileFragment.ContainerActivity, ViewPager.OnPageChangeListener, OnTouchListener {
     
     public static final int DIALOG_SHORT_WAIT = 0;
 
@@ -255,13 +255,6 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
     
 
     private void backToDisplayActivity() {
-        /*
-        Intent intent = new Intent(this, FileDisplayActivity.class);
-        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        intent.putExtra(FileDetailFragment.EXTRA_FILE, mFile);
-        intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, mAccount);
-        startActivity(intent);
-        */
         finish();
     }
     
@@ -311,11 +304,11 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
 
 
     @Override
-    public void showFragmentWithDetails(OCFile file) {
-        Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+    public void showDetails(OCFile file) {
+        Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
+        showDetailsIntent.setAction(FileDisplayActivity.ACTION_DETAILS);
         showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, file);
         showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
-        showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
         startActivity(showDetailsIntent);
         int pos = mPreviewImagePagerAdapter.getFilePosition(file);
         file = mPreviewImagePagerAdapter.getFileAt(pos);
@@ -440,6 +433,11 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
         }
         mFullScreen = !mFullScreen;
     }
+
+    @Override
+    protected void onAccountSet(boolean stateWasRecovered) {
+        // TODO
+    }
     
     
 }
index 8df06bf..9d49153 100644 (file)
@@ -47,7 +47,6 @@ import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.Toast;
 
-import com.actionbarsherlock.app.SherlockFragment;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
@@ -74,14 +73,12 @@ import eu.alefzero.webdav.WebdavUtils;
  * 
  * @author David A. Velasco
  */
-public class PreviewImageFragment extends SherlockFragment implements   FileFragment, 
-                                                                        OnRemoteOperationListener, 
+public class PreviewImageFragment extends FileFragment implements   OnRemoteOperationListener, 
                                                                         ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
     public static final String EXTRA_FILE = "FILE";
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
 
     private View mView;
-    private OCFile mFile;
     private Account mAccount;
     private FileDataStorageManager mStorageManager;
     private ImageView mImageView;
@@ -108,7 +105,7 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
      * @param ignoreFirstSavedState     Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution 
      */
     public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) {
-        mFile = fileToDetail;
+        super(fileToDetail);
         mAccount = ocAccount;
         mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
         mIgnoreFirstSavedState = ignoreFirstSavedState;
@@ -123,7 +120,7 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
      *  DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction 
      */
     public PreviewImageFragment() {
-        mFile = null;
+        super();
         mAccount = null;
         mStorageManager = null;
         mIgnoreFirstSavedState = false;
@@ -180,19 +177,19 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
         mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
         if (savedInstanceState != null) {
             if (!mIgnoreFirstSavedState) {
-                mFile = savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE);
+                setFile((OCFile)savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE));
                 mAccount = savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_ACCOUNT);
             } else {
                 mIgnoreFirstSavedState = false;
             }
         }
-        if (mFile == null) {
+        if (getFile() == null) {
             throw new IllegalStateException("Instanced with a NULL OCFile");
         }
         if (mAccount == null) {
             throw new IllegalStateException("Instanced with a NULL ownCloud Account");
         }
-        if (!mFile.isDown()) {
+        if (!getFile().isDown()) {
             throw new IllegalStateException("There is no local file to preview");
         }
     }
@@ -204,7 +201,7 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
-        outState.putParcelable(PreviewImageFragment.EXTRA_FILE, mFile);
+        outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile());
         outState.putParcelable(PreviewImageFragment.EXTRA_ACCOUNT, mAccount);
     }
     
@@ -212,9 +209,9 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
     @Override
     public void onStart() {
         super.onStart();
-        if (mFile != null) {
+        if (getFile() != null) {
            BitmapLoader bl = new BitmapLoader(mImageView, mMessageView, mProgressWheel);
-           bl.execute(new String[]{mFile.getStoragePath()});
+           bl.execute(new String[]{getFile().getStoragePath()});
         }
     }
     
@@ -272,42 +269,19 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
 
     
     private void seeDetails() {
-        ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mFile);        
+        ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());        
     }
 
 
     @Override
     public void onResume() {
         super.onResume();
-        //Log.e(TAG, "FRAGMENT, ONRESUME");
-        /*
-        mDownloadFinishReceiver = new DownloadFinishReceiver();
-        IntentFilter filter = new IntentFilter(
-                FileDownloader.DOWNLOAD_FINISH_MESSAGE);
-        getActivity().registerReceiver(mDownloadFinishReceiver, filter);
-        
-        mUploadFinishReceiver = new UploadFinishReceiver();
-        filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
-        getActivity().registerReceiver(mUploadFinishReceiver, filter);
-        */
-
     }
 
 
     @Override
     public void onPause() {
         super.onPause();
-        /*
-        if (mVideoPreview.getVisibility() == View.VISIBLE) {
-            mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
-        }*/
-        /*
-        getActivity().unregisterReceiver(mDownloadFinishReceiver);
-        mDownloadFinishReceiver = null;
-        
-        getActivity().unregisterReceiver(mUploadFinishReceiver);
-        mUploadFinishReceiver = null;
-        */
     }
 
 
@@ -328,22 +302,23 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
      * available apps for the MIME type known from the file extension, to let the user choose
      */
     private void openFile() {
-        String storagePath = mFile.getStoragePath();
+        OCFile file = getFile();
+        String storagePath = file.getStoragePath();
         String encodedStoragePath = WebdavUtils.encodePath(storagePath);
         try {
             Intent i = new Intent(Intent.ACTION_VIEW);
-            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
+            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
             i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
             startActivity(i);
             
         } catch (Throwable t) {
-            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
+            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file.getMimetype());
             boolean toastIt = true; 
             String mimeType = "";
             try {
                 Intent i = new Intent(Intent.ACTION_VIEW);
                 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
-                if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
+                if (mimeType == null || !mimeType.equals(file.getMimetype())) {
                     if (mimeType != null) {
                         i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
                     } else {
@@ -366,7 +341,7 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
                 
             } finally {
                 if (toastIt) {
-                    Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
+                    Toast.makeText(getActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
                 }
             }
             
@@ -384,7 +359,7 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
     private void removeFile() {
         ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
                 R.string.confirmation_remove_alert,
-                new String[]{mFile.getFileName()},
+                new String[]{getFile().getFileName()},
                 R.string.confirmation_remove_remote_and_local,
                 R.string.confirmation_remove_local,
                 R.string.common_cancel);
@@ -398,8 +373,8 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
      */
     @Override
     public void onConfirmation(String callerTag) {
-        if (mStorageManager.getFileById(mFile.getFileId()) != null) {   // check that the file is still there;
-            mLastRemoteOperation = new RemoveFileOperation( mFile,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
+        if (mStorageManager.getFileById(getFile().getFileId()) != null) {   // check that the file is still there;
+            mLastRemoteOperation = new RemoveFileOperation( getFile(),      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
                                                             true, 
                                                             mStorageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
@@ -415,11 +390,12 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
     @Override
     public void onNeutral(String callerTag) {
         // TODO this code should be made in a secondary thread,
-        if (mFile.isDown()) {   // checks it is still there
-            File f = new File(mFile.getStoragePath());
+        OCFile file = getFile();
+        if (file.isDown()) {   // checks it is still there
+            File f = new File(file.getStoragePath());
             f.delete();
-            mFile.setStoragePath(null);
-            mStorageManager.saveFile(mFile);
+            file.setStoragePath(null);
+            mStorageManager.saveFile(file);
             finish();
         }
     }
@@ -433,33 +409,6 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
     }
     
 
-    /**
-     * {@inheritDoc}
-     */
-    public OCFile getFile(){
-        return mFile;
-    }
-    
-    /*
-    /**
-     * Use this method to signal this Activity that it shall update its view.
-     * 
-     * @param file : An {@link OCFile}
-     *-/
-    public void updateFileDetails(OCFile file, Account ocAccount) {
-        mFile = file;
-        if (ocAccount != null && ( 
-                mStorageManager == null || 
-                (mAccount != null && !mAccount.equals(ocAccount))
-           )) {
-            mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
-        }
-        mAccount = ocAccount;
-        updateFileDetails(false);
-    }
-    */
-    
-
     private class BitmapLoader extends AsyncTask<String, Void, Bitmap> {
 
         /**
@@ -571,7 +520,7 @@ public class PreviewImageFragment extends SherlockFragment implements   FileFrag
                     
             } catch (Throwable t) {
                 mErrorMessageId = R.string.common_error_unknown;
-                Log_OC.e(TAG, "Unexpected error loading " + mFile.getStoragePath(), t);
+                Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
                 
             }
             return result;
index 164fe04..7ea9f52 100644 (file)
@@ -39,7 +39,6 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
-import android.support.v4.app.FragmentTransaction;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -50,7 +49,6 @@ import android.widget.ImageView;
 import android.widget.Toast;
 import android.widget.VideoView;
 
-import com.actionbarsherlock.app.SherlockFragment;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
@@ -63,10 +61,8 @@ 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.FileDetailActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
-import com.owncloud.android.ui.fragment.FileDetailFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 
 import com.owncloud.android.Log_OC;
@@ -82,8 +78,8 @@ import eu.alefzero.webdav.WebdavUtils;
  * 
  * @author David A. Velasco
  */
-public class PreviewMediaFragment extends SherlockFragment implements
-        OnTouchListener , FileFragment,  
+public class PreviewMediaFragment extends FileFragment implements
+        OnTouchListener,  
         ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener  {
 
     public static final String EXTRA_FILE = "FILE";
@@ -92,7 +88,6 @@ public class PreviewMediaFragment extends SherlockFragment implements
     private static final String EXTRA_PLAYING = "PLAYING";
 
     private View mView;
-    private OCFile mFile;
     private Account mAccount;
     private FileDataStorageManager mStorageManager;
     private ImageView mImagePreview;
@@ -121,7 +116,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
      * @param ocAccount         An ownCloud account; needed to start downloads
      */
     public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount, int startPlaybackPosition, boolean autoplay) {
-        mFile = fileToDetail;
+        super(fileToDetail);
         mAccount = ocAccount;
         mSavedPlaybackPosition = startPlaybackPosition;
         mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment 
@@ -137,7 +132,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
      *  DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction 
      */
     public PreviewMediaFragment() {
-        mFile = null;
+        super();
         mAccount = null;
         mSavedPlaybackPosition = 0;
         mStorageManager = null;
@@ -201,22 +196,23 @@ public class PreviewMediaFragment extends SherlockFragment implements
 
         mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
         if (savedInstanceState != null) {
-            mFile = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE);
+            setFile((OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE));
             mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT);
             mSavedPlaybackPosition = savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION);
             mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING);
             
         }
-        if (mFile == null) {
+        OCFile file = getFile();
+        if (file == null) {
             throw new IllegalStateException("Instanced with a NULL OCFile");
         }
         if (mAccount == null) {
             throw new IllegalStateException("Instanced with a NULL ownCloud Account");
         }
-        if (!mFile.isDown()) {
+        if (!file.isDown()) {
             throw new IllegalStateException("There is no local file to preview");
         }
-        if (mFile.isVideo()) {
+        if (file.isVideo()) {
             mVideoPreview.setVisibility(View.VISIBLE);
             mImagePreview.setVisibility(View.GONE);
             prepareVideo();
@@ -237,10 +233,10 @@ public class PreviewMediaFragment extends SherlockFragment implements
         super.onSaveInstanceState(outState);
         Log_OC.e(TAG, "onSaveInstanceState");
         
-        outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, mFile);
+        outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, getFile());
         outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
         
-        if (mFile.isVideo()) {
+        if (getFile().isVideo()) {
             mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
             mAutoplay = mVideoPreview.isPlaying();
             outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mSavedPlaybackPosition);
@@ -257,11 +253,12 @@ public class PreviewMediaFragment extends SherlockFragment implements
         super.onStart();
         Log_OC.e(TAG, "onStart");
 
-        if (mFile != null) {
-           if (mFile.isAudio()) {
+        OCFile file = getFile();
+        if (file != null) {
+           if (file.isAudio()) {
                bindMediaService();
                
-           } else if (mFile.isVideo()) {
+           } else if (file.isVideo()) {
                stopAudio();
                playVideo(); 
            }
@@ -331,7 +328,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
     
     private void seeDetails() {
         stopPreview(false);
-        ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mFile);        
+        ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());        
     }
 
 
@@ -348,7 +345,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
         mMediaController.setMediaPlayer(mVideoPreview);
         
         // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called
-        mVideoPreview.setVideoPath(mFile.getStoragePath()); 
+        mVideoPreview.setVideoPath(getFile().getStoragePath()); 
     }
     
 
@@ -397,7 +394,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
                     mVideoPreview.stopPlayback();
                     mAutoplay = false;
                     mSavedPlaybackPosition = 0;
-                    mVideoPreview.setVideoPath(mFile.getStoragePath());
+                    mVideoPreview.setVideoPath(getFile().getStoragePath());
                 }
             } // else : called from onError()
             mMediaController.updatePausePlay();
@@ -481,7 +478,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
     private void startFullScreenVideo() {
         Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
         i.putExtra(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
-        i.putExtra(PreviewVideoActivity.EXTRA_FILE, mFile);
+        i.putExtra(PreviewVideoActivity.EXTRA_FILE, getFile());
         i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
         mVideoPreview.pause();
         i.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPreview.getCurrentPosition());
@@ -505,9 +502,10 @@ public class PreviewMediaFragment extends SherlockFragment implements
     
 
     private void playAudio() {
-        if (!mMediaServiceBinder.isPlaying(mFile)) {
-            Log_OC.d(TAG, "starting playback of " + mFile.getStoragePath());
-            mMediaServiceBinder.start(mAccount, mFile, mAutoplay, mSavedPlaybackPosition);
+        OCFile file = getFile();
+        if (!mMediaServiceBinder.isPlaying(file)) {
+            Log_OC.d(TAG, "starting playback of " + file.getStoragePath());
+            mMediaServiceBinder.start(mAccount, file, mAutoplay, mSavedPlaybackPosition);
             
         } else {
             if (!mMediaServiceBinder.isPlaying() && mAutoplay) {
@@ -584,23 +582,24 @@ public class PreviewMediaFragment extends SherlockFragment implements
      * available apps for the MIME type known from the file extension, to let the user choose
      */
     private void openFile() {
+        OCFile file = getFile();
         stopPreview(true);
-        String storagePath = mFile.getStoragePath();
+        String storagePath = file.getStoragePath();
         String encodedStoragePath = WebdavUtils.encodePath(storagePath);
         try {
             Intent i = new Intent(Intent.ACTION_VIEW);
-            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
+            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
             i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
             startActivity(i);
             
         } catch (Throwable t) {
-            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
+            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file.getMimetype());
             boolean toastIt = true; 
             String mimeType = "";
             try {
                 Intent i = new Intent(Intent.ACTION_VIEW);
                 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
-                if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
+                if (mimeType == null || !mimeType.equals(file.getMimetype())) {
                     if (mimeType != null) {
                         i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
                     } else {
@@ -623,7 +622,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
                 
             } finally {
                 if (toastIt) {
-                    Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
+                    Toast.makeText(getActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
                 }
             }
             
@@ -640,7 +639,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
     private void removeFile() {
         ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
                 R.string.confirmation_remove_alert,
-                new String[]{mFile.getFileName()},
+                new String[]{getFile().getFileName()},
                 R.string.confirmation_remove_remote_and_local,
                 R.string.confirmation_remove_local,
                 R.string.common_cancel);
@@ -654,15 +653,16 @@ public class PreviewMediaFragment extends SherlockFragment implements
      */
     @Override
     public void onConfirmation(String callerTag) {
-        if (mStorageManager.getFileById(mFile.getFileId()) != null) {   // check that the file is still there;
+        OCFile file = getFile();
+        if (mStorageManager.getFileById(file.getFileId()) != null) {   // check that the file is still there;
             stopPreview(true);
-            mLastRemoteOperation = new RemoveFileOperation( mFile,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
+            mLastRemoteOperation = new RemoveFileOperation( file,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
                                                             true, 
                                                             mStorageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
             boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-            getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+            getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         }
     }
     
@@ -673,12 +673,13 @@ public class PreviewMediaFragment extends SherlockFragment implements
     @Override
     public void onNeutral(String callerTag) {
         // TODO this code should be made in a secondary thread,
-        if (mFile.isDown()) {   // checks it is still there
+        OCFile file = getFile();
+        if (file.isDown()) {   // checks it is still there
             stopPreview(true);
-            File f = new File(mFile.getStoragePath());
+            File f = new File(file.getStoragePath());
             f.delete();
-            mFile.setStoragePath(null);
-            mStorageManager.saveFile(mFile);
+            file.setStoragePath(null);
+            mStorageManager.saveFile(file);
             finish();
         }
     }
@@ -693,33 +694,6 @@ public class PreviewMediaFragment extends SherlockFragment implements
     
 
     /**
-     * {@inheritDoc}
-     */
-    public OCFile getFile(){
-        return mFile;
-    }
-    
-    /*
-    /**
-     * Use this method to signal this Activity that it shall update its view.
-     * 
-     * @param file : An {@link OCFile}
-     *-/
-    public void updateFileDetails(OCFile file, Account ocAccount) {
-        mFile = file;
-        if (ocAccount != null && ( 
-                mStorageManager == null || 
-                (mAccount != null && !mAccount.equals(ocAccount))
-           )) {
-            mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
-        }
-        mAccount = ocAccount;
-        updateFileDetails(false);
-    }
-    */
-    
-
-    /**
      * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
      * 
      * @param file      File to test if can be previewed.
@@ -743,7 +717,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
         boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
-        getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+        getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
         
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
@@ -760,10 +734,11 @@ public class PreviewMediaFragment extends SherlockFragment implements
     }
 
     private void stopPreview(boolean stopAudio) {
-        if (mFile.isAudio() && stopAudio) {
+        OCFile file = getFile();
+        if (file.isAudio() && stopAudio) {
             mMediaServiceBinder.pause();
             
-        } else if (mFile.isVideo()) {
+        } else if (file.isVideo()) {
             mVideoPreview.stopPlayback();
         }
     }
@@ -774,16 +749,7 @@ public class PreviewMediaFragment extends SherlockFragment implements
      * Finishes the preview
      */
     private void finish() {
-        Activity container = getActivity();
-        if (container instanceof FileDisplayActivity) {
-            // double pane
-            FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
-            transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
-            transaction.commit();
-            ((FileFragment.ContainerActivity)container).onFileStateChanged();
-        } else {
-            container.finish();
-        }
+        getActivity().onBackPressed();
     }
 
 
index 5940126..2731f9c 100644 (file)
@@ -1,11 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry combineaccessrules="false" kind="src" path="/owncloud-android"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
-       <classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
-       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
index 8000cd6..877df2d 100644 (file)
@@ -1,4 +1,8 @@
 eclipse.preferences.version=1
+<<<<<<< HEAD
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+=======
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
@@ -8,4 +12,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+>>>>>>> develop
 org.eclipse.jdt.core.compiler.source=1.6
index 8937e94..a3ee5ab 100644 (file)
@@ -11,4 +11,4 @@
 #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
 
 # Project target.
-target=android-14
+target=android-17