public void onDismiss(EditNameFragment dialog) { if (dialog instanceof EditNameFragment) { if (((EditNameFragment) dialog).getResult()) { String newFilename = ((EditNameFragment) dialog).getNewFilename(); Log.d(TAG, "name edit dialog dismissed with new name " + newFilename); if (!newFilename.equals(mFile.getFileName())) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); if (fdsm.getFileById(mFile.getFileId()) != null) { OCFile newFile = new OCFile(fdsm.getFileById(mFile.getParentId()).getRemotePath() + newFilename); newFile.setCreationTimestamp(mFile.getCreationTimestamp()); newFile.setFileId(mFile.getFileId()); newFile.setFileLength(mFile.getFileLength()); newFile.setKeepInSync(mFile.keepInSync()); newFile.setLastSyncDate(mFile.getLastSyncDate()); newFile.setMimetype(mFile.getMimetype()); newFile.setModificationTimestamp(mFile.getModificationTimestamp()); newFile.setParentId(mFile.getParentId()); boolean localRenameFails = false; if (mFile.isDown()) { File f = new File(mFile.getStoragePath()); Log.e(TAG, f.getAbsolutePath()); localRenameFails = !(f.renameTo(new File(f.getParent() + File.separator + newFilename))); Log.e(TAG, f.getParent() + File.separator + newFilename); newFile.setStoragePath(f.getParent() + File.separator + newFilename); } if (localRenameFails) { Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); msg.show(); } else { new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start(); boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity() .showDialog( (inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } } } } } else { Log.e( TAG, "Unknown dialog instance passed to onDismissDalog: " + dialog.getClass().getCanonicalName()); } }
/** * Updates the view with all relevant details about that file. * * <p>TODO Remove parameter when the transferring state of files is kept in database. * * <p>TODO REFACTORING! this method called 5 times before every time the fragment is shown! * * @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. * @param refresh If 'true', try to refresh the hold file from the database */ public void updateFileDetails(boolean transferring, boolean refresh) { if (readyToShow()) { if (refresh && mStorageManager != null) { mFile = mStorageManager.getFileByPath(mFile.getRemotePath()); } // set file details setFilename(mFile.getFileName()); setFiletype(mFile.getMimetype()); setFilesize(mFile.getFileLength()); if (ocVersionSupportsTimeCreated()) { setTimeCreated(mFile.getCreationTimestamp()); } setTimeModified(mFile.getModificationTimestamp()); CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); cb.setChecked(mFile.keepInSync()); // configure UI for depending upon local state of the file // if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || // FileUploader.isUploading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) { setButtonsForTransferring(); } else if (mFile.isDown()) { setButtonsForDown(); } else { // TODO load default preview image; when the local file is removed, the preview remains // there setButtonsForRemote(); } } getView().invalidate(); }
/** Updates the view with all relevant details about that file. */ public void updateFileDetails() { if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) { // set file details setFilename(mFile.getFileName()); setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile.getMimetype())); setFilesize(mFile.getFileLength()); if (ocVersionSupportsTimeCreated()) { setTimeCreated(mFile.getCreationTimestamp()); } setTimeModified(mFile.getModificationTimestamp()); CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); cb.setChecked(mFile.keepInSync()); // configure UI for depending upon local state of the file // 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))) { setButtonsForTransferring(); } else if (mFile.isDown()) { // Update preview if (mFile.getMimetype().startsWith("image/")) { BitmapLoader bl = new BitmapLoader(); bl.execute(new String[] {mFile.getStoragePath()}); } setButtonsForDown(); } else { setButtonsForRemote(); } } }