+ private void toggleKeepInSync() {
+ CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
+ OCFile file = getFile();
+ file.setKeepInSync(cb.isChecked());
+ mStorageManager.saveFile(file);
+
+ /// register the OCFile instance in the observer service to monitor local updates;
+ /// if necessary, the file is download
+ 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_FILE, file);
+ intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
+ getActivity().startService(intent);
+
+ if (file.keepInSync()) {
+ synchronizeFile(); // force an immediate synchronization
+ }
+ }
+
+
+ private void removeFile() {
+ OCFile file = getFile();
+ ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
+ R.string.confirmation_remove_alert,
+ new String[]{file.getFileName()},
+ file.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
+ file.isDown() ? R.string.confirmation_remove_local : -1,
+ R.string.common_cancel);
+ confDialog.setOnConfirmationListener(this);
+ confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
+ }
+
+
+ private void renameFile() {
+ OCFile file = getFile();
+ String fileName = file.getFileName();
+ int extensionStart = file.isFolder() ? -1 : fileName.lastIndexOf(".");
+ int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
+ EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
+ dialog.show(getFragmentManager(), "nameeditdialog");
+ }
+
+ private void synchronizeFile() {
+ OCFile file = getFile();
+ FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
+ FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
+ downloaderBinder.cancel(mAccount, file);
+ if (file.isDown()) {
+ setButtonsForDown();
+ } else {
+ setButtonsForRemote();
+ }
+
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
+ uploaderBinder.cancel(mAccount, file);
+ if (!file.fileExists()) {
+ // TODO make something better
+ ((FileDisplayActivity)getActivity()).cleanSecondFragment();
+
+ } else if (file.isDown()) {
+ setButtonsForDown();
+ } else {
+ setButtonsForRemote();
+ }
+
+ } else {
+ mLastRemoteOperation = new SynchronizeFileOperation(file, null, mStorageManager, mAccount, true, getActivity());
+ mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
+
+ // update ui
+ ((FileDisplayActivity) getActivity()).showLoadingDialog();
+
+ }
+ }
+