public static EditNameFragment newInstance(String filename) { EditNameFragment f = new EditNameFragment(); Bundle args = new Bundle(); args.putString("filename", filename); f.setArguments(args); return f; }
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()); } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.fdDownloadBtn: { Intent i = new Intent(getActivity(), FileDownloader.class); i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount); i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath()); i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath()); i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); // update ui setButtonsForTransferring(); getActivity().startService(i); mContainerActivity .onFileStateChanged(); // this is not working; it is performed before the // fileDownloadService registers it as 'in progress' break; } case R.id.fdKeepInSync: { CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); mFile.setKeepInSync(cb.isChecked()); FileDataStorageManager fdsm = new FileDataStorageManager( mAccount, getActivity().getApplicationContext().getContentResolver()); fdsm.saveFile(mFile); if (mFile.keepInSync()) { onClick(getView().findViewById(R.id.fdDownloadBtn)); } else { mContainerActivity .onFileStateChanged(); // put inside 'else' to not call it twice (here, and in the // virtual click on fdDownloadBtn) } Intent intent = new Intent(getActivity().getApplicationContext(), FileObserverService.class); intent.putExtra( FileObserverService.KEY_FILE_CMD, (cb.isChecked() ? FileObserverService.CMD_ADD_OBSERVED_FILE : FileObserverService.CMD_DEL_OBSERVED_FILE)); intent.putExtra(FileObserverService.KEY_CMD_ARG, mFile.getStoragePath()); getActivity().startService(intent); break; } case R.id.fdRenameBtn: { EditNameFragment dialog = EditNameFragment.newInstance(mFile.getFileName()); dialog.show(getFragmentManager(), "nameeditdialog"); dialog.setOnDismissListener(this); break; } case R.id.fdRemoveBtn: { ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance( R.string.confirmation_remove_alert, new String[] {mFile.getFileName()}, mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote, mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel); confDialog.setOnConfirmationListener(this); confDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; } case R.id.fdOpenBtn: { String storagePath = mFile.getStoragePath(); String encodedStoragePath = WebdavUtils.encodePath(storagePath); try { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mFile.getMimetype()); i.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); } catch (Throwable t) { Log.e( TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype()); boolean toastIt = true; String mimeType = ""; 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); i.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); toastIt = false; } } catch (IndexOutOfBoundsException e) { Log.e( TAG, "Trying to find out MIME type of a file without extension: " + storagePath); } catch (ActivityNotFoundException e) { Log.e( TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension"); } catch (Throwable th) { Log.e(TAG, "Unexpected problem when opening: " + storagePath, th); } finally { if (toastIt) { Toast.makeText( getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT) .show(); } } } break; } default: Log.e(TAG, "Incorrect view clicked!"); } /* else if (v.getId() == R.id.fdShareBtn) { Thread t = new Thread(new ShareRunnable(mFile.getRemotePath())); t.start(); }*/ }