Jorge Antonio Diaz-Benito Soriano 10 жил өмнө
parent
commit
4a5718a445

+ 31 - 35
res/layout/file_preview.xml

@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ownCloud Android client application
 
   Copyright (C) 2012-2013  ownCloud Inc.
@@ -25,40 +24,37 @@
     android:layout_height="match_parent"
     android:background="@color/background_color"
     android:gravity="center"
-    tools:context=".ui.fragment.FilePreviewFragment" >
+    tools:context=".ui.fragment.FilePreviewFragment">
 
-    <FrameLayout 
+    <FrameLayout
         android:id="@+id/visual_area"
-   	    android:layout_width="match_parent"
-   	    android:layout_height="0dp"
-   	    android:layout_alignParentTop="true"
-   	    android:layout_above="@+id/media_controller"
-        >
-    
-	    <ImageView
-	        android:id="@+id/image_preview"
-	        android:layout_width="match_parent"
-	        android:layout_height="match_parent"
-	        android:layout_margin="16dp"
-	        android:layout_gravity="center"
-	        android:contentDescription="@string/preview_image_description"
-	        android:src="@drawable/logo" />
-	    
-	   	<VideoView  
-	   	    android:id="@+id/video_preview"
-			android:layout_width="match_parent"
-			android:layout_height="match_parent"  
-			android:layout_gravity="center" 
-			android:visibility="gone"
-			/>
-	   	
-   	</FrameLayout>
-   	
-   	<com.owncloud.android.media.MediaControlView 
-   	    android:id="@id/media_controller"
-   	    android:layout_width="match_parent"
-   	    android:layout_height="wrap_content"
-   	    android:layout_alignParentBottom="true"
-   	    />
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_alignParentTop="true"
+        android:layout_above="@+id/media_controller">
+
+        <ImageView
+            android:id="@+id/image_preview"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_margin="16dp"
+            android:layout_gravity="center"
+            android:contentDescription="@string/preview_image_description"
+            android:src="@drawable/logo" />
+
+        <VideoView
+            android:id="@+id/video_preview"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_gravity="center"
+            android:visibility="gone" />
+
+    </FrameLayout>
+
+    <com.owncloud.android.media.MediaControlView
+        android:id="@id/media_controller"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true" />
 
 </RelativeLayout>

+ 29 - 0
res/layout/text_file_preview.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_marginStart="8dp"
+    android:layout_marginEnd="8dp">
+
+    <ScrollView
+        android:id="@+id/text_scrollview"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:scrollbars="vertical"
+        android:fillViewport="true"
+        android:visibility="gone">
+
+        <TextView
+            android:id="@+id/text_preview"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center" />
+    </ScrollView>
+
+    <ProgressBar
+        android:id="@+id/progress_bar"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:visibility="gone" />
+</FrameLayout>

+ 78 - 67
src/com/owncloud/android/datamodel/OCFile.java

@@ -18,15 +18,14 @@
 
 package com.owncloud.android.datamodel;
 
-import java.io.File;
-
-import com.owncloud.android.lib.common.utils.Log_OC;
-
-
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.webkit.MimeTypeMap;
 
