X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/73f8797b7572e431037fd5ee55c24237c544dfcb..7d1ea9819ce0e08cf17b3d0aeef0211c8ef304c8:/src/com/owncloud/android/ui/fragment/FileDetailFragment.java diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 8740f834..4be1fbbf 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -1,9 +1,10 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski + * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -20,7 +21,6 @@ package com.owncloud.android.ui.fragment; import java.io.File; import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.UsernamePasswordCredentials; import android.accounts.Account; import android.accounts.AccountManager; @@ -56,7 +56,7 @@ import android.widget.Toast; import com.actionbarsherlock.app.SherlockFragment; import com.owncloud.android.DisplayUtils; -import com.owncloud.android.authenticator.AccountAuthenticator; +import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; @@ -65,7 +65,6 @@ import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.network.BearerCredentials; -import com.owncloud.android.network.OwnCloudClientUtils; import com.owncloud.android.operations.OnRemoteOperationListener; import com.owncloud.android.operations.RemoteOperation; import com.owncloud.android.operations.RemoteOperationResult; @@ -142,10 +141,6 @@ public class FileDetailFragment extends SherlockFragment implements mAccount = ocAccount; mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment mLayout = R.layout.file_details_empty; - - if(fileToDetail != null && ocAccount != null) { - mLayout = R.layout.file_details_fragment; - } } @@ -166,6 +161,10 @@ public class FileDetailFragment extends SherlockFragment implements mAccount = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_ACCOUNT); } + if(mFile != null && mAccount != null) { + mLayout = R.layout.file_details_fragment; + } + View view = null; view = inflater.inflate(mLayout, container, false); mView = view; @@ -410,7 +409,6 @@ public class FileDetailFragment extends SherlockFragment implements true, mStorageManager); mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity()); - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } @@ -446,7 +444,7 @@ public class FileDetailFragment extends SherlockFragment implements * @return True when the fragment was created with the empty layout. */ public boolean isEmpty() { - return mLayout == R.layout.file_details_empty; + return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null); } @@ -492,8 +490,7 @@ public class FileDetailFragment extends SherlockFragment implements // set file details setFilename(mFile.getFileName()); - setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile - .getMimetype())); + setFiletype(mFile.getMimetype()); setFilesize(mFile.getFileLength()); if(ocVersionSupportsTimeCreated()){ setTimeCreated(mFile.getCreationTimestamp()); @@ -545,8 +542,14 @@ public class FileDetailFragment extends SherlockFragment implements */ private void setFiletype(String mimetype) { TextView tv = (TextView) getView().findViewById(R.id.fdType); - if (tv != null) - tv.setText(mimetype); + if (tv != null) { + String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);; + tv.setText(printableMimetype); + } + ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon); + if (iv != null) { + iv.setImageResource(DisplayUtils.getResourceId(mimetype)); + } } /** @@ -721,14 +724,14 @@ public class FileDetailFragment extends SherlockFragment implements if (mFile.getRemotePath().equals(uploadRemotePath) || renamedInUpload) { if (uploadWasFine) { - mFile = mStorageManager.getFileByPath(mFile.getRemotePath()); + mFile = mStorageManager.getFileByPath(uploadRemotePath); } if (renamedInUpload) { String newName = (new File(uploadRemotePath)).getName(); Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG); msg.show(); - getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done } + getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server } } @@ -936,28 +939,14 @@ public class FileDetailFragment extends SherlockFragment implements */ @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { - if (!result.isSuccess() && result.getCode() == ResultCode.UNAUTHORIZED) { - AccountManager am = AccountManager.get(getSherlockActivity()); - //am.invalidateAuthToken(AccountAuthenticator.ACCOUNT_TYPE, OwnCloudClientUtils.getAuthorizationTokenType(operation.getClient().getCredentials())); - Credentials cred = operation.getClient().getCredentials(); - if (cred instanceof BearerCredentials) { - am.invalidateAuthToken(AccountAuthenticator.ACCOUNT_TYPE, ((BearerCredentials)cred).getAccessToken()); - } else { - am.clearPassword(mAccount); - } - operation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity()); // need a new client instance, so avoid retry() - // TODO si el usuario no se autoriza de nuevo, esto genera un bucle infinito; o un error en la creación del objecto cliente - - } else { - if (operation instanceof RemoveFileOperation) { - onRemoveFileOperationFinish((RemoveFileOperation)operation, result); + if (operation instanceof RemoveFileOperation) { + onRemoveFileOperationFinish((RemoveFileOperation)operation, result); - } else if (operation instanceof RenameFileOperation) { - onRenameFileOperationFinish((RenameFileOperation)operation, result); + } else if (operation instanceof RenameFileOperation) { + onRenameFileOperationFinish((RenameFileOperation)operation, result); - } else if (operation instanceof SynchronizeFileOperation) { - onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); - } + } else if (operation instanceof SynchronizeFileOperation) { + onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); } }