X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/e8c9e5b09a18d1fa8a764046b7da1402fada46f1..fd1704c49cfabc9607bc67d35b6f36afca0591ff:/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 45ec0a9a..932fa513 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -17,10 +17,15 @@ */ package eu.alefzero.owncloud.ui.fragment; +import java.util.List; + +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; @@ -38,9 +43,11 @@ import android.widget.Toast; import com.actionbarsherlock.app.SherlockFragment; import eu.alefzero.owncloud.DisplayUtils; -import eu.alefzero.owncloud.FileDownloader; import eu.alefzero.owncloud.R; +import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.datamodel.OCFile; +import eu.alefzero.owncloud.files.services.FileDownloader; +import eu.alefzero.owncloud.utils.OwnCloudVersion; /** * This Fragment is used to display the details about a file. @@ -137,7 +144,8 @@ public class FileDetailFragment extends SherlockFragment implements Intent i = new Intent(getActivity(), FileDownloader.class); i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT)); - i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getPath()); + i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); getActivity().startService(i); } @@ -178,7 +186,10 @@ public class FileDetailFragment extends SherlockFragment implements setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile .getMimetype())); setFilesize(mFile.getFileLength()); - setTimeCreated(mFile.getCreationTimestamp()); + if(ocVersionSupportsTimeCreated()){ + setTimeCreated(mFile.getCreationTimestamp()); + } + setTimeModified(mFile.getModificationTimestamp()); // Update preview @@ -199,7 +210,12 @@ public class FileDetailFragment extends SherlockFragment implements public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype()); - startActivity(i); + List list = getActivity().getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); + if (list.size() > 0) { + startActivity(i); + } else { + Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show(); + } } }); } else { @@ -245,8 +261,11 @@ public class FileDetailFragment extends SherlockFragment implements */ private void setTimeCreated(long milliseconds){ TextView tv = (TextView) getView().findViewById(R.id.fdCreated); + TextView tvLabel = (TextView) getView().findViewById(R.id.fdCreatedLabel); if(tv != null){ tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds)); + tv.setVisibility(View.VISIBLE); + tvLabel.setVisibility(View.VISIBLE); } } @@ -260,6 +279,28 @@ public class FileDetailFragment extends SherlockFragment implements tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds)); } } + + /** + * In ownCloud 3.0.3 and 4.0.0 there is a bug that SabreDAV does not return + * the time that the file was created. There is a chance that this will + * be fixed in future versions. Use this method to check if this version of + * ownCloud has this fix. + * @return True, if ownCloud the ownCloud version is > 3.0.4 and 4.0.1 + */ + private boolean ocVersionSupportsTimeCreated(){ + if(mIntent != null){ + Account ocAccount = mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT); + if(ocAccount != null){ + AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); + OwnCloudVersion ocVersion = new OwnCloudVersion(accManager + .getUserData(ocAccount, AccountAuthenticator.KEY_OC_VERSION)); + if(ocVersion.compareTo(new OwnCloudVersion(0x030004)) >= 0 || ocVersion.compareTo(new OwnCloudVersion(0x040001)) >= 0){ + return true; + } + } + } + return false; + } /** * Once the file download has finished -> update view @@ -268,9 +309,10 @@ public class FileDetailFragment extends SherlockFragment implements private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - updateFileDetails(); + ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); + updateFileDetails(mIntent); } - + } }