+import com.owncloud.android.lib.common.utils.Log_OC;
+
+import java.io.File;
+
 public class OCFile implements Parcelable, Comparable<OCFile> {
 
     public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<OCFile>() {
@@ -45,7 +44,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     public static final String ROOT_PATH = PATH_SEPARATOR;
 
     private static final String TAG = OCFile.class.getSimpleName();
-    
+
     private long mId;
     private long mParentId;
     private long mLength;
@@ -61,7 +60,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     private boolean mKeepInSync;
 
     private String mEtag;
-    
+
     private boolean mShareByLink;
     private String mPublicLink;
 
@@ -73,9 +72,9 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Create new {@link OCFile} with given path.
-     * 
+     * <p/>
      * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
-     * 
+     *
      * @param path The remote path of the file.
      */
     public OCFile(String path) {
@@ -89,7 +88,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Reconstruct from parcel
-     * 
+     *
      * @param source The source parcel
      */
     private OCFile(Parcel source) {
@@ -137,10 +136,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         dest.writeString(mRemoteId);
         dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0);
     }
-    
+
     /**
      * Gets the ID of the file
-     * 
+     *
      * @return the file ID
      */
     public long getFileId() {
@@ -149,7 +148,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Returns the remote path of the file on ownCloud
-     * 
+     *
      * @return The remote path to the file
      */
     public String getRemotePath() {
@@ -159,7 +158,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     /**
      * Can be used to check, whether or not this file exists in the database
      * already
-     * 
+     *
      * @return true, if the file exists in the database
      */
     public boolean fileExists() {
@@ -168,7 +167,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Use this to find out if this file is a folder.
-     * 
+     *
      * @return true if it is a folder
      */
     public boolean isFolder() {
@@ -177,7 +176,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Use this to check if this file is available locally
-     * 
+     *
      * @return true if it is
      */
     public boolean isDown() {
@@ -187,10 +186,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         }
         return false;
     }
-    
+
     /**
      * The path, where the file is stored locally
-     * 
+     *
      * @return The local path to the file
      */
     public String getStoragePath() {
@@ -199,7 +198,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Can be used to set the path where the file is stored
-     * 
+     *
      * @param storage_path to set
      */
     public void setStoragePath(String storage_path) {
@@ -208,7 +207,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Get a UNIX timestamp of the file creation time
-     * 
+     *
      * @return A UNIX timestamp of the time that file was created
      */
     public long getCreationTimestamp() {
@@ -217,7 +216,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Set a UNIX timestamp of the time the file was created
-     * 
+     *
      * @param creation_timestamp to set
      */
     public void setCreationTimestamp(long creation_timestamp) {
@@ -227,8 +226,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     /**
      * Get a UNIX timestamp of the file modification time.
      *
-     * @return  A UNIX timestamp of the modification time, corresponding to the value returned by the server
-     *          in the last synchronization of the properties of this file. 
+     * @return A UNIX timestamp of the modification time, corresponding to the value returned by the server
+     * in the last synchronization of the properties of this file.
      */
     public long getModificationTimestamp() {
         return mModifiedTimestamp;
@@ -236,22 +235,22 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Set a UNIX timestamp of the time the time the file was modified.
-     * 
-     * To update with the value returned by the server in every synchronization of the properties 
+     * <p/>
+     * To update with the value returned by the server in every synchronization of the properties
      * of this file.
-     * 
+     *
      * @param modification_timestamp to set
      */
     public void setModificationTimestamp(long modification_timestamp) {
         mModifiedTimestamp = modification_timestamp;
     }
 
-    
+
     /**
      * Get a UNIX timestamp of the file modification time.
      *
-     * @return  A UNIX timestamp of the modification time, corresponding to the value returned by the server
-     *          in the last synchronization of THE CONTENTS of this file. 
+     * @return A UNIX timestamp of the modification time, corresponding to the value returned by the server
+     * in the last synchronization of THE CONTENTS of this file.
      */
     public long getModificationTimestampAtLastSyncForData() {
         return mModifiedTimestampAtLastSyncForData;
@@ -259,39 +258,38 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Set a UNIX timestamp of the time the time the file was modified.
-     * 
-     * To update with the value returned by the server in every synchronization of THE CONTENTS 
+     * <p/>
+     * To update with the value returned by the server in every synchronization of THE CONTENTS
      * of this file.
-     * 
-     * @param modification_timestamp to set
+     *
+     * @param modificationTimestamp to set
      */
     public void setModificationTimestampAtLastSyncForData(long modificationTimestamp) {
         mModifiedTimestampAtLastSyncForData = modificationTimestamp;
     }
 
-    
-    
+
     /**
      * Returns the filename and "/" for the root directory
-     * 
+     *
      * @return The name of the file
      */
     public String getFileName() {
         File f = new File(getRemotePath());
         return f.getName().length() == 0 ? ROOT_PATH : f.getName();
     }
-    
+
     /**
      * Sets the name of the file
-     * 
-     * Does nothing if the new name is null, empty or includes "/" ; or if the file is the root directory 
+     * <p/>
+     * Does nothing if the new name is null, empty or includes "/" ; or if the file is the root directory
      */
     public void setFileName(String name) {
         Log_OC.d(TAG, "OCFile name changin from " + mRemotePath);
         if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(ROOT_PATH)) {
             String parent = (new File(getRemotePath())).getParent();
             parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR;
-            mRemotePath =  parent + name;
+            mRemotePath = parent + name;
             if (isFolder()) {
                 mRemotePath += PATH_SEPARATOR;
             }
@@ -301,7 +299,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Can be used to get the Mimetype
-     * 
+     *
      * @return the Mimetype as a String
      */
     public String getMimetype() {
@@ -311,10 +309,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     /**
      * Adds a file to this directory. If this file is not a directory, an
      * exception gets thrown.
-     * 
+     *
      * @param file to add
      * @throws IllegalStateException if you try to add a something and this is
-     *             not a directory
+     *                               not a directory
      */
     public void addFile(OCFile file) throws IllegalStateException {
         if (isFolder()) {
@@ -353,7 +351,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Sets the ID of the file
-     * 
+     *
      * @param file_id to set
      */
     public void setFileId(long file_id) {
@@ -362,7 +360,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Sets the Mime-Type of the
-     * 
+     *
      * @param mimetype to set
      */
     public void setMimetype(String mimetype) {
@@ -371,7 +369,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Sets the ID of the parent folder
-     * 
+     *
      * @param parent_id to set
      */
     public void setParentId(long parent_id) {
@@ -380,7 +378,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Sets the file size in bytes
-     * 
+     *
      * @param file_len to set
      */
     public void setFileLength(long file_len) {
@@ -389,7 +387,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Returns the size of the file in bytes
-     * 
+     *
      * @return The filesize in bytes
      */
     public long getFileLength() {
@@ -398,7 +396,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Returns the ID of the parent Folder
-     * 
+     *
      * @return The ID
      */
     public long getParentId() {
@@ -407,13 +405,13 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Check, if this file needs updating
-     * 
+     *
      * @return
      */
     public boolean needsUpdatingWhileSaving() {
         return mNeedsUpdating;
     }
-    
+
     public boolean needsUpdateThumbnail() {
         return mNeedsUpdateThumbnail;
     }
@@ -425,11 +423,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     public long getLastSyncDateForProperties() {
         return mLastSyncDateForProperties;
     }
-    
+
     public void setLastSyncDateForProperties(long lastSyncDate) {
         mLastSyncDateForProperties = lastSyncDate;
     }
-    
+
     public long getLastSyncDateForData() {
         return mLastSyncDateForData;
     }
@@ -441,14 +439,14 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     public void setKeepInSync(boolean keepInSync) {
         mKeepInSync = keepInSync;
     }
-    
+
     public boolean keepInSync() {
         return mKeepInSync;
     }
-    
+
     @Override
     public int describeContents() {
-        return this.hashCode();
+        return super.hashCode();
     }
 
     @Override
@@ -465,13 +463,13 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     @Override
     public boolean equals(Object o) {
-        if(o instanceof OCFile){
+        if (o instanceof OCFile) {
             OCFile that = (OCFile) o;
-            if(that != null){
+            if (that != null) {
                 return this.mId == that.mId;
             }
         }
-        
+
         return false;
     }
 
@@ -489,8 +487,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     public void setEtag(String etag) {
         this.mEtag = etag;
     }
-    
-    
+
+
     public boolean isShareByLink() {
         return mShareByLink;
     }
@@ -515,22 +513,36 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         return 0;
     }
 
-    /** @return  'True' if the file contains audio */
+    /**
+     * @return 'True' if the file contains audio
+     */
     public boolean isAudio() {
         return (mMimeType != null && mMimeType.startsWith("audio/"));
     }
 
-    /** @return  'True' if the file contains video */
+    /**
+     * @return 'True' if the file contains video
+     */
     public boolean isVideo() {
         return (mMimeType != null && mMimeType.startsWith("video/"));
     }
 
-    /** @return  'True' if the file contains an image */
+    /**
+     * @return 'True' if the file contains an image
+     */
     public boolean isImage() {
         return ((mMimeType != null && mMimeType.startsWith("image/")) ||
-                 getMimeTypeFromName().startsWith("image/"));
+                getMimeTypeFromName().startsWith("image/"));
     }
-    
+
+    /**
+     * @return 'True' if the file is simple text (e.g. not application-dependent, like .doc or .docx)
+     */
+    public boolean isText() {
+        return !isFolder() && !isAudio() && !isVideo() && !isImage() && ((mMimeType != null && mMimeType.startsWith("text/")) ||
+                getMimeTypeFromName().startsWith("text/"));
+    }
+
     public String getMimeTypeFromName() {
         String extension = "";
         int pos = mRemotePath.lastIndexOf('.');
@@ -556,5 +568,4 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     public void setRemoteId(String remoteId) {
         this.mRemoteId = remoteId;
     }
-
 }

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 236 - 220
src/com/owncloud/android/ui/activity/FileDisplayActivity.java


+ 4 - 2
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -44,6 +44,7 @@ import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
 import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.ui.preview.PreviewMediaFragment;
+import com.owncloud.android.ui.preview.PreviewTextFragment;
 
 /**
  * A Fragment that lists all files and folders in a given path.
@@ -125,7 +126,7 @@ public class OCFileListFragment extends ExtendedListFragment {
                 mContainerActivity
         );
         setListAdapter(mAdapter);
-        
+
         registerForContextMenu(getListView());
         getListView().setOnCreateContextMenuListener(this);
   }
@@ -201,7 +202,8 @@ public class OCFileListFragment extends ExtendedListFragment {
                 if (PreviewImageFragment.canBePreviewed(file)) {
                     // preview image - it handles the download, if needed
                     ((FileDisplayActivity)mContainerActivity).startImagePreview(file);
-                    
+                } else if (PreviewTextFragment.canBePreviewed(file)){
+                    ((FileDisplayActivity)mContainerActivity).startTextPreview(file);
                 } else if (file.isDown()) {
                     if (PreviewMediaFragment.canBePreviewed(file)) {
                         // media preview

+ 341 - 0
src/com/owncloud/android/ui/preview/PreviewTextFragment.java

@@ -0,0 +1,341 @@
+package com.owncloud.android.ui.preview;
+
+import android.accounts.Account;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ProgressBar;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.FileMenuFilter;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
+import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
+import com.owncloud.android.ui.fragment.FileFragment;
+
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Scanner;
+
+public class PreviewTextFragment extends FileFragment {
+    private static final String EXTRA_FILE = "FILE";
+    private static final String EXTRA_ACCOUNT = "ACCOUNT";
+    private static final String TAG = PreviewTextFragment.class.getSimpleName();
+
+    private Account mAccount;
+    private TextView mTextPreview;
+    private ProgressBar mProgressBar;
+    private ScrollView mScrollView;
+
+    /**
+     * Creates an empty fragment for previews.
+     * <p/>
+     * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically
+     * (for instance, when the device is turned a aside).
+     * <p/>
+     * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful
+     * construction
+     */
+    public PreviewTextFragment() {
+        super();
+        mAccount = null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        super.onCreateView(inflater, container, savedInstanceState);
+        Log_OC.e(TAG, "onCreateView");
+
+
+        View ret = inflater.inflate(R.layout.text_file_preview, container, false);
+
+        mScrollView = (ScrollView) ret.findViewById(R.id.text_scrollview);
+        mTextPreview = (TextView) ret.findViewById(R.id.text_preview);
+        mProgressBar = (ProgressBar) ret.findViewById(R.id.progress_bar);
+
+        return ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        OCFile file = getFile();
+
+        Bundle args = getArguments();
+
+        if (file == null)
+            file = args.getParcelable(FileDisplayActivity.EXTRA_FILE);
+
+        if (mAccount == null)
+            mAccount = args.getParcelable(FileDisplayActivity.EXTRA_ACCOUNT);
+
+
+        if (savedInstanceState == null) {
+            if (file == null) {
+                throw new IllegalStateException("Instanced with a NULL OCFile");
+            }
+            if (mAccount == null) {
+                throw new IllegalStateException("Instanced with a NULL ownCloud Account");
+            }
+        } else {
+            file = savedInstanceState.getParcelable(EXTRA_FILE);
+            mAccount = savedInstanceState.getParcelable(EXTRA_ACCOUNT);
+        }
+        setFile(file);
+        setHasOptionsMenu(true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile());
+        outState.putParcelable(PreviewImageFragment.EXTRA_ACCOUNT, mAccount);
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        Log_OC.e(TAG, "onStart");
+
+        loadAndShowTextPreview(getFile().getStoragePath(), mTextPreview);
+    }
+
+    private void loadAndShowTextPreview(String location, TextView textView) {
+        new TextLoadAsyncTask().execute(location, textView);
+    }
+
+    /**
+     * Reads the file to preview and shows its contents. Too critical to be anonymous.
+     */
+    private class TextLoadAsyncTask extends AsyncTask<Object, Void, StringWriter> {
+        TextView mTextView;
+
+        @Override
+        protected void onPreExecute() {
+            mProgressBar.setVisibility(View.VISIBLE);
+        }
+
+        @Override
+        protected StringWriter doInBackground(java.lang.Object... params) {
+            if (params.length != 2)
+                throw new IllegalArgumentException("The parameters to " + TextLoadAsyncTask.class.getName() + " must be (1) the file location and (2) the text view to update");
+            final String location = (String) params[0];
+            mTextView = (TextView) params[1];
+
+            FileInputStream inputStream = null;
+            Scanner sc = null;
+            StringWriter source = new StringWriter();
+            BufferedWriter bufferedWriter = new BufferedWriter(source);
+            try {
+                inputStream = new FileInputStream(location);
+                sc = new Scanner(inputStream);
+                while (sc.hasNextLine()) {
+                    bufferedWriter.append(sc.nextLine());
+                    if (sc.hasNextLine()) bufferedWriter.append("\n");
+                }
+                bufferedWriter.close();
+                IOException exc = sc.ioException();
+                if (exc != null) throw exc;
+            } catch (IOException e) {
+                finish();
+            } finally {
+                if (inputStream != null) {
+                    try {
+                        inputStream.close();
+                    } catch (IOException e) {
+                        finish();
+                    }
+                }
+                if (sc != null) {
+                    sc.close();
+                }
+            }
+            return source;
+        }
+
+        @Override
+        protected void onPostExecute(final StringWriter stringWriter) {
+            super.onPostExecute(stringWriter);
+            mProgressBar.setVisibility(View.GONE);
+            mScrollView.setVisibility(View.VISIBLE);
+            mTextView.setText(new String(stringWriter.getBuffer()));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        super.onCreateOptionsMenu(menu, inflater);
+        inflater.inflate(R.menu.file_actions_menu, menu);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onPrepareOptionsMenu(Menu menu) {
+        super.onPrepareOptionsMenu(menu);
+
+        if (mContainerActivity.getStorageManager() != null) {
+            FileMenuFilter mf = new FileMenuFilter(
+                    getFile(),
+                    mContainerActivity.getStorageManager().getAccount(),
+                    mContainerActivity,
+                    getSherlockActivity()
+            );
+            mf.filter(menu);
+        }
+
+        // additional restriction for this fragment
+        MenuItem item = menu.findItem(R.id.action_rename_file);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_move);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+        // this one doesn't make sense since the file has to be down in order to be previewed
+        item = menu.findItem(R.id.action_download_file);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.action_share_file: {
+                mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
+                return true;
+            }
+            case R.id.action_unshare_file: {
+                mContainerActivity.getFileOperationsHelper().unshareFileWithLink(getFile());
+                return true;
+            }
+            case R.id.action_open_file_with: {
+                openFile();
+                return true;
+            }
+            case R.id.action_remove_file: {
+                RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(getFile());
+                dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
+                return true;
+            }
+            case R.id.action_see_details: {
+                seeDetails();
+                return true;
+            }
+            case R.id.action_send_file: {
+                sendFile();
+                return true;
+            }
+            case R.id.action_sync_file: {
+                mContainerActivity.getFileOperationsHelper().syncFile(getFile());
+                return true;
+            }
+
+            default:
+                return false;
+        }
+    }
+
+    /**
+     * Update the file of the fragment with file value
+     *
+     * @param file
+     */
+    public void updateFile(OCFile file) {
+        setFile(file);
+    }
+
+    private void sendFile() {
+        mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
+    }
+
+    private void seeDetails() {
+        mContainerActivity.showDetails(getFile());
+    }
+
+    @Override
+    public void onPause() {
+        Log_OC.e(TAG, "onPause");
+        super.onPause();
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        Log_OC.e(TAG, "onResume");
+    }
+
+    @Override
+    public void onDestroy() {
+        Log_OC.e(TAG, "onDestroy");
+        super.onDestroy();
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        Log_OC.e(TAG, "onStop");
+    }
+
+    /**
+     * Opens the previewed file with an external application.
+     */
+    private void openFile() {
+        mContainerActivity.getFileOperationsHelper().openFile(getFile());
+        finish();
+    }
+
+    /**
+     * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewTextFragment} to be previewed.
+     *
+     * @param file File to test if can be previewed.
+     * @return 'True' if the file can be handled by the fragment.
+     */
+    public static boolean canBePreviewed(OCFile file) {
+        return (file != null && file.isDown() && file.isText());
+    }
+
+    /**
+     * Finishes the preview
+     */
+    private void finish() {
+        getSherlockActivity().onBackPressed();
+    }
+}

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно