*/\r
package eu.alefzero.owncloud.ui.fragment;\r
\r
+import java.util.List;\r
+\r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
import android.content.BroadcastReceiver;\r
import android.content.Context;\r
import android.content.Intent;\r
import android.content.IntentFilter;\r
+import android.content.pm.PackageManager;\r
import android.graphics.Bitmap;\r
import android.graphics.BitmapFactory;\r
import android.net.Uri;\r
import com.actionbarsherlock.app.SherlockFragment;\r
\r
import eu.alefzero.owncloud.DisplayUtils;\r
-import eu.alefzero.owncloud.FileDownloader;\r
import eu.alefzero.owncloud.R;\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
+import eu.alefzero.owncloud.files.services.FileDownloader;\r
+import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
\r
/**\r
* This Fragment is used to display the details about a file.\r
Intent i = new Intent(getActivity(), FileDownloader.class);\r
i.putExtra(FileDownloader.EXTRA_ACCOUNT,\r
mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT));\r
- i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getPath());\r
+ i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());\r
+ i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
getActivity().startService(i);\r
}\r
\r
setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile\r
.getMimetype()));\r
setFilesize(mFile.getFileLength());\r
- setTimeCreated(mFile.getCreationTimestamp());\r
+ if(ocVersionSupportsTimeCreated()){\r
+ setTimeCreated(mFile.getCreationTimestamp());\r
+ }\r
+ \r
setTimeModified(mFile.getModificationTimestamp());\r
\r
// Update preview\r
public void onClick(View v) {\r
Intent i = new Intent(Intent.ACTION_VIEW);\r
i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype());\r
- startActivity(i);\r
+ List list = getActivity().getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY);\r
+ if (list.size() > 0) {\r
+ startActivity(i);\r
+ } else {\r
+ Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();\r
+ }\r
}\r
});\r
} else {\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
tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));\r
}\r
}\r
+ \r
+ /**\r
+ * In ownCloud 3.0.3 and 4.0.0 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 > 3.0.4 and 4.0.1\r
+ */\r
+ private boolean ocVersionSupportsTimeCreated(){\r
+ if(mIntent != null){\r
+ Account ocAccount = mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT);\r
+ if(ocAccount != null){\r
+ AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);\r
+ OwnCloudVersion ocVersion = new OwnCloudVersion(accManager\r
+ .getUserData(ocAccount, AccountAuthenticator.KEY_OC_VERSION));\r
+ if(ocVersion.compareTo(new OwnCloudVersion(0x030004)) >= 0 || ocVersion.compareTo(new OwnCloudVersion(0x040001)) >= 0){\r
+ return true;\r
+ }\r
+ }\r
+ }\r
+ return false;\r
+ }\r
\r
/**\r
* Once the file download has finished -> update view\r
private class DownloadFinishReceiver extends BroadcastReceiver {\r
@Override\r
public void onReceive(Context context, Intent intent) {\r
- updateFileDetails();\r
+ ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));\r
+ updateFileDetails(mIntent);\r
}\r
-\r
+ \r
}\r
\r
}\r