X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/3defb175cb59ae3158f92347a8045f198e3208c7..a99f74bd9e09ed9acc74b0fe276ed030b91fc85d:/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 46d8d56e..2d46a55c 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, @@ -50,6 +51,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.Display; @@ -121,6 +123,7 @@ public class FileDetailFragment extends SherlockFragment implements private Handler mHandler; private RemoteOperation mLastRemoteOperation; + private DialogFragment mCurrentDialog; private static final String TAG = FileDetailFragment.class.getSimpleName(); public static final String FTAG = "FileDetails"; @@ -153,10 +156,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; - } } @@ -177,6 +176,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; @@ -191,7 +194,7 @@ public class FileDetailFragment extends SherlockFragment implements mPreview = (ImageView)mView.findViewById(R.id.fdPreview); } - updateFileDetails(); + updateFileDetails(false); return view; } @@ -274,7 +277,6 @@ public class FileDetailFragment extends SherlockFragment implements public void onClick(View v) { switch (v.getId()) { case R.id.fdDownloadBtn: { - //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { @@ -306,7 +308,7 @@ public class FileDetailFragment extends SherlockFragment implements } } else { - mLastRemoteOperation = new SynchronizeFileOperation(mFile, mStorageManager, mAccount, true, false, getActivity()); + mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity()); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); mLastRemoteOperation.execute(wc, this, mHandler); @@ -342,8 +344,7 @@ public class FileDetailFragment extends SherlockFragment implements break; } case R.id.fdRenameBtn: { - EditNameDialog dialog = EditNameDialog.newInstance(mFile.getFileName()); - dialog.setOnDismissListener(this); + EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this); dialog.show(getFragmentManager(), "nameeditdialog"); break; } @@ -355,7 +356,8 @@ public class FileDetailFragment extends SherlockFragment implements mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel); confDialog.setOnConfirmationListener(this); - confDialog.show(getFragmentManager(), FTAG_CONFIRMATION); + mCurrentDialog = confDialog; + mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; } case R.id.fdOpenBtn: { @@ -374,8 +376,13 @@ public class FileDetailFragment extends SherlockFragment implements try { Intent i = new Intent(Intent.ACTION_VIEW); mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); - if (mimeType != null && !mimeType.equals(mFile.getMimetype())) { - i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType); + if (mimeType == null || !mimeType.equals(mFile.getMimetype())) { + if (mimeType != null) { + i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType); + } else { + // desperate try + i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*"); + } i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); toastIt = false; @@ -424,6 +431,8 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } } + mCurrentDialog.dismiss(); + mCurrentDialog = null; } @Override @@ -435,11 +444,15 @@ public class FileDetailFragment extends SherlockFragment implements mStorageManager.saveFile(mFile); updateFileDetails(mFile, mAccount); } + mCurrentDialog.dismiss(); + mCurrentDialog = null; } @Override public void onCancel(String callerTag) { Log.d(TAG, "REMOVAL CANCELED"); + mCurrentDialog.dismiss(); + mCurrentDialog = null; } @@ -449,7 +462,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); } @@ -475,21 +488,27 @@ public class FileDetailFragment extends SherlockFragment implements mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver()); } mAccount = ocAccount; - updateFileDetails(); + updateFileDetails(false); } /** * Updates the view with all relevant details about that file. + * + * TODO Remove parameter when the transferring state of files is kept in database. + * + * @param transferring Flag signaling if the file should be considered as downloading or uploading, + * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and + * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false. + * */ - public void updateFileDetails() { + public void updateFileDetails(boolean transferring) { if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) { // set file details setFilename(mFile.getFileName()); - setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile - .getMimetype())); + setFiletype(mFile.getMimetype()); setFilesize(mFile.getFileLength()); if(ocVersionSupportsTimeCreated()){ setTimeCreated(mFile.getCreationTimestamp()); @@ -504,7 +523,7 @@ public class FileDetailFragment extends SherlockFragment implements //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); - if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) { + if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) { setButtonsForTransferring(); } else if (mFile.isDown()) { @@ -517,9 +536,11 @@ public class FileDetailFragment extends SherlockFragment implements setButtonsForDown(); } else { + // TODO load default preview image; when the local file is removed, the preview remains there setButtonsForRemote(); } } + getView().invalidate(); } @@ -539,8 +560,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)); + } } /** @@ -602,7 +629,6 @@ public class FileDetailFragment extends SherlockFragment implements if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); downloadButton.setText(R.string.filedetails_sync_file); - //downloadButton.setEnabled(true); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); @@ -687,7 +713,7 @@ public class FileDetailFragment extends SherlockFragment implements if (downloadWasFine) { mFile = mStorageManager.getFileByPath(downloadedRemotePath); } - updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine + updateFileDetails(false); // it updates the buttons; must be called although !downloadWasFine } } } @@ -712,12 +738,19 @@ public class FileDetailFragment extends SherlockFragment implements if (!isEmpty() && accountName.equals(mAccount.name)) { boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false); String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH); - if (mFile.getRemotePath().equals(uploadRemotePath)) { + boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH)); + if (mFile.getRemotePath().equals(uploadRemotePath) || + renamedInUpload) { if (uploadWasFine) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); - mFile = fdsm.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(); } - updateFileDetails(); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server + 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 } } } @@ -833,6 +866,7 @@ public class FileDetailFragment extends SherlockFragment implements String newFilename = dialog.getNewFilename(); Log.d(TAG, "name edit dialog dismissed with new name " + newFilename); mLastRemoteOperation = new RenameFileOperation( mFile, + mAccount, newFilename, new FileDataStorageManager(mAccount, getActivity().getContentResolver())); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); @@ -992,10 +1026,8 @@ public class FileDetailFragment extends SherlockFragment implements if (!result.isSuccess()) { if (result.getCode() == ResultCode.SYNC_CONFLICT) { Intent i = new Intent(getActivity(), ConflictsResolveActivity.class); - //i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); - i.putExtra("remotepath", mFile.getRemotePath()); - i.putExtra("localpath", mFile.getStoragePath()); - i.putExtra("account", mAccount); + i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile); + i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount); startActivity(i); } else { @@ -1003,6 +1035,13 @@ public class FileDetailFragment extends SherlockFragment implements msg.show(); } + if (mFile.isDown()) { + setButtonsForDown(); + + } else { + setButtonsForRemote(); + } + } else { if (operation.transferWasRequested()) { mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so