Pin code
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / FileDetailFragment.java
index f667204..8abf569 100644 (file)
  */\r
 package eu.alefzero.owncloud.ui.fragment;\r
 \r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.commons.httpclient.HostConfiguration;\r
+import org.apache.commons.httpclient.HttpException;\r
+import org.apache.commons.httpclient.cookie.CookiePolicy;\r
+import org.apache.commons.httpclient.methods.GetMethod;\r
+import org.apache.commons.httpclient.methods.PostMethod;\r
+import org.apache.commons.httpclient.methods.StringRequestEntity;\r
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;\r
+import org.apache.commons.httpclient.params.HttpMethodParams;\r
+import org.apache.http.HttpStatus;\r
+import org.apache.http.NameValuePair;\r
+import org.apache.http.client.utils.URLEncodedUtils;\r
+import org.apache.http.message.BasicNameValuePair;\r
+import org.apache.http.protocol.HTTP;\r
+import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;\r
+import org.json.JSONException;\r
+import org.json.JSONObject;\r
+\r
 import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
+import android.content.ActivityNotFoundException;\r
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
 import android.content.Intent;\r
 import android.content.IntentFilter;\r
-import android.database.Cursor;\r
 import android.graphics.Bitmap;\r
 import android.graphics.BitmapFactory;\r
+import android.graphics.BitmapFactory.Options;\r
+import android.graphics.Point;\r
+import android.graphics.drawable.BitmapDrawable;\r
+import android.graphics.drawable.Drawable;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
+import android.preference.PreferenceActivity.Header;\r
+import android.util.Log;\r
+import android.view.Display;\r
 import android.view.LayoutInflater;\r
 import android.view.View;\r
 import android.view.View.OnClickListener;\r
 import android.view.ViewGroup;\r
+import android.webkit.MimeTypeMap;\r
+import android.widget.Button;\r
+import android.widget.CheckBox;\r
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
-import android.widget.VideoView;\r
 \r
 import com.actionbarsherlock.app.SherlockFragment;\r
 \r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.DisplayUtils;\r
-import eu.alefzero.owncloud.FileDownloader;\r
 import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
+import eu.alefzero.owncloud.datamodel.OCFile;\r
+import eu.alefzero.owncloud.files.services.FileDownloader;\r
+import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
+import eu.alefzero.webdav.WebdavClient;\r
 \r
 /**\r
  * This Fragment is used to display the details about a file.\r
+ * \r
  * @author Bartek Przybylski\r
- *\r
+ * \r
  */\r
