浏览代码

FileDetailsFragment now working on tablets

Lennart Rosam 13 年之前
父节点
当前提交
ffc941e440

+ 2 - 2
res/layout-large-land/files.xml

@@ -24,7 +24,7 @@
     <LinearLayout
         android:id="@+id/file_list_container"
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
+        android:layout_height="fill_parent"
         android:layout_weight="1" >
 
         <fragment
@@ -39,7 +39,7 @@
 
     <LinearLayout android:id="@+id/file_details_container"
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
+        android:layout_height="fill_parent"
         android:layout_weight="2" >
 
         <fragment

+ 18 - 16
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

@@ -53,7 +53,7 @@ public class FileDetailFragment extends SherlockFragment implements
     public static final String FILE = "FILE";
 
     private Intent mIntent;
-    private View mView;
+    //private View mView;
     private DownloadFinishReceiver mDownloadFinishReceiver;
     private OCFile mFile;
 
@@ -73,7 +73,7 @@ public class FileDetailFragment extends SherlockFragment implements
      * to contain {@link FileDetailFragment#FILE} with an OCFile and also
      * {@link FileDownloader#EXTRA_ACCOUNT} with the account.
      * 
-     * @param nonEmptyFragment True, to enable file detail rendering
+     * @param intent Intent with an account and a file in it for rendering
      */
     public FileDetailFragment(Intent intent) {
         mLayout = R.layout.file_details_fragment;
@@ -124,7 +124,7 @@ public class FileDetailFragment extends SherlockFragment implements
             setFilesize(mFile.getFileLength());
 
             // set file preview if available and possible
-            VideoView videoView = (VideoView) mView
+            VideoView videoView = (VideoView) getView()
                     .findViewById(R.id.videoView1);
             videoView.setVisibility(View.INVISIBLE);
             if (mFile.getStoragePath() == null) {
@@ -134,7 +134,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 imageView.setOnClickListener(this);
             } else {
                 if (mFile.getMimetype().startsWith("image/")) {
-                    ImageView imageView = (ImageView) mView
+                    ImageView imageView = (ImageView) getView()
                             .findViewById(R.id.imageView2);
                     Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath());
                     imageView.setImageBitmap(bmp);
@@ -151,23 +151,25 @@ public class FileDetailFragment extends SherlockFragment implements
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
         View view = null;
-
         view = inflater.inflate(mLayout, container, false);
-        mIntent = getActivity().getIntent();
-        mView = view;
-
-        // make sure we are not using the empty layout
-        if (mEmptyLayout == false) {
-            updateFileDetails();
-        }
-
         return view;
     }
 
     @Override
-    public View getView() {
-        return mView == null ? super.getView() : mView;
-    };
+    public void onStart() {
+        super.onStart();
+        
+        // Fill in required information about file displaying
+        if(mIntent == null){
+            mIntent = getActivity().getIntent();
+        }
+        
+        // Fill in the details if the layout is not empty
+        if(!mEmptyLayout){
+            updateFileDetails();
+        }
+        
+    }
 
     private void setFilename(String filename) {
         TextView tv = (TextView) getView().findViewById(R.id.textView1);

+ 20 - 3
src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java

@@ -84,6 +84,8 @@ public class FileListFragment extends FragmentListView {
             ((FileDisplayActivity) getActivity()).pushPath(dirname);
 
             populateFileList();
+            resetFileFragment();
+            
             return;
         }
 
@@ -107,11 +109,11 @@ public class FileListFragment extends FragmentListView {
 
             if (fd.isEmptyLayout()) {
                 // True, if this is the first time a user taps on a file
-                fd = new FileDetailFragment(showDetailsIntent);
                 FragmentTransaction transaction = getFragmentManager()
                         .beginTransaction();
-                transaction.replace(R.id.file_details_container, fd,
-                        "FileDetails");
+                fd = new FileDetailFragment(showDetailsIntent);
+                transaction.replace(R.id.fileDetail, fd, "FileDetails");
+                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                 transaction.commit();
             } else {
                 fd.updateFileDetails(showDetailsIntent);
@@ -122,6 +124,20 @@ public class FileListFragment extends FragmentListView {
         }
     }
 
+    /**
+     * Resets the FileDetailsFragment on Tablets
+     * so that it always displays "Tab on a file to display it's details" 
+     */
+    private void resetFileFragment() {
+        FileDetailFragment fileDetails = (FileDetailFragment) getFragmentManager().findFragmentByTag("FileDetails");
+        if(fileDetails != null){
+            FragmentTransaction transaction = getFragmentManager().beginTransaction();
+            transaction.remove(fileDetails);
+            transaction.add(R.id.file_details_container, new FileDetailFragment());
+            transaction.commit();
+        }
+    }
+
     @Override
     public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
             long arg3) {
@@ -140,6 +156,7 @@ public class FileListFragment extends FragmentListView {
     public void onNavigateUp() {
         mDirNames.pop();
         populateFileList();
+        resetFileFragment();
     }
 
     /**