Merge pull request #1088 from owncloud/updated_docs_about_target_of_PRs
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
index 831c25f..6840f91 100644 (file)
@@ -49,7 +49,6 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v4.view.GravityCompat;
-import android.support.v7.app.ActionBar;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -59,6 +58,7 @@ import android.widget.Toast;
 
 import com.owncloud.android.MainApp;
 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;
@@ -195,9 +195,6 @@ public class FileDisplayActivity extends HookActivity
         getSupportActionBar().setHomeButtonEnabled(true);       // mandatory since Android ICS,
                                                                 // according to the official
                                                                 // documentation
-        if (getFile() != null) {
-            updateActionBarTitle();
-        }
 
         setSupportProgressBarIndeterminateVisibility(mSyncInProgress
         /*|| mRefreshSharesInProgress*/);
@@ -263,7 +260,7 @@ public class FileDisplayActivity extends HookActivity
                 
             } else {
                 updateFragmentsVisibility(!file.isFolder());
-                updateNavigationElementsInActionBar(file.isFolder() ? null : file);
+                updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
             }
         }
     }
@@ -294,7 +291,7 @@ public class FileDisplayActivity extends HookActivity
             if (secondFragment != null) {
                 setSecondFragment(secondFragment);
                 updateFragmentsVisibility(true);
-                updateNavigationElementsInActionBar(file);
+                updateActionBarTitleAndHomeButton(file);
                 
             } else {
                 cleanSecondFragment();
@@ -325,7 +322,7 @@ public class FileDisplayActivity extends HookActivity
                         startPlaybackPosition, autoplay);
 
             } else {
-                secondFragment = new FileDetailFragment(file, getAccount());
+                secondFragment = FileDetailFragment.newInstance(file, getAccount());
             }
         }
         return secondFragment;
@@ -402,7 +399,7 @@ public class FileDisplayActivity extends HookActivity
             tr.commit();
         }
         updateFragmentsVisibility(false);
-        updateNavigationElementsInActionBar(null);
+        updateActionBarTitleAndHomeButton(null);
     }
 
     protected void refreshListOfFilesFragment() {
@@ -624,10 +621,7 @@ public class FileDisplayActivity extends HookActivity
         String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
         if (filePaths != null) {
             String[] remotePaths = new String[filePaths.length];
-            String remotePathBase = "";
-
-            if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR))
-                remotePathBase += OCFile.PATH_SEPARATOR;
+            String remotePathBase = getCurrentDir().getRemotePath();
             for (int j = 0; j< remotePaths.length; j++) {
                 remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
             }
@@ -736,6 +730,11 @@ public class FileDisplayActivity extends HookActivity
     public void onBackPressed() {
         OCFileListFragment listOfFiles = getListOfFilesFragment(); 
         if (mDualPane || getSecondFragment() == null) {
+            OCFile currentDir = getCurrentDir();
+            if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
+                finish();
+                return;
+            }
             if (listOfFiles != null) {  // should never be null, indeed
                 listOfFiles.onBrowseUp();
             }
@@ -743,7 +742,6 @@ public class FileDisplayActivity extends HookActivity
         if (listOfFiles != null) {  // should never be null, indeed
             setFile(listOfFiles.getCurrentFile());
         }
-        updateActionBarTitle();
         cleanSecondFragment();
 
     }
@@ -1122,7 +1120,6 @@ public class FileDisplayActivity extends HookActivity
             // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice());
             setFile(listOfFiles.getCurrentFile());
             startSyncFolderOperation(root, false);
-            updateActionBarTitle();
         }
         cleanSecondFragment();
 
@@ -1136,12 +1133,10 @@ public class FileDisplayActivity extends HookActivity
      */
     @Override
     public void onBrowsedDownTo(OCFile directory) {
-        cleanSecondFragment();
         setFile(directory);
-        updateActionBarTitle();
+        cleanSecondFragment();
         // Sync Folder
         startSyncFolderOperation(directory, false);
-        
     }
 
     /**
@@ -1152,52 +1147,23 @@ public class FileDisplayActivity extends HookActivity
      */
     @Override
     public void showDetails(OCFile file) {
-        Fragment detailFragment = new FileDetailFragment(file, getAccount());
+        Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
         setSecondFragment(detailFragment);
         updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
+        updateActionBarTitleAndHomeButton(file);
         setFile(file);
     }
 
-
-    /**
-     * TODO
-     */
-    private void updateNavigationElementsInActionBar(OCFile chosenFile) {
-        ActionBar actionBar = getSupportActionBar();
-
-        // For adding content description tag to a title field in the action bar
-        int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
-
-        if (chosenFile == null || mDualPane) {
-            // only list of files - set for browsing through folders
-            OCFile currentDir = getCurrentDir();
-            boolean noRoot = (currentDir != null && currentDir.getParentId() != 0);
-//            actionBar.setDisplayHomeAsUpEnabled(noRoot);
-//            actionBar.setDisplayShowTitleEnabled(!noRoot);
-            actionBar.setDisplayHomeAsUpEnabled(true);
-            actionBar.setDisplayShowTitleEnabled(true);
-            if (!noRoot) {
-                actionBar.setTitle(getString(R.string.default_display_name_for_root_folder));
-                View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
-                if (actionBarTitleView != null) {    // it's null in Android 2.x
-                    actionBarTitleView.setContentDescription(
-                            getString(R.string.default_display_name_for_root_folder));
-                }
-            }
-            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+    @Override
+    protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
+        if (mDualPane) {
+            // in dual pane mode, keep the focus of title an action bar in the current folder
+            super.updateActionBarTitleAndHomeButton(getCurrentDir());
 
         } else {
-            actionBar.setDisplayHomeAsUpEnabled(true);
-            actionBar.setDisplayShowTitleEnabled(true);
-            actionBar.setTitle(chosenFile.getFileName());
-            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
-            View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
-            if (actionBarTitleView != null) {    // it's null in Android 2.x
-                getWindow().getDecorView().findViewById(actionBarTitleId).
-                        setContentDescription(chosenFile.getFileName());
-            }
+            super.updateActionBarTitleAndHomeButton(chosenFile);
         }
+
     }
 
 
@@ -1661,7 +1627,7 @@ public class FileDisplayActivity extends HookActivity
                 autoplay);
         setSecondFragment(mediaFragment);
         updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
+        updateActionBarTitleAndHomeButton(file);
         setFile(file);
     }
 
@@ -1673,12 +1639,12 @@ public class FileDisplayActivity extends HookActivity
      * @param file          {@link OCFile} to download and preview.
      */
     public void startDownloadForPreview(OCFile file) {
-        Fragment detailFragment = new FileDetailFragment(file, getAccount());
+        Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
         setSecondFragment(detailFragment);
         mWaitingToPreview = file;
         requestForDownload();
         updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
+        updateActionBarTitleAndHomeButton(file);
         setFile(file);
     }