From: David A. Velasco Date: Fri, 23 Nov 2012 13:32:58 +0000 (+0100) Subject: Merge branch 'long_press' X-Git-Tag: oc-android-1.4.3~88 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a7cbc53251aac878a9a356166d388685523f26bc?ds=inline;hp=-c Merge branch 'long_press' --- a7cbc53251aac878a9a356166d388685523f26bc diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 1f34ae5f,99968910..4a5b5cb3 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -39,8 -39,6 +39,8 @@@ import android.content.pm.PackageInfo import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources.NotFoundException; import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@@ -74,7 -72,13 +74,13 @@@ import com.owncloud.android.files.servi import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.network.OwnCloudClientUtils; + import com.owncloud.android.operations.OnRemoteOperationListener; + import com.owncloud.android.operations.RemoteOperation; import com.owncloud.android.operations.RemoteOperationResult; + import com.owncloud.android.operations.RemoveFileOperation; + import com.owncloud.android.operations.RenameFileOperation; + import com.owncloud.android.operations.SynchronizeFileOperation; + import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.syncadapter.FileSyncService; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; @@@ -92,7 -96,7 +98,7 @@@ import eu.alefzero.webdav.WebdavClient */ public class FileDisplayActivity extends SherlockFragmentActivity implements - OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener { + OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener { private ArrayAdapter mDirectories; private OCFile mCurrentDir = null; @@@ -124,8 -128,6 +130,8 @@@ private static final int ACTION_SELECT_MULTIPLE_FILES = 2; private static final String TAG = "FileDisplayActivity"; + + private static int[] mMenuIdentifiersToPatch = {R.id.about_app}; @Override public void onCreate(Bundle savedInstanceState) { @@@ -274,32 -276,9 +280,32 @@@ public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSherlock().getMenuInflater(); inflater.inflate(R.menu.menu, menu); + + patchHiddenAccents(menu); + return true; } + /** + * Workaround for this: http://code.google.com/p/android/issues/detail?id=3974 + * + * @param menu Menu to patch + */ + private void patchHiddenAccents(Menu menu) { + for (int i = 0; i < mMenuIdentifiersToPatch.length ; i++) { + MenuItem aboutItem = menu.findItem(mMenuIdentifiersToPatch[i]); + if (aboutItem != null && aboutItem.getIcon() instanceof BitmapDrawable) { + // Clip off the bottom three (density independent) pixels of transparent padding + Bitmap original = ((BitmapDrawable) aboutItem.getIcon()).getBitmap(); + float scale = getResources().getDisplayMetrics().density; + int clippedHeight = (int) (original.getHeight() - (3 * scale)); + Bitmap scaled = Bitmap.createBitmap(original, 0, 0, original.getWidth(), clippedHeight); + aboutItem.setIcon(new BitmapDrawable(getResources(), scaled)); + } + } + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { boolean retval = true; @@@ -332,7 -311,7 +338,7 @@@ break; } default: - retval = false; + retval = super.onOptionsItemSelected(item); } return retval; } @@@ -896,16 -875,11 +902,11 @@@ */ @Override public void onReceive(Context context, Intent intent) { - long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1); - OCFile parentDir = mStorageManager.getFileById(parentDirId); + String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); - - if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - parentDir != null && - ( (mCurrentDir == null && parentDir.getFileName().equals("/")) || - parentDir.equals(mCurrentDir) - ) - ) { + boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); + boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + if (sameAccount && isDescendant) { OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); @@@ -924,9 -898,9 +925,9 @@@ public void onReceive(Context context, Intent intent) { String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); - - if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) { + boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); + boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + if (sameAccount && isDescendant) { OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); @@@ -1051,7 -1025,7 +1052,7 @@@ if (mDualPane) { FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); if (fragment != null) - fragment.updateFileDetails(); + fragment.updateFileDetails(false); } } @@@ -1096,4 -1070,151 +1097,151 @@@ } + /** + * Updates the view associated to the activity after the finish of some operation over files + * in the current account. + * + * @param operation Removal operation performed. + * @param result Result of the removal. + */ + @Override + public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { + 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); + } + } + + + /** + * Updates the view associated to the activity after the finish of an operation trying to remove a + * file. + * + * @param operation Removal operation performed. + * @param result Result of the removal. + */ + private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { + dismissDialog(DIALOG_SHORT_WAIT); + if (result.isSuccess()) { + Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG); + msg.show(); + OCFile removedFile = operation.getFile(); + if (mDualPane) { + FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (details != null && removedFile.equals(details.getDisplayedFile()) ) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment + transaction.commit(); + } + } + if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) { + mFileList.listDirectory(); + } + + } else { + Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG); + msg.show(); + if (result.isSslRecoverableException()) { + mLastSslUntrustedServerResult = result; + showDialog(DIALOG_SSL_VALIDATOR); + } + } + } + + /** + * Updates the view associated to the activity after the finish of an operation trying to rename a + * file. + * + * @param operation Renaming operation performed. + * @param result Result of the renaming. + */ + private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) { + dismissDialog(DIALOG_SHORT_WAIT); + OCFile renamedFile = operation.getFile(); + if (result.isSuccess()) { + if (mDualPane) { + FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (details != null && renamedFile.equals(details.getDisplayedFile()) ) { + details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this)); + } + } + if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) { + mFileList.listDirectory(); + } + + } else { + if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { + Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG); + msg.show(); + // TODO throw again the new rename dialog + } else { + Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG); + msg.show(); + if (result.isSslRecoverableException()) { + mLastSslUntrustedServerResult = result; + showDialog(DIALOG_SSL_VALIDATOR); + } + } + } + } + + + private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) { + dismissDialog(DIALOG_SHORT_WAIT); + OCFile syncedFile = operation.getLocalFile(); + if (!result.isSuccess()) { + if (result.getCode() == ResultCode.SYNC_CONFLICT) { + Intent i = new Intent(this, ConflictsResolveActivity.class); + i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile); + i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this)); + startActivity(i); + + } else { + Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG); + msg.show(); + } + + } else { + if (operation.transferWasRequested()) { + mFileList.listDirectory(); + onTransferStateChanged(syncedFile, true, true); + + } else { + Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); + msg.show(); + } + } + } + + + /** + * {@inheritDoc} + */ + @Override + public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) { + /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + }*/ + if (mDualPane) { + FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (details != null && file.equals(details.getDisplayedFile()) ) { + if (downloading || uploading) { + details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this)); + } else { + details.updateFileDetails(downloading || uploading); + } + } + } + } + + + + + }