-public class FileDetailFragment extends SherlockFragment implements OnClickListener {\r
-  \r
-  private Intent mIntent;\r
-  private View mView;\r
-  private DownloadFinishReceiver dfr;\r
-  \r
-  @Override\r
-  public void onResume() {\r
-    super.onResume();\r
-    dfr = new DownloadFinishReceiver();\r
-    IntentFilter filter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
-    getActivity().registerReceiver(dfr, filter);\r
-  }\r
-  \r
-  @Override\r
-  public void onPause() {\r
-    super.onPause();\r
-    getActivity().unregisterReceiver(dfr);\r
-    dfr = null;\r
-  }\r
-  \r
-  public void setStuff(Intent intent) {\r
-    mIntent = intent;\r
-    setStuff(getView());\r
-  }\r
-  \r
-  private void setStuff(View view) {\r
-    mView = view;\r
-    String id = mIntent.getStringExtra("FILE_ID");\r
-    Account account = mIntent.getParcelableExtra("ACCOUNT");\r
-    String account_name = account.name;\r
-    Cursor c = getActivity().managedQuery(\r
-        Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, id),\r
-        null,\r
-        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",\r
-        new String[]{account_name},\r
-        null);\r
-    c.moveToFirst();\r
-\r
-    // Retrieve details from DB\r
-    String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));\r
-    String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));\r
-    String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));\r
-    long filesize = c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));\r
-\r
-    // set file details\r
-    setFilename(filename);\r
-    setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mimetype));\r
-    setFilesize(filesize);\r
-    \r
-    // set file preview if available and possible\r
-    View w = view.findViewById(R.id.videoView1);\r
-    w.setVisibility(View.INVISIBLE);\r
-    if (path == null) {\r
-      ImageView v = (ImageView) getView().findViewById(R.id.imageView2);\r
-      v.setImageResource(R.drawable.download);\r
-      v.setOnClickListener(this);\r
-    } else {\r
-      if (mimetype.startsWith("image/")) {\r
-        ImageView v = (ImageView) view.findViewById(R.id.imageView2);\r
-        Bitmap bmp = BitmapFactory.decodeFile(path);\r
-        v.setImageBitmap(bmp);\r
-      } else if (mimetype.startsWith("video/")) {\r
-        VideoView v = (VideoView) view.findViewById(R.id.videoView1);\r
-        v.setVisibility(View.VISIBLE);\r
-        v.setVideoPath(path);\r
-        v.start();\r
-      }\r
-    }\r
-  }\r
-\r
-  @Override\r
-  public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
-      Bundle savedInstanceState) {\r
-    View v = null;\r
-    \r
-    if (getActivity().getIntent() != null && getActivity().getIntent().getStringExtra("FILE_ID") != null) {\r
-       v = inflater.inflate(R.layout.file_details_fragment, container, false);\r
-       mIntent = getActivity().getIntent();\r
-       setStuff(v);\r
-    } else {\r
-       v = inflater.inflate(R.layout.file_details_empty, container, false);\r
-    }\r
-    return v;\r
-  }\r
-\r
-  @Override\r
-  public View getView() {\r
-    return mView == null ? super.getView() : mView;\r
-  };\r
-  \r
-  public void setFilename(String filename) {\r
-    TextView tv = (TextView) getView().findViewById(R.id.textView1);\r
-    if (tv != null) tv.setText(filename);\r
-  }\r
-  \r
-  public void setFiletype(String mimetype) {\r
-    TextView tv = (TextView) getView().findViewById(R.id.textView2);\r
-    if (tv != null) tv.setText(mimetype);\r
-  }\r
-  \r
-  public void setFilesize(long filesize) {\r
-    TextView tv = (TextView) getView().findViewById(R.id.textView3);\r
-    if (tv != null) tv.setText(DisplayUtils.bitsToHumanReadable(filesize));\r
-  }\r
-\r
-  @Override\r
-  public void onClick(View v) {\r
-    Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();\r
-    Intent i = new Intent(getActivity(), FileDownloader.class);\r
-    i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra("ACCOUNT"));\r
-    i.putExtra(FileDownloader.EXTRA_FILE_PATH, mIntent.getStringExtra("FULL_PATH"));\r
-    getActivity().startService(i);\r
-  }\r
-  \r
-  private class DownloadFinishReceiver extends BroadcastReceiver {\r
+public class FileDetailFragment extends SherlockFragment implements\r
+        OnClickListener {\r
+\r
+    public static final String EXTRA_FILE = "FILE";\r
+    public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
+\r
+    private int mLayout;\r
+    private View mView;\r
+    private OCFile mFile;\r
+    private Account mAccount;\r
+    \r
+    private DownloadFinishReceiver mDownloadFinishReceiver;\r
+\r
+    private static final String TAG = "FileDetailFragment";\r
+    public static final String FTAG = "FileDetails"; \r
+\r
+    \r
+    /**\r
+     * Creates an empty details fragment.\r
+     * \r
+     * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically. \r
+     */\r
+    public FileDetailFragment() {\r
+        mFile = null;\r
+        mAccount = null;\r
+        mLayout = R.layout.file_details_empty;\r
+    }\r
+    \r
+    \r
+    /**\r
+     * Creates a details fragment.\r
+     * \r
+     * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before).\r
+     * \r
+     * @param fileToDetail      An {@link OCFile} to show in the fragment\r
+     * @param ocAccount         An ownCloud account; needed to start downloads\r
+     */\r
+    public FileDetailFragment(OCFile fileToDetail, Account ocAccount){\r
+        mFile = fileToDetail;\r
+        mAccount = ocAccount;\r
+        mLayout = R.layout.file_details_empty;\r
+        \r
+        if(fileToDetail != null && ocAccount != null) {\r
+            mLayout = R.layout.file_details_fragment;\r
+        }\r
+    }\r
+    \r
+    \r
     @Override\r
-    public void onReceive(Context context, Intent intent) {\r
-      setStuff(getView());\r
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
+            Bundle savedInstanceState) {\r
+        super.onCreateView(inflater, container, savedInstanceState);\r
+        \r
+        if (savedInstanceState != null) {\r
+            mFile = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);\r
+            mAccount = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_ACCOUNT);\r
+        }\r
+        \r
+        View view = null;\r
+        view = inflater.inflate(mLayout, container, false);\r
+        mView = view;\r
+        \r
+        updateFileDetails();\r
+        return view;\r
+    }\r
+    \r
+\r
+    @Override\r
+    public void onSaveInstanceState(Bundle outState) {\r
+        Log.i(getClass().toString(), "onSaveInstanceState() start");\r
+        super.onSaveInstanceState(outState);\r
+        outState.putParcelable(FileDetailFragment.EXTRA_FILE, mFile);\r
+        outState.putParcelable(FileDetailFragment.EXTRA_ACCOUNT, mAccount);\r
+        Log.i(getClass().toString(), "onSaveInstanceState() end");\r
+    }\r
+\r
+    \r
+    @Override\r
+    public void onResume() {\r
+        super.onResume();\r
+        mDownloadFinishReceiver = new DownloadFinishReceiver();\r
+        IntentFilter filter = new IntentFilter(\r
+                FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
+        getActivity().registerReceiver(mDownloadFinishReceiver, filter);\r
+    }\r
+\r
+    @Override\r
+    public void onPause() {\r
+        super.onPause();\r
+        getActivity().unregisterReceiver(mDownloadFinishReceiver);\r
+        mDownloadFinishReceiver = null;\r
+    }\r
+\r
+    @Override\r
+    public View getView() {\r
+        return super.getView() == null ? mView : super.getView();\r
+    }\r
+\r
+    @Override\r
+    public void onClick(View v) {\r
+        if (v.getId() == R.id.fdDownloadBtn) {\r
+            Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();\r
+            Intent i = new Intent(getActivity(), FileDownloader.class);\r
+            i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
+            i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());\r
+            i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath());\r
+            i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
+            v.setEnabled(false);\r
+            getActivity().startService(i);\r
+        } else if (v.getId() == R.id.fdKeepInSync) {\r
+            CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);\r
+            mFile.setKeepInSync(cb.isChecked());\r
+            FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());\r
+            fdsm.saveFile(mFile);\r
+            if (mFile.keepInSync() && !mFile.isDownloaded()) {\r
+                onClick(getView().findViewById(R.id.fdDownloadBtn));\r
+            }\r
+        }/* else if (v.getId() == R.id.fdShareBtn) {\r
+            Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));\r
+            t.start();\r
+        }*/\r
+    }\r
+\r
+\r
+    /**\r
+     * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.\r
+     * \r
+     * @return  True when the fragment was created with the empty layout.\r
+     */\r
+    public boolean isEmpty() {\r
+        return mLayout == R.layout.file_details_empty;\r
+    }\r
+\r
+    \r
+    /**\r
+     * Can be used to get the file that is currently being displayed.\r
+     * @return The file on the screen.\r
+     */\r
+    public OCFile getDisplayedFile(){\r
+        return mFile;\r
+    }\r
+    \r
+    /**\r
+     * Use this method to signal this Activity that it shall update its view.\r
+     * \r
+     * @param file : An {@link OCFile}\r
+     */\r
+    public void updateFileDetails(OCFile file, Account ocAccount) {\r
+        mFile = file;\r
+        mAccount = ocAccount;\r
+        updateFileDetails();\r
+    }\r
+    \r
+\r
+    /**\r
+     * Updates the view with all relevant details about that file.\r
+     */\r
+    public void updateFileDetails() {\r
+\r
+        if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
+            \r
+            Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
+            // set file details\r
+            setFilename(mFile.getFileName());\r
+            setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile\r
+                    .getMimetype()));\r
+            setFilesize(mFile.getFileLength());\r
+            if(ocVersionSupportsTimeCreated()){\r
+                setTimeCreated(mFile.getCreationTimestamp());\r
+            }\r
+           \r
+            setTimeModified(mFile.getModificationTimestamp());\r
+            \r
+            CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);\r
+            cb.setChecked(mFile.keepInSync());\r
+            cb.setOnClickListener(this);\r
+            //getView().findViewById(R.id.fdShareBtn).setOnClickListener(this);\r
+            \r
+            if (mFile.getStoragePath() != null) {\r
+                // Update preview\r
+                ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
+                try {\r
+                    if (mFile.getMimetype().startsWith("image/")) {\r
+                        BitmapFactory.Options options = new Options();\r
+                        options.inScaled = true;\r
+                        options.inPurgeable = true;\r
+                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {\r
+                            options.inPreferQualityOverSpeed = false;\r
+                        }\r
+                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {\r
+                            options.inMutable = false;\r
+                        }\r
+\r
+                        Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+\r
+                        if (bmp != null) {\r
+                            int width = options.outWidth;\r
+                            int height = options.outHeight;\r
+                            int scale = 1;\r
+                            boolean recycle = false;\r
+                            if (width >= 2048 || height >= 2048) {\r
+                                scale = (int) (Math.ceil(Math.max(height, width)/2048.));\r
+                                options.inSampleSize = scale;\r
+                                recycle = true;\r
+                            }\r
+                                Display display = getActivity().getWindowManager().getDefaultDisplay();\r
+                                Point size = new Point();\r
+                                int screenwidth;\r
+                                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {\r
+                                    display.getSize(size);\r
+                                    screenwidth = size.x;\r
+                                } else {\r
+                                    screenwidth = display.getWidth();\r
+                                }\r
+\r
+                                Log.e("ASD", "W " + width + " SW " + screenwidth);\r
+\r
+                                if (width > screenwidth) {\r
+                                    scale = (int) (Math.ceil(Math.max(height, width)/screenwidth));\r
+                                    options.inSampleSize = scale;\r
+                                    recycle = true;\r
+                                }\r
+                            \r
+\r
+                            if (recycle) bmp.recycle();\r
+                            bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+                            \r
+                        }\r
+                        if (bmp != null) {\r
+                            preview.setImageBitmap(bmp);\r
+                        }\r
+                    }\r
+                } catch (OutOfMemoryError e) {\r
+                    preview.setVisibility(View.INVISIBLE);\r
+                    Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength());\r
+                    \r
+                } catch (NoSuchFieldError e) {\r
+                    preview.setVisibility(View.INVISIBLE);\r
+                    Log.e(TAG, "Error from access to unexisting field despite protection " + mFile.getFileLength());\r
+                    \r
+                } catch (Throwable t) {\r
+                    preview.setVisibility(View.INVISIBLE);\r
+                    Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t);\r
+                }\r
+                \r
+                // Change download button to open button\r
+                downloadButton.setText(R.string.filedetails_open);\r
+                downloadButton.setOnClickListener(new OnClickListener() {\r
+                    @Override\r
+                    public void onClick(View v) {\r
+                        String storagePath = mFile.getStoragePath();\r
+                        try {\r
+                            Intent i = new Intent(Intent.ACTION_VIEW);\r
+                            i.setDataAndType(Uri.parse("file://"+ storagePath), mFile.getMimetype());\r
+                            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
+                            startActivity(i);\r
+                            \r
+                        } catch (Throwable t) {\r
+                            Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());\r
+                            boolean toastIt = true; \r
+                            String mimeType = "";\r
+                            try {\r
+                                Intent i = new Intent(Intent.ACTION_VIEW);\r
+                                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));\r
+                                if (mimeType != null && !mimeType.equals(mFile.getMimetype())) {\r
+                                    i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType);\r
+                                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
+                                    startActivity(i);\r
+                                    toastIt = false;\r
+                                }\r
+                                \r
+                            } catch (IndexOutOfBoundsException e) {\r
+                                Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);\r
+                                \r
+                            } catch (ActivityNotFoundException e) {\r
+                                Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");\r
+                                \r
+                            } catch (Throwable th) {\r
+                                Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);\r
+                                \r
+                            } finally {\r
+                                if (toastIt) {\r
+                                    Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();\r
+                                }\r
+                            }\r
+                            \r
+                        }\r
+                    }\r
+                });\r
+            } else {\r
+                // Make download button effective\r
+                downloadButton.setOnClickListener(this);\r
+            }\r
+        }\r
+    }\r
+    \r
+    \r
+    /**\r
+     * Updates the filename in view\r
+     * @param filename to set\r
+     */\r
+    private void setFilename(String filename) {\r
+        TextView tv = (TextView) getView().findViewById(R.id.fdFilename);\r
+        if (tv != null)\r
+            tv.setText(filename);\r
+    }\r
+\r
+    /**\r
+     * Updates the MIME type in view\r
+     * @param mimetype to set\r
+     */\r
+    private void setFiletype(String mimetype) {\r
+        TextView tv = (TextView) getView().findViewById(R.id.fdType);\r
+        if (tv != null)\r
+            tv.setText(mimetype);\r
+    }\r
+\r
+    /**\r
+     * Updates the file size in view\r
+     * @param filesize in bytes to set\r
+     */\r
+    private void setFilesize(long filesize) {\r
+        TextView tv = (TextView) getView().findViewById(R.id.fdSize);\r
+        if (tv != null)\r
+            tv.setText(DisplayUtils.bytesToHumanReadable(filesize));\r
+    }\r
+    \r
+    /**\r
+     * Updates the time that the file was created in view\r
+     * @param milliseconds Unix time to set\r
+     */\r
+    private void setTimeCreated(long milliseconds){\r
+        TextView tv = (TextView) getView().findViewById(R.id.fdCreated);\r
+        TextView tvLabel = (TextView) getView().findViewById(R.id.fdCreatedLabel);\r
+        if(tv != null){\r
+            tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));\r
+            tv.setVisibility(View.VISIBLE);\r
+            tvLabel.setVisibility(View.VISIBLE);\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * Updates the time that the file was last modified\r
+     * @param milliseconds Unix time to set\r
+     */\r
+    private void setTimeModified(long milliseconds){\r
+        TextView tv = (TextView) getView().findViewById(R.id.fdModified);\r
+        if(tv != null){\r
+            tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return\r
+     * the time that the file was created. There is a chance that this will\r
+     * be fixed in future versions. Use this method to check if this version of\r
+     * ownCloud has this fix.\r
+     * @return True, if ownCloud the ownCloud version is supporting creation time\r
+     */\r
+    private boolean ocVersionSupportsTimeCreated(){\r
+        /*if(mAccount != null){\r
+            AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);\r
+            OwnCloudVersion ocVersion = new OwnCloudVersion(accManager\r
+                    .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));\r
+            if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) {\r
+                return true;\r
+            }\r
+        }*/\r
+        return false;\r
+    }\r
+\r
+    /**\r
+     * Once the file download has finished -> update view\r
+     * @author Bartek Przybylski\r
+     */\r
+    private class DownloadFinishReceiver extends BroadcastReceiver {\r
+        @Override\r
+        public void onReceive(Context context, Intent intent) {\r
+            getView().findViewById(R.id.fdDownloadBtn).setEnabled(true);\r
+            if (intent.getAction().equals(FileDownloader.BAD_DOWNLOAD_MESSAGE)) {\r
+                Toast.makeText(context, R.string.downloader_download_failed , Toast.LENGTH_SHORT).show();\r
+                \r
+            } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {\r
+                mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));\r
+                updateFileDetails();\r
+            }\r
+        }\r
+        \r
+    }\r
+    \r
+    // this is a temporary class for sharing purposes, it need to be replacead in transfer service\r
+    private class ShareRunnable implements Runnable {\r
+        private String mPath;\r
+\r
+        public ShareRunnable(String path) {\r
+            mPath = path;\r
+        }\r
+        \r
+        public void run() {\r
+            AccountManager am = AccountManager.get(getActivity());\r
+            Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());\r
+            OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));\r
+            String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);\r
+\r
+            Log.d("share", "sharing for version " + ocv.toString());\r
+\r
+            if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {\r
+                String APPS_PATH = "/apps/files_sharing/";\r
+                String SHARE_PATH = "ajax/share.php";\r
+\r
+                String SHARED_PATH = "/apps/files_sharing/get.php?token=";\r
+                \r
+                final String WEBDAV_SCRIPT = "webdav.php";\r
+                final String WEBDAV_FILES_LOCATION = "/files/";\r
+                \r
+                WebdavClient wc = new WebdavClient();\r
+                HttpConnectionManagerParams params = new HttpConnectionManagerParams();\r
+                params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);\r
+\r
+                //wc.getParams().setParameter("http.protocol.single-cookie-header", true);\r
+                //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);\r
+\r
+                PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);\r
+\r
+                post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );\r
+                post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));\r
+                List<NameValuePair> formparams = new ArrayList<NameValuePair>();\r
+                Log.d("share", mPath+"");\r
+                formparams.add(new BasicNameValuePair("sources",mPath));\r
+                formparams.add(new BasicNameValuePair("uid_shared_with", "public"));\r
+                formparams.add(new BasicNameValuePair("permissions", "0"));\r
+                post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));\r
+\r
+                int status;\r
+                try {\r
+                    PropFindMethod find = new PropFindMethod(url+"/");\r
+                    find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));\r
+                    Log.d("sharer", ""+ url+"/");\r
+                    wc.setCredentials(account.name.substring(0, account.name.lastIndexOf('@')), am.getPassword(account));\r
+                    \r
+                    for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {\r
+                        Log.d("sharer-h", a.getName() + ":"+a.getValue());\r
+                    }\r
+                    \r
+                    int status2 = wc.executeMethod(find);\r
+\r
+                    Log.d("sharer", "propstatus "+status2);\r
+                    \r
+                    GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");\r
+                    get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));\r
+                    \r
+                    status2 = wc.executeMethod(get);\r
+\r
+                    Log.d("sharer", "getstatus "+status2);\r
+                    Log.d("sharer", "" + get.getResponseBodyAsString());\r
+                    \r
+                    for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {\r
+                        Log.d("sharer", a.getName() + ":"+a.getValue());\r
+                    }\r
+\r
+                    status = wc.executeMethod(post);\r
+                    for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {\r
+                        Log.d("sharer-h", a.getName() + ":"+a.getValue());\r
+                    }\r
+                    for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {\r
+                        Log.d("sharer", a.getName() + ":"+a.getValue());\r
+                    }\r
+                    String resp = post.getResponseBodyAsString();\r
+                    Log.d("share", ""+post.getURI().toString());\r
+                    Log.d("share", "returned status " + status);\r
+                    Log.d("share", " " +resp);\r
+                    \r
+                    if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {\r
+                        return;\r
+                     }\r
+\r
+                    JSONObject jsonObject = new JSONObject (resp);\r
+                    String jsonStatus = jsonObject.getString("status");\r
+                    if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");\r
+                    \r
+                    String token = jsonObject.getString("data");\r
+                    String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token; \r
+                    Log.d("Actions:shareFile ok", "url: " + uri);   \r
+                    \r
+                } catch (HttpException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                } catch (IOException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                } catch (JSONException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                } catch (Exception e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                }\r
+                \r
+            } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {\r
+                \r
+            }\r
+        }\r
     }\r
     \r
-  }\r
-  \r
 }\r