From: David A. Velasco Date: Mon, 18 Feb 2013 10:23:18 +0000 (+0100) Subject: Added basic menu options to the preview fragment: open, delete, see details X-Git-Tag: oc-android-1.4.3~39^2~58 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/f2474ae28d3765968559d4eaa965a16e50981793?ds=inline;hp=--cc Added basic menu options to the preview fragment: open, delete, see details --- f2474ae28d3765968559d4eaa965a16e50981793 diff --git a/res/layout/file_details_fragment.xml b/res/layout/file_details_fragment.xml index cee45a9e..135a8640 100644 --- a/res/layout/file_details_fragment.xml +++ b/res/layout/file_details_fragment.xml @@ -165,19 +165,10 @@ android:layout_centerHorizontal="true" android:text="@string/fd_keep_in_sync" /> - - + + + + + + + + + + + diff --git a/res/menu/file_context_menu.xml b/res/menu/file_context_menu.xml deleted file mode 100644 index 622c483d..00000000 --- a/res/menu/file_context_menu.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/menu/main_menu.xml b/res/menu/main_menu.xml new file mode 100644 index 00000000..2aff9e36 --- /dev/null +++ b/res/menu/main_menu.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/res/menu/menu.xml b/res/menu/menu.xml deleted file mode 100644 index 4bee2e87..00000000 --- a/res/menu/menu.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - diff --git a/res/values/strings.xml b/res/values/strings.xml index 8466b0cf..d3fbe15d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -24,6 +24,7 @@ Create directory Search Settings + See details General Device tracking diff --git a/src/com/owncloud/android/ui/activity/FileDetailActivity.java b/src/com/owncloud/android/ui/activity/FileDetailActivity.java index 5bf6bd2b..a36c9723 100644 --- a/src/com/owncloud/android/ui/activity/FileDetailActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDetailActivity.java @@ -40,8 +40,10 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.ui.fragment.FileDetailFragment; +import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.FilePreviewFragment; +import com.owncloud.android.AccountUtils; import com.owncloud.android.R; /** @@ -57,6 +59,10 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File public static final String TAG = FileDetailActivity.class.getSimpleName(); + public static final String EXTRA_MODE = "MODE"; + public static final int MODE_DETAILS = 0; + public static final int MODE_PREVIEW = 1; + private boolean mConfigurationChangedToLandscape = false; private FileDownloaderBinder mDownloaderBinder = null; private ServiceConnection mDownloadConnection, mUploadConnection = null; @@ -99,8 +105,10 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File private void createChildFragment() { OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT); + int mode = getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW); + Fragment newFragment = null; - if (FilePreviewFragment.canBePreviewed(file)) { + if (FilePreviewFragment.canBePreviewed(file) && mode == MODE_PREVIEW) { newFragment = new FilePreviewFragment(file, account); } else { @@ -243,5 +251,13 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File public FileUploaderBinder getFileUploaderBinder() { return mUploaderBinder; } + + + @Override + public void showFragmentWithDetails(OCFile file) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.fragment, new FileDetailFragment(file, (Account) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT)), FileDetailFragment.FTAG); + transaction.commit(); + } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index fbce7cb8..5619caff 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -21,6 +21,7 @@ package com.owncloud.android.ui.activity; import java.io.File; import android.accounts.Account; +import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.app.AlertDialog.Builder; @@ -137,7 +138,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private static final String TAG = "FileDisplayActivity"; - private static int[] mMenuIdentifiersToPatch = {R.id.about_app}; + private static int[] mMenuIdentifiersToPatch = {R.id.action_about_app}; @Override public void onCreate(Bundle savedInstanceState) { @@ -320,7 +321,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSherlock().getMenuInflater(); - inflater.inflate(R.menu.menu, menu); + inflater.inflate(R.menu.main_menu, menu); patchHiddenAccents(menu); @@ -351,11 +352,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public boolean onOptionsItemSelected(MenuItem item) { boolean retval = true; switch (item.getItemId()) { - case R.id.createDirectoryItem: { + case R.id.action_create_dir: { showDialog(DIALOG_CREATE_DIR); break; } - case R.id.startSync: { + case R.id.action_sync_account: { startSynchronization(); break; } @@ -368,7 +369,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements startActivity(settingsIntent); break; } - case R.id.about_app : { + case R.id.action_about_app: { showDialog(DIALOG_ABOUT_APP); break; } @@ -1292,7 +1293,21 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } - + @Override + public void showFragmentWithDetails(OCFile file) { + if (mDualPane) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); + transaction.commit(); + + } else { + Intent showDetailsIntent = new Intent(this, FileDetailActivity.class); + showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file); + showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this)); + showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS); + startActivity(showDetailsIntent); + } + } } diff --git a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java index f2c36afb..ed6e7fa7 100644 --- a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -347,8 +347,7 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements String[] args = {getString(R.string.app_name)}; ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(R.string.upload_query_move_foreign_files, args, R.string.common_yes, -1, R.string.common_no); dialog.setOnConfirmationListener(UploadFilesActivity.this); - mCurrentDialog = dialog; - mCurrentDialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG); + dialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG); } } } @@ -363,16 +362,12 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements setResult(RESULT_OK_AND_MOVE, data); finish(); } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @Override public void onNeutral(String callerTag) { Log.d(TAG, "Phantom neutral button in dialog was clicked; dialog tag is " + callerTag); - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @@ -380,8 +375,6 @@ public class UploadFilesActivity extends SherlockFragmentActivity implements public void onCancel(String callerTag) { /// nothing to do; don't finish, let the user change the selection Log.d(TAG, "Negative button in dialog was clicked; dialog tag is " + callerTag); - mCurrentDialog.dismiss(); - mCurrentDialog = null; } diff --git a/src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java b/src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java index 7cf45538..42d1e622 100644 --- a/src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java +++ b/src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java @@ -35,6 +35,8 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { public final static String ARG_NEUTRAL_BTN_RES = "neutral_btn_res"; public final static String ARG_NEGATIVE_BTN_RES = "negative_btn_res"; + public static final String FTAG_CONFIRMATION = "CONFIRMATION_FRAGMENT"; + private ConfirmationDialogFragmentListener mListener; /** @@ -89,6 +91,7 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mListener.onConfirmation(getTag()); + dialog.dismiss(); } }); if (neuBtn != -1) @@ -96,6 +99,7 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mListener.onNeutral(getTag()); + dialog.dismiss(); } }); if (negBtn != -1) @@ -104,6 +108,7 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { @Override public void onClick(DialogInterface dialog, int which) { mListener.onCancel(getTag()); + dialog.dismiss(); } }); return builder.create(); diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index e90dbf71..680c0b6d 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -115,28 +115,26 @@ import eu.alefzero.webdav.WebdavUtils; * @author David A. Velasco */ public class FileDetailFragment extends SherlockFragment implements - OnClickListener, OnTouchListener, + OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener, FileFragment { public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; - private FileDetailFragment.ContainerActivity mContainerActivity; + private FileFragment.ContainerActivity mContainerActivity; private int mLayout; private View mView; private OCFile mFile; private Account mAccount; private FileDataStorageManager mStorageManager; - private ImageView mPreview; private DownloadFinishReceiver mDownloadFinishReceiver; private UploadFinishReceiver mUploadFinishReceiver; private Handler mHandler; private RemoteOperation mLastRemoteOperation; - private DialogFragment mCurrentDialog; private MediaServiceBinder mMediaServiceBinder = null; private MediaController mMediaController = null; @@ -208,8 +206,6 @@ public class FileDetailFragment extends SherlockFragment implements mView.findViewById(R.id.fdOpenBtn).setOnClickListener(this); mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this); //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this); - mPreview = (ImageView)mView.findViewById(R.id.fdPreview); - mPreview.setOnTouchListener(this); } updateFileDetails(false); @@ -275,8 +271,6 @@ public class FileDetailFragment extends SherlockFragment implements filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); getActivity().registerReceiver(mUploadFinishReceiver, filter); - mPreview = (ImageView)mView.findViewById(R.id.fdPreview); // this is here just because it is nullified in onPause() - } @@ -290,10 +284,6 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().unregisterReceiver(mUploadFinishReceiver); mUploadFinishReceiver = null; - if (mPreview != null) { // why? - mPreview = null; - } - } @@ -404,8 +394,7 @@ public class FileDetailFragment extends SherlockFragment implements mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel); confDialog.setOnConfirmationListener(this); - mCurrentDialog = confDialog; - mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION); + confDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; } case R.id.fdOpenBtn: { @@ -423,17 +412,6 @@ public class FileDetailFragment extends SherlockFragment implements } - @Override - public boolean onTouch(View v, MotionEvent event) { - if (v == mPreview && event.getAction() == MotionEvent.ACTION_DOWN && mFile != null && mFile.isDown()) { - if (mFile.isVideo()) { - startVideoActivity(); - } - } - return false; - } - - private void startVideoActivity() { Intent i = new Intent(getActivity(), VideoActivity.class); i.putExtra(VideoActivity.EXTRA_FILE, mFile); @@ -564,8 +542,6 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } @Override @@ -577,15 +553,11 @@ 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; } @@ -661,11 +633,6 @@ public class FileDetailFragment extends SherlockFragment implements setButtonsForTransferring(); } else if (mFile.isDown()) { - // Update preview - if (mFile.getMimetype().startsWith("image/")) { - BitmapLoader bl = new BitmapLoader(); - bl.execute(new String[]{mFile.getStoragePath()}); - } setButtonsForDown(); @@ -819,30 +786,6 @@ public class FileDetailFragment extends SherlockFragment implements /** - * Interface to implement by any Activity that includes some instance of FileDetailFragment - * - * @author David A. Velasco - */ - public interface ContainerActivity extends TransferServiceGetter { - - /** - * Callback method invoked when the detail fragment wants to notice its container - * activity about a relevant state the file shown by the fragment. - * - * Added to notify to FileDisplayActivity about the need of refresh the files list. - * - * Currently called when: - * - a download is started; - * - a rename is completed; - * - a deletion is completed; - * - the 'inSync' flag is changed; - */ - public void onFileStateChanged(); - - } - - - /** * Once the file download has finished -> update view * @author Bartek Przybylski */ @@ -1022,80 +965,6 @@ public class FileDetailFragment extends SherlockFragment implements } - class BitmapLoader extends AsyncTask { - @SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20 - @Override - protected Bitmap doInBackground(String... params) { - Bitmap result = null; - if (params.length != 1) return result; - String storagePath = params[0]; - try { - - BitmapFactory.Options options = new Options(); - options.inScaled = true; - options.inPurgeable = true; - options.inJustDecodeBounds = true; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - options.inPreferQualityOverSpeed = false; - } - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { - options.inMutable = false; - } - - result = BitmapFactory.decodeFile(storagePath, options); - options.inJustDecodeBounds = false; - - int width = options.outWidth; - int height = options.outHeight; - int scale = 1; - if (width >= 2048 || height >= 2048) { - scale = (int) Math.ceil((Math.ceil(Math.max(height, width) / 2048.))); - options.inSampleSize = scale; - } - Display display = getActivity().getWindowManager().getDefaultDisplay(); - Point size = new Point(); - int screenwidth; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { - display.getSize(size); - screenwidth = size.x; - } else { - screenwidth = display.getWidth(); - } - - Log.e("ASD", "W " + width + " SW " + screenwidth); - - if (width > screenwidth) { - scale = (int) Math.ceil((float)width / screenwidth); - options.inSampleSize = scale; - } - - result = BitmapFactory.decodeFile(storagePath, options); - - Log.e("ASD", "W " + options.outWidth + " SW " + options.outHeight); - - } catch (OutOfMemoryError e) { - result = null; - Log.e(TAG, "Out of memory occured for file with size " + storagePath); - - } catch (NoSuchFieldError e) { - result = null; - Log.e(TAG, "Error from access to unexisting field despite protection " + storagePath); - - } catch (Throwable t) { - result = null; - Log.e(TAG, "Unexpected error while creating image preview " + storagePath, t); - } - return result; - } - @Override - protected void onPostExecute(Bitmap result) { - if (result != null && mPreview != null) { - mPreview.setImageBitmap(result); - } - } - - } - /** * {@inheritDoc} */ diff --git a/src/com/owncloud/android/ui/fragment/FileFragment.java b/src/com/owncloud/android/ui/fragment/FileFragment.java index 5537d62e..24e1251e 100644 --- a/src/com/owncloud/android/ui/fragment/FileFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileFragment.java @@ -21,6 +21,7 @@ package com.owncloud.android.ui.fragment; import android.support.v4.app.Fragment; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.ui.activity.TransferServiceGetter; /** * Common methods for {@link Fragment}s containing {@link OCFile}s @@ -36,4 +37,36 @@ public interface FileFragment { * @return The {@link OCFile} hold */ public OCFile getFile(); + + + /** + * Interface to implement by any Activity that includes some instance of FileFragment + * + * @author David A. Velasco + */ + public interface ContainerActivity extends TransferServiceGetter { + + /** + * Callback method invoked when the detail fragment wants to notice its container + * activity about a relevant state the file shown by the fragment. + * + * Added to notify to FileDisplayActivity about the need of refresh the files list. + * + * Currently called when: + * - a download is started; + * - a rename is completed; + * - a deletion is completed; + * - the 'inSync' flag is changed; + */ + public void onFileStateChanged(); + + /** + * Request the parent activity to show the details of an {@link OCFile}. + * + * @param file File to show details + */ + public void showFragmentWithDetails(OCFile file); + + } + } diff --git a/src/com/owncloud/android/ui/fragment/FilePreviewFragment.java b/src/com/owncloud/android/ui/fragment/FilePreviewFragment.java index 291bcd46..b4c1d432 100644 --- a/src/com/owncloud/android/ui/fragment/FilePreviewFragment.java +++ b/src/com/owncloud/android/ui/fragment/FilePreviewFragment.java @@ -80,8 +80,12 @@ import android.widget.MediaController; import android.widget.TextView; import android.widget.Toast; import android.widget.VideoView; +import android.widget.AdapterView.AdapterContextMenuInfo; import com.actionbarsherlock.app.SherlockFragment; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; import com.owncloud.android.AccountUtils; import com.owncloud.android.DisplayUtils; import com.owncloud.android.authenticator.AccountAuthenticator; @@ -126,19 +130,17 @@ import eu.alefzero.webdav.WebdavUtils; * @author David A. Velasco */ public class FilePreviewFragment extends SherlockFragment implements - /*OnClickListener,*/ OnTouchListener , FileFragment - /*ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener*/ { + /*OnClickListener,*/ OnTouchListener , FileFragment, + ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener /*, EditNameDialogListener*/ { public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; private static final String EXTRA_PLAY_POSITION = "PLAY_POSITION"; - //private FilePreviewFragment.ContainerActivity mContainerActivity; - private View mView; private OCFile mFile; private Account mAccount; - //private FileDataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private ImageView mImagePreview; public Bitmap mBitmap = null; private VideoView mVideoPreview; @@ -147,9 +149,8 @@ public class FilePreviewFragment extends SherlockFragment implements //private DownloadFinishReceiver mDownloadFinishReceiver; //private UploadFinishReceiver mUploadFinishReceiver; - //private Handler mHandler; - //private RemoteOperation mLastRemoteOperation; - //private DialogFragment mCurrentDialog; + private Handler mHandler; + private RemoteOperation mLastRemoteOperation; private MediaServiceBinder mMediaServiceBinder = null; private MediaController mMediaController = null; @@ -157,8 +158,6 @@ public class FilePreviewFragment extends SherlockFragment implements private VideoHelper mVideoHelper; private static final String TAG = FilePreviewFragment.class.getSimpleName(); - public static final String FTAG = FilePreviewFragment.class.getSimpleName();; - //public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT"; /** @@ -173,7 +172,7 @@ public class FilePreviewFragment extends SherlockFragment implements mFile = fileToDetail; mAccount = ocAccount; mSavedPlaybackPosition = 0; - //mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment + mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment } @@ -188,7 +187,7 @@ public class FilePreviewFragment extends SherlockFragment implements mFile = null; mAccount = null; mSavedPlaybackPosition = 0; - //mStorageManager = null; + mStorageManager = null; } @@ -198,7 +197,8 @@ public class FilePreviewFragment extends SherlockFragment implements @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - //mHandler = new Handler(); + mHandler = new Handler(); + setHasOptionsMenu(true); } @@ -232,6 +232,8 @@ public class FilePreviewFragment extends SherlockFragment implements @Override public void onAttach(Activity activity) { super.onAttach(activity); + if (!(activity instanceof FileFragment.ContainerActivity)) + throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName()); } @@ -242,7 +244,7 @@ public class FilePreviewFragment extends SherlockFragment implements public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - //mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); + mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); if (savedInstanceState != null) { mFile = savedInstanceState.getParcelable(FilePreviewFragment.EXTRA_FILE); mAccount = savedInstanceState.getParcelable(FilePreviewFragment.EXTRA_ACCOUNT); @@ -306,6 +308,88 @@ public class FilePreviewFragment extends SherlockFragment implements } + /** + * {@inheritDoc} + */ + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + + inflater.inflate(R.menu.file_actions_menu, menu); + List toHide = new ArrayList(); + + MenuItem item = null; + toHide.add(R.id.action_cancel_download); + toHide.add(R.id.action_cancel_upload); + toHide.add(R.id.action_download_file); + toHide.add(R.id.action_rename_file); // by now + + for (int i : toHide) { + item = menu.findItem(i); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } + } + + } + + + /** + * {@inheritDoc} + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_open_file_with: { + openFile(); + return true; + } + case R.id.action_remove_file: { + removeFile(); + return true; + } + case R.id.action_see_details: { + seeDetails(); + return true; + } + + /* + case R.id.action_toggle_keep_in_sync: { + CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); + mFile.setKeepInSync(cb.isChecked()); + mStorageManager.saveFile(mFile); + + /// 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, mFile); + intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount); + Log.e(TAG, "starting observer service"); + getActivity().startService(intent); + + if (mFile.keepInSync()) { + onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization + } + break; + }*/ + default: + return false; + } + } + + + private void seeDetails() { + stopPreview(false); + ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mFile); + } + + private void prepareVideo() { // create helper to get more control on the playback mVideoHelper = new VideoHelper(); @@ -441,6 +525,11 @@ public class FilePreviewFragment extends SherlockFragment implements mMediaController = null; } } + } + + @Override + public void onDestroy() { + super.onDestroy(); if (mBitmap != null) { mBitmap.recycle(); } @@ -660,11 +749,15 @@ public class FilePreviewFragment extends SherlockFragment implements - /*-* - * Opens mFile. - *-/ + /** + * Opens the previewed file with an external application. + * + * TODO - improve this; instead of prioritize the actions available for the MIME type in the server, + * we should get a list of available apps for MIME tpye in the server and join it with the list of + * available apps for the MIME type known from the file extension, to let the user choose + */ private void openFile() { - + stopPreview(true); String storagePath = mFile.getStoragePath(); String encodedStoragePath = WebdavUtils.encodePath(storagePath); try { @@ -708,48 +801,70 @@ public class FilePreviewFragment extends SherlockFragment implements } } + finish(); + } + + /** + * Starts a the removal of the previewed file. + * + * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)}, + * depending upon the user selection in the dialog. + */ + private void removeFile() { + ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance( + R.string.confirmation_remove_alert, + new String[]{mFile.getFileName()}, + R.string.confirmation_remove_remote_and_local, + R.string.confirmation_remove_local, + R.string.common_cancel); + confDialog.setOnConfirmationListener(this); + confDialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION); } - */ - /* + + /** + * Performs the removal of the previewed file, both locally and in the server. + */ @Override public void onConfirmation(String callerTag) { - if (callerTag.equals(FTAG_CONFIRMATION)) { - if (mStorageManager.getFileById(mFile.getFileId()) != null) { - mLastRemoteOperation = new RemoveFileOperation( mFile, - true, - mStorageManager); - WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); - mLastRemoteOperation.execute(wc, this, mHandler); - - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; - getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); - } + if (mStorageManager.getFileById(mFile.getFileId()) != null) { // check that the file is still there; + stopPreview(true); + mLastRemoteOperation = new RemoveFileOperation( mFile, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters + true, + mStorageManager); + WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); + mLastRemoteOperation.execute(wc, this, mHandler); + + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } + + /** + * Removes the file from local storage + */ @Override public void onNeutral(String callerTag) { - File f = null; - if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) { + // TODO this code should be made in a secondary thread, + if (mFile.isDown()) { // checks it is still there + stopPreview(true); + File f = new File(mFile.getStoragePath()); f.delete(); mFile.setStoragePath(null); mStorageManager.saveFile(mFile); - updateFileDetails(mFile, mAccount); + finish(); } - mCurrentDialog.dismiss(); - mCurrentDialog = null; } + /** + * User cancelled the removal action. + */ @Override public void onCancel(String callerTag) { - Log.d(TAG, "REMOVAL CANCELED"); - mCurrentDialog.dismiss(); - mCurrentDialog = null; + // nothing to do here } - */ + /** * {@inheritDoc} @@ -928,26 +1043,25 @@ public class FilePreviewFragment extends SherlockFragment implements (file.isAudio() || file.isVideo() || file.isImage())); } - /*-* + /** * {@inheritDoc} - *-/ + */ @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { if (operation.equals(mLastRemoteOperation)) { if (operation instanceof RemoveFileOperation) { onRemoveFileOperationFinish((RemoveFileOperation)operation, result); - + + /* } else if (operation instanceof RenameFileOperation) { onRenameFileOperationFinish((RenameFileOperation)operation, result); } else if (operation instanceof SynchronizeFileOperation) { - onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); + onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);*/ } } } - */ - /* private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); @@ -955,15 +1069,7 @@ public class FilePreviewFragment extends SherlockFragment implements if (result.isSuccess()) { Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); msg.show(); - if (inDisplayActivity) { - // double pane - FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); - transaction.replace(R.id.file_details_container, new FilePreviewFragment(null, null)); // empty FileDetailFragment - transaction.commit(); - mContainerActivity.onFileStateChanged(); - } else { - getActivity().finish(); - } + finish(); } else { Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); @@ -973,7 +1079,38 @@ public class FilePreviewFragment extends SherlockFragment implements } } } + + private void stopPreview(boolean stopAudio) { + if (mMediaController != null) { + mMediaController.hide(); + } + if (mFile.isAudio() && stopAudio) { + mMediaServiceBinder.pause(); + + } else if (mFile.isVideo()) { + mVideoPreview.stopPlayback(); + } + } + + + + /** + * Finishes the preview + */ + private void finish() { + Activity container = getActivity(); + if (container instanceof FileDisplayActivity) { + // double pane + FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment + transaction.commit(); + ((FileFragment.ContainerActivity)container).onFileStateChanged(); + } else { + container.finish(); + } + } + /* private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) { boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 117b0b2d..9a479da2 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -80,8 +80,6 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial private Handler mHandler; private OCFile mTargetFile; - private DialogFragment mCurrentDialog; - /** * {@inheritDoc} */ @@ -162,7 +160,7 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getActivity().getMenuInflater(); - inflater.inflate(R.menu.file_context_menu, menu); + inflater.inflate(R.menu.file_actions_menu, menu); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; OCFile targetFile = (OCFile) mAdapter.getItem(info.position); List toHide = new ArrayList(); @@ -171,46 +169,47 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial MenuItem item = null; if (targetFile.isDirectory()) { // contextual menu for folders - toHide.add(R.id.open_file_item); - toHide.add(R.id.download_file_item); - toHide.add(R.id.cancel_download_item); - toHide.add(R.id.cancel_upload_item); + toHide.add(R.id.action_open_file_with); + toHide.add(R.id.action_download_file); + toHide.add(R.id.action_cancel_download); + toHide.add(R.id.action_cancel_upload); + toHide.add(R.id.action_see_details); if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) || mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ) { - toDisable.add(R.id.rename_file_item); - toDisable.add(R.id.remove_file_item); + toDisable.add(R.id.action_rename_file); + toDisable.add(R.id.action_remove_file); } } else { // contextual menu for regular files if (targetFile.isDown()) { - toHide.add(R.id.cancel_download_item); - toHide.add(R.id.cancel_upload_item); - item = menu.findItem(R.id.download_file_item); + toHide.add(R.id.action_cancel_download); + toHide.add(R.id.action_cancel_upload); + item = menu.findItem(R.id.action_download_file); if (item != null) { item.setTitle(R.string.filedetails_sync_file); } } else { - toHide.add(R.id.open_file_item); + toHide.add(R.id.action_open_file_with); } if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { - toHide.add(R.id.download_file_item); - toHide.add(R.id.cancel_upload_item); - toDisable.add(R.id.open_file_item); - toDisable.add(R.id.rename_file_item); - toDisable.add(R.id.remove_file_item); + toHide.add(R.id.action_download_file); + toHide.add(R.id.action_cancel_upload); + toDisable.add(R.id.action_open_file_with); + toDisable.add(R.id.action_rename_file); + toDisable.add(R.id.action_remove_file); } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { - toHide.add(R.id.download_file_item); - toHide.add(R.id.cancel_download_item); - toDisable.add(R.id.open_file_item); - toDisable.add(R.id.rename_file_item); - toDisable.add(R.id.remove_file_item); + toHide.add(R.id.action_download_file); + toHide.add(R.id.action_cancel_download); + toDisable.add(R.id.action_open_file_with); + toDisable.add(R.id.action_rename_file); + toDisable.add(R.id.action_remove_file); } else { - toHide.add(R.id.cancel_download_item); - toHide.add(R.id.cancel_upload_item); + toHide.add(R.id.action_cancel_download); + toHide.add(R.id.action_cancel_upload); } } @@ -239,12 +238,12 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); mTargetFile = (OCFile) mAdapter.getItem(info.position); switch (item.getItemId()) { - case R.id.rename_file_item: { + case R.id.action_rename_file: { EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mTargetFile.getFileName(), this); dialog.show(getFragmentManager(), EditNameDialog.TAG); return true; } - case R.id.remove_file_item: { + case R.id.action_remove_file: { int messageStringId = R.string.confirmation_remove_alert; int posBtnStringId = R.string.confirmation_remove_remote; int neuBtnStringId = -1; @@ -263,11 +262,10 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial neuBtnStringId, R.string.common_cancel); confDialog.setOnConfirmationListener(this); - mCurrentDialog = confDialog; - mCurrentDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION); + confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION); return true; } - case R.id.open_file_item: { + case R.id.action_open_file_with: { String storagePath = mTargetFile.getStoragePath(); String encodedStoragePath = WebdavUtils.encodePath(storagePath); try { @@ -313,7 +311,7 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial } return true; } - case R.id.download_file_item: { + case R.id.action_download_file: { Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()); RemoteOperation operation = new SynchronizeFileOperation(mTargetFile, null, mContainerActivity.getStorageManager(), account, true, false, getSherlockActivity()); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getSherlockActivity().getApplicationContext()); @@ -321,7 +319,7 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial getSherlockActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT); return true; } - case R.id.cancel_download_item: { + case R.id.action_cancel_download: { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity()); if (downloaderBinder != null && downloaderBinder.isDownloading(account, mTargetFile)) { @@ -331,7 +329,7 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial } return true; } - case R.id.cancel_upload_item: { + case R.id.action_cancel_upload: { FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity()); if (uploaderBinder != null && uploaderBinder.isUploading(account, mTargetFile)) { @@ -341,6 +339,10 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial } return true; } + case R.id.action_see_details: { + ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mTargetFile); + return true; + } default: return super.onContextItemSelected(item); } @@ -498,10 +500,6 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT); } - if (mCurrentDialog != null) { - mCurrentDialog.dismiss(); - mCurrentDialog = null; - } } } @@ -517,10 +515,6 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial mTargetFile.setStoragePath(null); mContainerActivity.getStorageManager().saveFile(mTargetFile); } - if (mCurrentDialog != null) { - mCurrentDialog.dismiss(); - mCurrentDialog = null; - } listDirectory(); mContainerActivity.onTransferStateChanged(mTargetFile, false, false); } @@ -528,10 +522,6 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial @Override public void onCancel(String callerTag) { Log.d(TAG, "REMOVAL CANCELED"); - if (mCurrentDialog != null) { - mCurrentDialog.dismiss(); - mCurrentDialog = null; - } }