From: jabarros Date: Wed, 17 Sep 2014 07:47:34 +0000 (+0200) Subject: Merge branch 'develop' into better_loggin_system X-Git-Tag: oc-android-1.7.0_signed~176^2~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/2ef886af316609c2e4a1fe5f2ee32345a8008e33?ds=inline;hp=-c Merge branch 'develop' into better_loggin_system --- 2ef886af316609c2e4a1fe5f2ee32345a8008e33 diff --combined res/values/strings.xml index 3611c105,40910804..21115b91 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -33,8 -33,7 +33,7 @@@ Imprint "Try %1$s on your smartphone!" - "I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s" - + "I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s" Check Server Server address https://… @@@ -255,9 -254,9 +254,9 @@@ Sorry, sharing is not enabled on your server. Please contact your administrator. - Unable to share this file or folder. Please, make sure it exists + Unable to share. Please check whether the file exists An error occurred while trying to share this file or folder - Unable to unshare this file or folder. It does not exist. + Unable to unshare. Please check whether the file exists An error occurred while trying to unshare this file or folder Send @@@ -286,9 -285,16 +285,21 @@@ Add account Secure connection is redirected through an unsecured route. + Logs + Send History + Owncloud Android app logs + Loading data... + + Authentication required + Wrong password + Move + Nothing in here. You can add a folder! + Choose + + Unable to move. Please check whether the file exists + It is not possible to move a folder into a descendant + The file exists already in the destination folder + An error occurred while trying to move this file or folder + to move this file + diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index 80a522ba,21aab72f..d88b8dc2 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@@ -50,7 -50,9 +50,9 @@@ import android.view.View.OnFocusChangeL import android.view.View.OnTouchListener; import android.view.Window; import android.view.inputmethod.EditorInfo; + import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; + import android.webkit.WebView; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; @@@ -69,7 -71,6 +71,7 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; @@@ -78,10 -79,12 +80,11 @@@ import com.owncloud.android.operations. import com.owncloud.android.operations.OAuth2GetAccessToken; import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; + import com.owncloud.android.ui.dialog.CredentialsDialogFragment; import com.owncloud.android.ui.dialog.IndeterminateProgressDialog; import com.owncloud.android.ui.dialog.SamlWebViewDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener; -import com.owncloud.android.utils.Log_OC; /** * This Activity is used to add an ownCloud account to the App @@@ -125,6 -128,8 +128,8 @@@ SsoWebViewClientListener, OnSslUntruste private static final String UNTRUSTED_CERT_DIALOG_TAG = "UNTRUSTED_CERT_DIALOG"; private static final String SAML_DIALOG_TAG = "SAML_DIALOG"; private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG"; + private static final String CREDENTIALS_DIALOG_TAG = "CREDENTIALS_DIALOG"; + private static final String KEY_AUTH_IS_FIRST_ATTEMPT_TAG = "KEY_AUTH_IS_FIRST_ATTEMPT"; /// parameters from EXTRAs in starter Intent @@@ -170,6 -175,8 +175,8 @@@ private String mAuthToken = ""; + private boolean mIsFirstAuthAttempt; + /// Identifier of operation in progress which result shouldn't be lost private long mWaitingForOpId = Long.MAX_VALUE; @@@ -186,6 -193,8 +193,8 @@@ super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); + mIsFirstAuthAttempt = true; + // bind to Operations Service mOperationsServiceConnection = new OperationsServiceConnection(); if (!bindService(new Intent(this, OperationsService.class), @@@ -210,6 -219,7 +219,7 @@@ } else { mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE); mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID); + mIsFirstAuthAttempt = savedInstanceState.getBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG); } /// load user interface @@@ -556,6 -566,9 +566,9 @@@ outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText); outState.putString(KEY_AUTH_TOKEN, mAuthToken); + /// authentication + outState.putBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG, mIsFirstAuthAttempt); + //Log_OC.wtf(TAG, "onSaveInstanceState end" ); } @@@ -1684,6 -1697,7 +1697,7 @@@ dialog.show(ft, UNTRUSTED_CERT_DIALOG_TAG); } + /** * Show untrusted cert dialog */ @@@ -1774,5 -1788,33 +1788,33 @@@ } } - + + /** + * Create and show dialog for request authentication to the user + * @param webView + * @param handler + */ + public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) { + + // Show a dialog with the certificate info + CredentialsDialogFragment dialog = CredentialsDialogFragment.newInstanceForCredentials(webView, handler); + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction ft = fm.beginTransaction(); + ft.addToBackStack(null); + dialog.setCancelable(false); + dialog.show(ft, CREDENTIALS_DIALOG_TAG); + + if (!mIsFirstAuthAttempt) { + Toast.makeText(getApplicationContext(), getText(R.string.saml_authentication_wrong_pass), Toast.LENGTH_LONG).show(); + } else { + mIsFirstAuthAttempt = false; + } + } + + /** + * For retrieving the clicking on authentication cancel button + */ + public void doNegativeAuthenticatioDialogClick(){ + mIsFirstAuthAttempt = true; + } } diff --combined src/com/owncloud/android/authentication/SsoWebViewClient.java index 6ce86689,fb078bdf..b90ab85b --- a/src/com/owncloud/android/authentication/SsoWebViewClient.java +++ b/src/com/owncloud/android/authentication/SsoWebViewClient.java @@@ -24,9 -24,6 +24,9 @@@ import java.security.cert.CertificateEx import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import com.owncloud.android.lib.common.network.NetworkUtils; +import com.owncloud.android.lib.common.utils.Log_OC; + import android.content.Context; import android.graphics.Bitmap; import android.net.http.SslCertificate; @@@ -43,6 -40,9 +43,6 @@@ import android.webkit.WebResourceRespon import android.webkit.WebView; import android.webkit.WebViewClient; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.utils.Log_OC; - /** * Custom {@link WebViewClient} client aimed to catch the end of a single-sign-on process @@@ -66,6 -66,7 +66,7 @@@ public class SsoWebViewClient extends W private WeakReference mListenerRef; private String mTargetUrl; private String mLastReloadedUrlAtError; + public SsoWebViewClient (Context context, Handler listenerHandler, SsoWebViewClientListener listener) { mContext = context; @@@ -86,6 -87,7 +87,7 @@@ @Override public void onPageStarted (WebView view, String url, Bitmap favicon) { Log_OC.d(TAG, "onPageStarted : " + url); + view.clearCache(true); super.onPageStarted(view, url, favicon); } @@@ -195,6 -197,8 +197,8 @@@ @Override public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm) { Log_OC.d(TAG, "onReceivedHttpAuthRequest : " + host); + + ((AuthenticatorActivity)mContext).createAuthenticationDialog(view, handler); } @Override @@@ -229,5 -233,4 +233,4 @@@ Log_OC.d(TAG, "shouldOverrideKeyEvent : " + event); return false; } - } diff --combined src/com/owncloud/android/datamodel/FileDataStorageManager.java index 1034eb97,aaafb3a0..4848246f --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@@ -27,11 -27,11 +27,11 @@@ import java.util.Vector import com.owncloud.android.MainApp; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.utils.FileStorageUtils; -import com.owncloud.android.utils.Log_OC; import android.accounts.Account; @@@ -612,6 -612,126 +612,126 @@@ public class FileDataStorageManager } + public void moveLocalFile(OCFile file, String targetPath, String targetParentPath) { + + if (file != null && file.fileExists() && !OCFile.ROOT_PATH.equals(file.getFileName())) { + + OCFile targetParent = getFileByPath(targetParentPath); + if (targetParent == null) { + // TODO panic + } + + /// 1. get all the descendants of the moved element in a single QUERY + Cursor c = null; + if (getContentProviderClient() != null) { + try { + c = getContentProviderClient().query( + ProviderTableMeta.CONTENT_URI, + null, + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + + ProviderTableMeta.FILE_PATH + " LIKE ? ", + new String[] { + mAccount.name, + file.getRemotePath() + "%" + }, + ProviderTableMeta.FILE_PATH + " ASC " + ); + } catch (RemoteException e) { + Log_OC.e(TAG, e.getMessage()); + } + + } else { + c = getContentResolver().query( + ProviderTableMeta.CONTENT_URI, + null, + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + + ProviderTableMeta.FILE_PATH + " LIKE ? ", + new String[] { + mAccount.name, + file.getRemotePath() + "%" + }, + ProviderTableMeta.FILE_PATH + " ASC " + ); + } + + /// 2. prepare a batch of update operations to change all the descendants + ArrayList operations = + new ArrayList(c.getCount()); + String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name); + if (c.moveToFirst()) { + int lengthOfOldPath = file.getRemotePath().length(); + int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath; + do { + ContentValues cv = new ContentValues(); // keep construction in the loop + OCFile child = createFileInstance(c); + cv.put( + ProviderTableMeta.FILE_PATH, + targetPath + child.getRemotePath().substring(lengthOfOldPath) + ); + if (child.getStoragePath() != null && + child.getStoragePath().startsWith(defaultSavePath)) { + // update link to downloaded content - but local move is not done here! + cv.put( + ProviderTableMeta.FILE_STORAGE_PATH, + defaultSavePath + targetPath + + child.getStoragePath().substring(lengthOfOldStoragePath) + ); + } + if (child.getRemotePath().equals(file.getRemotePath())) { + cv.put( + ProviderTableMeta.FILE_PARENT, + targetParent.getFileId() + ); + } + operations.add( + ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). + withValues(cv). + withSelection( + ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(child.getFileId()) } + ) + .build()); + + } while (c.moveToNext()); + } + c.close(); + + /// 3. apply updates in batch + try { + if (getContentResolver() != null) { + getContentResolver().applyBatch(MainApp.getAuthority(), operations); + + } else { + getContentProviderClient().applyBatch(operations); + } + + } catch (Exception e) { + Log_OC.e( + TAG, + "Fail to update " + file.getFileId() + " and descendants in database", + e + ); + } + + /// 4. move in local file system + String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file); + File localFile = new File(localPath); + boolean renamed = false; + if (localFile.exists()) { + File targetFile = new File(defaultSavePath + targetPath); + File targetFolder = targetFile.getParentFile(); + if (!targetFolder.exists()) { + targetFolder.mkdirs(); + } + renamed = localFile.renameTo(targetFile); + } + Log_OC.d(TAG, "Local file RENAMED : " + renamed); + + } + + } + + private Vector getFolderContent(long parentId) { Vector ret = new Vector(); @@@ -1302,4 -1422,5 +1422,5 @@@ */ //} } + } diff --combined src/com/owncloud/android/files/FileOperationsHelper.java index 1bc19309,62b49006..e1ab1953 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@@ -34,11 -34,11 +34,11 @@@ import com.owncloud.android.files.servi import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.WebdavUtils; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.services.OperationsService; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.dialog.ShareLinkToDialog; -import com.owncloud.android.utils.Log_OC; /** * @@@ -265,7 -265,24 +265,24 @@@ public class FileOperationsHelper } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) { uploaderBinder.cancel(account, file); } - } + } + + /** + * Start move file operation + * @param newfile File where it is going to be moved + * @param currentFile File with the previous info + */ + public void moveFile(OCFile newfile, OCFile currentFile) { + // Move files + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_MOVE_FILE); + service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath()); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); + + mFileActivity.showLoadingDialog(); + } public long getOpIdWaitingFor() { diff --combined src/com/owncloud/android/files/services/FileUploader.java index 012b40b4,1984593f..5b7185ac --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@@ -46,6 -46,7 +46,7 @@@ import android.support.v4.app.Notificat import android.webkit.MimeTypeMap; import com.owncloud.android.R; + import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@@ -58,7 -59,6 +59,7 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; @@@ -72,6 -72,7 +73,6 @@@ import com.owncloud.android.operations. import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.utils.ErrorMessageAdapter; -import com.owncloud.android.utils.Log_OC; @@@ -185,6 -186,9 +186,9 @@@ public class FileUploader extends Servi return Service.START_NOT_STICKY; } Account account = intent.getParcelableExtra(KEY_ACCOUNT); + if (!AccountUtils.exists(account, getApplicationContext())) { + return Service.START_NOT_STICKY; + } String[] localPaths = null, remotePaths = null, mimeTypes = null; OCFile[] files = null; diff --combined src/com/owncloud/android/services/OperationsService.java index 2617ca9a,4ce9660e..a5bb22db --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@@ -35,7 -35,6 +35,7 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; @@@ -43,11 -42,13 +43,12 @@@ import com.owncloud.android.operations. import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.GetServerInfoOperation; + import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.OAuth2GetAccessToken; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.UnshareLinkOperation; -import com.owncloud.android.utils.Log_OC; import android.accounts.Account; import android.accounts.AccountsException; @@@ -79,6 -80,7 +80,7 @@@ public class OperationsService extends public static final String EXTRA_CREATE_FULL_PATH = "CREATE_FULL_PATH"; public static final String EXTRA_SYNC_FILE_CONTENTS = "SYNC_FILE_CONTENTS"; public static final String EXTRA_RESULT = "RESULT"; + public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH"; // TODO review if ALL OF THEM are necessary public static final String EXTRA_SUCCESS_IF_ABSENT = "SUCCESS_IF_ABSENT"; @@@ -97,6 -99,7 +99,7 @@@ public static final String ACTION_REMOVE = "REMOVE"; public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER"; public static final String ACTION_SYNC_FILE = "SYNC_FILE"; + public static final String ACTION_MOVE_FILE = "MOVE_FILE"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; @@@ -375,6 -378,11 +378,11 @@@ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true); operation = new SynchronizeFileOperation(remotePath, account, syncFileContents, getApplicationContext()); + } else if (action.equals(ACTION_MOVE_FILE)) { + // Move file/folder + String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH); + operation = new MoveFileOperation(remotePath,newParentPath,account); } } diff --combined src/com/owncloud/android/ui/activity/FileActivity.java index 511eac5f,68754d7a..136bdb55 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@@ -52,7 -52,6 +52,7 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.UnshareLinkOperation; @@@ -60,6 -59,7 +60,6 @@@ import com.owncloud.android.services.Op import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.dialog.LoadingDialog; import com.owncloud.android.utils.ErrorMessageAdapter; -import com.owncloud.android.utils.Log_OC; /** @@@ -80,6 -80,8 +80,8 @@@ implements OnRemoteOperationListener, C private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT"; private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";; + protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200; + /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located. */ private Account mAccount; @@@ -506,11 -508,12 +508,12 @@@ } - private void updateFileFromDB(){ - OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath()); - if (file != null) { - setFile(file); - } + protected void updateFileFromDB(){ + OCFile file = getFile(); + if (file != null) { + file = getStorageManager().getFileByPath(file.getRemotePath()); + setFile(file); + } } /** diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 8cd43745,63298334..69d44212 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -21,6 -21,8 +21,8 @@@ package com.owncloud.android.ui.activit import java.io.File; import java.io.IOException; + import org.apache.commons.httpclient.methods.PostMethod; + import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; @@@ -48,6 -50,7 +50,7 @@@ import android.provider.MediaStore import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; + import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@@ -61,7 -64,6 +64,7 @@@ import com.actionbarsherlock.view.Menu import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; +import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; @@@ -78,9 -80,9 +81,10 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateShareOperation; + import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; @@@ -100,6 -102,7 +104,6 @@@ import com.owncloud.android.ui.preview. import com.owncloud.android.ui.preview.PreviewVideoActivity; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; -import com.owncloud.android.utils.Log_OC; /** @@@ -110,8 -113,9 +114,9 @@@ */ public class FileDisplayActivity extends HookActivity implements - FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener { - + FileFragment.ContainerActivity, OnNavigationListener, + OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener { + private ArrayAdapter mDirectories; private SyncBroadcastReceiver mSyncBroadcastReceiver; @@@ -135,6 -139,7 +140,7 @@@ private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1; private static final int ACTION_SELECT_MULTIPLE_FILES = 2; + public static final int ACTION_MOVE_FILES = 3; private static final String TAG = FileDisplayActivity.class.getSimpleName(); @@@ -287,7 -292,7 +293,7 @@@ if (listOfFiles != null) { listOfFiles.listDirectory(getCurrentDir()); } else { - Log.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); + Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } /// Second fragment @@@ -303,12 -308,12 +309,12 @@@ } } else { - Log.wtf(TAG, "initFragments() called with invalid NULLs!"); + Log_OC.wtf(TAG, "initFragments() called with invalid NULLs!"); if (getAccount() == null) { - Log.wtf(TAG, "\t account is NULL"); + Log_OC.wtf(TAG, "\t account is NULL"); } if (getFile() == null) { - Log.wtf(TAG, "\t file is NULL"); + Log_OC.wtf(TAG, "\t file is NULL"); } } } @@@ -447,16 -452,6 +453,16 @@@ } @Override + public boolean onPrepareOptionsMenu(Menu menu) { + if (BuildConfig.DEBUG) { + menu.findItem(R.id.action_logger).setVisible(true); + } else { + menu.findItem(R.id.action_logger).setVisible(false); + } + return super.onPrepareOptionsMenu(menu); + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSherlock().getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); @@@ -486,11 -481,6 +492,11 @@@ startActivity(settingsIntent); break; } + case R.id.action_logger: { + Intent loggerIntent = new Intent(getApplicationContext(),LogHistoryActivity.class); + startActivity(loggerIntent); + break; + } case android.R.id.home: { FileFragment second = getSecondFragment(); OCFile currentDir = getCurrentDir(); @@@ -566,6 -556,20 +572,20 @@@ } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) { requestMultipleUpload(data, resultCode); + } else if (requestCode == ACTION_MOVE_FILES && (resultCode == RESULT_OK || + resultCode == MoveActivity.RESULT_OK_AND_MOVE)){ + + final Intent fData = data; + final int fResultCode = resultCode; + getHandler().postDelayed( + new Runnable() { + @Override + public void run() { + requestMoveOperation(fData, fResultCode); + } + }, + DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS + ); } } @@@ -646,6 -650,18 +666,18 @@@ startService(i); } + /** + * Request the operation for moving the file/folder from one path to another + * + * @param data Intent received + * @param resultCode Result code received + */ + private void requestMoveOperation(Intent data, int resultCode) { + OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(MoveActivity.EXTRA_CURRENT_FOLDER); + OCFile targetFile = (OCFile) data.getParcelableExtra(MoveActivity.EXTRA_TARGET_FILE); + getFileOperationsHelper().moveFile(folderToMoveAt, targetFile); + } + @Override public void onBackPressed() { OCFileListFragment listOfFiles = getListOfFilesFragment(); @@@ -1010,7 -1026,7 +1042,7 @@@ } ocFileListFragment.setMessageForEmptyList(getString(message)); } else { - Log.e(TAG, "OCFileListFragment is null"); + Log_OC.e(TAG, "OCFileListFragment is null"); } } @@@ -1331,7 -1347,9 +1363,9 @@@ } else if (operation instanceof UnshareLinkOperation) { onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); - } + } else if (operation instanceof MoveFileOperation) { + onMoveFileOperationFinish((MoveFileOperation)operation, result); + } } @@@ -1410,12 -1428,13 +1444,13 @@@ /** - * Updates the view associated to the activity after the finish of an operation trying create a new folder + * Updates the view associated to the activity after the finish of an operation trying to move a + * file. * - * @param operation Creation operation performed. - * @param result Result of the creation. + * @param operation Move operation performed. + * @param result Result of the move operation. */ - private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) { + private void onMoveFileOperationFinish(MoveFileOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { dismissLoadingDialog(); refreshListOfFilesFragment(); @@@ -1502,6 -1521,30 +1537,30 @@@ } } + /** + * Updates the view associated to the activity after the finish of an operation trying create a new folder + * + * @param operation Creation operation performed. + * @param result Result of the creation. + */ + private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) { + if (result.isSuccess()) { + dismissLoadingDialog(); + refreshListOfFilesFragment(); + } else { + dismissLoadingDialog(); + try { + Toast msg = Toast.makeText(FileDisplayActivity.this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log_OC.e(TAG, "Error while trying to show fail message " , e); + } + } + } + /** * {@inheritDoc} @@@ -1670,4 -1713,17 +1729,17 @@@ onTransferStateChanged(file, false, false); } + @Override + public void onRefresh() { + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { + OCFile folder = listOfFiles.getCurrentFile(); + if (folder != null) { + /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId()); + listDirectory(mFile);*/ + startSyncFolderOperation(folder); + } + } + } + } diff --combined src/com/owncloud/android/ui/activity/MoveActivity.java index 00000000,be8fce1a..c6025c4c mode 000000,100644..100644 --- a/src/com/owncloud/android/ui/activity/MoveActivity.java +++ b/src/com/owncloud/android/ui/activity/MoveActivity.java @@@ -1,0 -1,568 +1,568 @@@ + /* ownCloud Android client application + * Copyright (C) 2012-2014 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + package com.owncloud.android.ui.activity; + + import java.io.IOException; + + import android.accounts.Account; + import android.accounts.AccountManager; + import android.accounts.AuthenticatorException; + import android.accounts.OperationCanceledException; + import android.content.BroadcastReceiver; + import android.content.Context; + import android.content.Intent; + import android.content.IntentFilter; + import android.content.res.Resources.NotFoundException; + import android.os.Bundle; + import android.support.v4.app.Fragment; + import android.support.v4.app.FragmentTransaction; + import android.support.v4.widget.SwipeRefreshLayout; + import android.util.Log; + import android.view.View; + import android.view.View.OnClickListener; + import android.widget.Button; + import android.widget.Toast; + + import com.actionbarsherlock.app.ActionBar; + import com.actionbarsherlock.view.Menu; + import com.actionbarsherlock.view.MenuInflater; + import com.actionbarsherlock.view.MenuItem; + import com.actionbarsherlock.view.Window; + import com.owncloud.android.R; + import com.owncloud.android.datamodel.OCFile; + import com.owncloud.android.lib.common.OwnCloudAccount; + import com.owncloud.android.lib.common.OwnCloudClient; + import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; + import com.owncloud.android.lib.common.OwnCloudCredentials; + import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; + import com.owncloud.android.lib.common.operations.RemoteOperation; + import com.owncloud.android.lib.common.operations.RemoteOperationResult; + import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; + import com.owncloud.android.operations.CreateFolderOperation; + import com.owncloud.android.operations.SynchronizeFolderOperation; + import com.owncloud.android.syncadapter.FileSyncAdapter; + import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; + import com.owncloud.android.ui.fragment.FileFragment; + import com.owncloud.android.ui.fragment.OCFileListFragment; + import com.owncloud.android.utils.DisplayUtils; + import com.owncloud.android.utils.ErrorMessageAdapter; -import com.owncloud.android.utils.Log_OC; ++import com.owncloud.android.lib.common.utils.Log_OC; + + public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity, + OnClickListener, SwipeRefreshLayout.OnRefreshListener { + + public static final String EXTRA_CURRENT_FOLDER = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CURRENT_FOLDER"; + public static final String EXTRA_TARGET_FILE = UploadFilesActivity.class.getCanonicalName() + "EXTRA_TARGET_FILE"; + + public static final int RESULT_OK_AND_MOVE = 1; + + private SyncBroadcastReceiver mSyncBroadcastReceiver; + + private static final String TAG = MoveActivity.class.getSimpleName(); + + private static final String TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS"; + + private boolean mSyncInProgress = false; + + private Button mCancelBtn; + private Button mChooseBtn; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + Log_OC.d(TAG, "onCreate() start"); + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + + super.onCreate(savedInstanceState); + + setContentView(R.layout.files_move); + + if (savedInstanceState == null) { + createFragments(); + } + + // sets callback listeners for UI elements + initControls(); + + // Action bar setup + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + setSupportProgressBarIndeterminateVisibility(mSyncInProgress); + // always AFTER setContentView(...) ; to work around bug in its implementation + + // sets message for empty list of folders + setBackgroundText(); + + Log_OC.d(TAG, "onCreate() end"); + + } + + @Override + protected void onStart() { + super.onStart(); + getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId()); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + /** + * Called when the ownCloud {@link Account} associated to the Activity was just updated. + */ + @Override + protected void onAccountSet(boolean stateWasRecovered) { + super.onAccountSet(stateWasRecovered); + if (getAccount() != null) { + + updateFileFromDB(); + + OCFile folder = getFile(); + if (folder == null || !folder.isFolder()) { + // fall back to root folder + setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH)); + folder = getFile(); + } + + if (!stateWasRecovered) { + OCFileListFragment listOfFolders = getListOfFilesFragment(); + listOfFolders.listDirectory(folder); + + startSyncFolderOperation(folder); + } + + updateNavigationElementsInActionBar(); + } + } + + private void createFragments() { + OCFileListFragment listOfFiles = new OCFileListFragment(); + Bundle args = new Bundle(); + args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true); + args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, false); + listOfFiles.setArguments(args); + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS); + transaction.commit(); + } + + /** + * Show a text message on screen view for notifying user if content is + * loading or folder is empty + */ + private void setBackgroundText() { + OCFileListFragment listFragment = getListOfFilesFragment(); + if (listFragment != null) { + int message = R.string.file_list_loading; + if (!mSyncInProgress) { + // In case folder list is empty + message = R.string.file_list_empty_moving; + } + listFragment.setMessageForEmptyList(getString(message)); + } else { + Log.e(TAG, "OCFileListFragment is null"); + } + } + + private OCFileListFragment getListOfFilesFragment() { + Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(MoveActivity.TAG_LIST_OF_FOLDERS); + if (listOfFiles != null) { + return (OCFileListFragment)listOfFiles; + } + Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!"); + return null; + } + + + /** + * {@inheritDoc} + * + * Updates action bar and second fragment, if in dual pane mode. + */ + @Override + public void onBrowsedDownTo(OCFile directory) { + setFile(directory); + updateNavigationElementsInActionBar(); + // Sync Folder + startSyncFolderOperation(directory); + + } + + + public void startSyncFolderOperation(OCFile folder) { + long currentSyncTime = System.currentTimeMillis(); + + mSyncInProgress = true; + + // perform folder synchronization + RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder, + currentSyncTime, + false, + getFileOperationsHelper().isSharedSupported(), + getStorageManager(), + getAccount(), + getApplicationContext() + ); + synchFolderOp.execute(getAccount(), this, null, null); + + setSupportProgressBarIndeterminateVisibility(true); + + setBackgroundText(); + } + + @Override + protected void onResume() { + super.onResume(); + Log_OC.e(TAG, "onResume() start"); + + // refresh list of files + refreshListOfFilesFragment(); + + // Listen for sync messages + IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START); + syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END); + syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED); + syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); + syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); + mSyncBroadcastReceiver = new SyncBroadcastReceiver(); + registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); + + Log_OC.d(TAG, "onResume() end"); + } + + @Override + protected void onPause() { + Log_OC.e(TAG, "onPause() start"); + if (mSyncBroadcastReceiver != null) { + unregisterReceiver(mSyncBroadcastReceiver); + //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver); + mSyncBroadcastReceiver = null; + } + + Log_OC.d(TAG, "onPause() end"); + super.onPause(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getSherlock().getMenuInflater(); + inflater.inflate(R.menu.main_menu, menu); + menu.findItem(R.id.action_upload).setVisible(false); + menu.findItem(R.id.action_settings).setVisible(false); + menu.findItem(R.id.action_sync_account).setVisible(false); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + boolean retval = true; + switch (item.getItemId()) { + case R.id.action_create_dir: { + CreateFolderDialogFragment dialog = + CreateFolderDialogFragment.newInstance(getCurrentFolder()); + dialog.show( + getSupportFragmentManager(), + CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT + ); + break; + } + case android.R.id.home: { + OCFile currentDir = getCurrentFolder(); + if(currentDir != null && currentDir.getParentId() != 0) { + onBackPressed(); + } + break; + } + default: + retval = super.onOptionsItemSelected(item); + } + return retval; + } + + private OCFile getCurrentFolder() { + OCFile file = getFile(); + if (file != null) { + if (file.isFolder()) { + return file; + } else if (getStorageManager() != null) { + String parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName())); + return getStorageManager().getFileByPath(parentPath); + } + } + return null; + } + + protected void refreshListOfFilesFragment() { + OCFileListFragment fileListFragment = getListOfFilesFragment(); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + + public void browseToRoot() { + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { // should never be null, indeed + OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); + listOfFiles.listDirectory(root); + setFile(listOfFiles.getCurrentFile()); + updateNavigationElementsInActionBar(); + startSyncFolderOperation(root); + } + } + + @Override + public void onBackPressed() { + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { // should never be null, indeed + int levelsUp = listOfFiles.onBrowseUp(); + if (levelsUp == 0) { + finish(); + return; + } + setFile(listOfFiles.getCurrentFile()); + updateNavigationElementsInActionBar(); + } + } + + private void updateNavigationElementsInActionBar() { + ActionBar actionBar = getSupportActionBar(); + OCFile currentDir = getCurrentFolder(); + boolean atRoot = (currentDir == null || currentDir.getParentId() == 0); + actionBar.setDisplayHomeAsUpEnabled(!atRoot); + actionBar.setHomeButtonEnabled(!atRoot); + actionBar.setTitle( + atRoot + ? getString(R.string.default_display_name_for_root_folder) + : currentDir.getFileName() + ); + } + + /** + * Set per-view controllers + */ + private void initControls(){ + mCancelBtn = (Button) findViewById(R.id.move_files_btn_cancel); + mCancelBtn.setOnClickListener(this); + mChooseBtn = (Button) findViewById(R.id.move_files_btn_choose); + mChooseBtn.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + if (v == mCancelBtn) { + finish(); + } else if (v == mChooseBtn) { + Intent i = getIntent(); + OCFile targetFile = (OCFile) i.getParcelableExtra(MoveActivity.EXTRA_TARGET_FILE); + + Intent data = new Intent(); + data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder()); + data.putExtra(EXTRA_TARGET_FILE, targetFile); + setResult(RESULT_OK_AND_MOVE, data); + finish(); + } + } + + + @Override + public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { + super.onRemoteOperationFinish(operation, result); + + if (operation instanceof CreateFolderOperation) { + onCreateFolderOperationFinish((CreateFolderOperation)operation, result); + + } + } + + + /** + * Updates the view associated to the activity after the finish of an operation trying + * to create a new folder. + * + * @param operation Creation operation performed. + * @param result Result of the creation. + */ + private void onCreateFolderOperationFinish( + CreateFolderOperation operation, RemoteOperationResult result + ) { + + if (result.isSuccess()) { + dismissLoadingDialog(); + refreshListOfFilesFragment(); + } else { + dismissLoadingDialog(); + try { + Toast msg = Toast.makeText(MoveActivity.this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log_OC.e(TAG, "Error while trying to show fail message " , e); + } + } + } + + + + private class SyncBroadcastReceiver extends BroadcastReceiver { + + /** + * {@link BroadcastReceiver} to enable syncing feedback in UI + */ + @Override + public void onReceive(Context context, Intent intent) { + try { + String event = intent.getAction(); + Log_OC.d(TAG, "Received broadcast " + event); + String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME); + String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH); + RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncAdapter.EXTRA_RESULT); + boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); + + if (sameAccount) { + + if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { + mSyncInProgress = true; + + } else { + OCFile currentFile = (getFile() == null) ? null : getStorageManager().getFileByPath(getFile().getRemotePath()); + OCFile currentDir = (getCurrentFolder() == null) ? null : getStorageManager().getFileByPath(getCurrentFolder().getRemotePath()); + + if (currentDir == null) { + // current folder was removed from the server + Toast.makeText( MoveActivity.this, + String.format(getString(R.string.sync_current_folder_was_removed), getCurrentFolder().getFileName()), + Toast.LENGTH_LONG) + .show(); + browseToRoot(); + + } else { + if (currentFile == null && !getFile().isFolder()) { + // currently selected file was removed in the server, and now we know it + currentFile = currentDir; + } + + if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) { + OCFileListFragment fileListFragment = getListOfFilesFragment(); + if (fileListFragment != null) { + fileListFragment.listDirectory(currentDir); + } + } + setFile(currentFile); + } + + mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event)); + + if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. + equals(event) && + /// TODO refactor and make common + synchResult != null && !synchResult.isSuccess() && + (synchResult.getCode() == ResultCode.UNAUTHORIZED || + synchResult.isIdPRedirection() || + (synchResult.isException() && synchResult.getException() + instanceof AuthenticatorException))) { + + OwnCloudClient client = null; + try { + OwnCloudAccount ocAccount = + new OwnCloudAccount(getAccount(), context); + client = (OwnCloudClientManagerFactory.getDefaultSingleton(). + removeClientFor(ocAccount)); + // TODO get rid of these exceptions + } catch (AccountNotFoundException e) { + e.printStackTrace(); + } catch (AuthenticatorException e) { + e.printStackTrace(); + } catch (OperationCanceledException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + if (client != null) { + OwnCloudCredentials cred = client.getCredentials(); + if (cred != null) { + AccountManager am = AccountManager.get(context); + if (cred.authTokenExpires()) { + am.invalidateAuthToken( + getAccount().type, + cred.getAuthToken() + ); + } else { + am.clearPassword(getAccount()); + } + } + } + + requestCredentialsUpdate(); + + } + } + removeStickyBroadcast(intent); + Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); + setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); + + setBackgroundText(); + + } + + } catch (RuntimeException e) { + // avoid app crashes after changing the serial id of RemoteOperationResult + // in owncloud library with broadcast notifications pending to process + removeStickyBroadcast(intent); + } + } + } + + + + /** + * Shows the information of the {@link OCFile} received as a + * parameter in the second fragment. + * + * @param file {@link OCFile} whose details will be shown + */ + @Override + public void showDetails(OCFile file) { + + } + + /** + * {@inheritDoc} + */ + @Override + public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) { + + } + + + @Override + public void onRefresh() { + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { + OCFile folder = listOfFiles.getCurrentFile(); + if (folder != null) { + startSyncFolderOperation(folder); + } + } + } + + } diff --combined src/com/owncloud/android/ui/activity/Preferences.java index 0e3e199b,e726efad..9ac6e27b --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@@ -51,9 -51,9 +51,9 @@@ import com.owncloud.android.R import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.db.DbHandler; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.LongClickableCheckBoxPreference; import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.Log_OC; /** @@@ -66,13 -66,12 +66,10 @@@ public class Preferences extends Sherlo private static final String TAG = "OwnCloudPreferences"; - private static final String PREVIOUS_ACCOUNT_KEY = "ACCOUNT"; - private DbHandler mDbHandler; private CheckBoxPreference pCode; - //private CheckBoxPreference pLogging; - //private Preference pLoggingHistory; private Preference pAboutApp; - private Account mPreviousAccount = null; private PreferenceCategory mAccountsPrefCategory = null; private final Handler mHandler = new Handler(); private String mAccountName; @@@ -89,13 -88,8 +86,8 @@@ ActionBar actionBar = getSherlock().getActionBar(); actionBar.setIcon(DisplayUtils.getSeasonalIconId()); actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setTitle(R.string.actionbar_settings); - if (savedInstanceState != null) { - mPreviousAccount = savedInstanceState.getParcelable(PREVIOUS_ACCOUNT_KEY); - } else { - mPreviousAccount = AccountUtils.getCurrentOwnCloudAccount(this); - } - // Load the accounts category for adding the list of accounts mAccountsPrefCategory = (PreferenceCategory) findPreference("accounts_category"); @@@ -260,6 -254,44 +252,6 @@@ Log_OC.e(TAG, "Error while showing about dialog", e); } } - - /* DISABLED FOR RELEASE UNTIL FIXED - pLogging = (CheckBoxPreference) findPreference("log_to_file"); - if (pLogging != null) { - pLogging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - - String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log"; - - if(!pLogging.isChecked()) { - Log_OC.d("Debug", "start logging"); - Log_OC.v("PATH", logpath); - Log_OC.startLogging(logpath); - } - else { - Log_OC.d("Debug", "stop logging"); - Log_OC.stopLogging(); - } - return true; - } - }); - } - - pLoggingHistory = (Preference) findPreference("log_history"); - if (pLoggingHistory != null) { - pLoggingHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - Intent intent = new Intent(getApplicationContext(),LogHistoryActivity.class); - startActivity(intent); - return true; - } - }); - } - */ - } @Override @@@ -414,8 -446,23 +406,23 @@@ for (Account a : accounts) { CheckBoxPreference p = (CheckBoxPreference) findPreference(a.name); if (key.equals(a.name)) { + boolean accountChanged = !p.isChecked(); p.setChecked(true); - AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), a.name); + AccountUtils.setCurrentOwnCloudAccount( + getApplicationContext(), + a.name + ); + if (accountChanged) { + // restart the main activity + Intent i = new Intent( + Preferences.this, + FileDisplayActivity.class + ); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(i); + } else { + finish(); + } } else { p.setChecked(false); } @@@ -455,22 -502,4 +462,4 @@@ } - @Override - protected void onPause() { - if (this.isFinishing()) { - Account current = AccountUtils.getCurrentOwnCloudAccount(this); - if ((mPreviousAccount == null && current != null) - || (mPreviousAccount != null && !mPreviousAccount.equals(current))) { - // the account set as default changed since this activity was - // created - - // restart the main activity - Intent i = new Intent(this, FileDisplayActivity.class); - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(i); - } - } - super.onPause(); - } - } diff --combined src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index d5c01b44,abd53d3a..45a6aafe --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@@ -18,6 -18,8 +18,8 @@@ package com.owncloud.android.ui.fragment; + import java.util.ArrayList; + import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; @@@ -31,17 -33,23 +33,23 @@@ import android.widget.TextView import com.actionbarsherlock.app.SherlockFragment; import com.owncloud.android.R; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.ExtendedListView; -import com.owncloud.android.utils.Log_OC; /** * TODO extending SherlockListFragment instead of SherlockFragment */ - public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener{ + public class ExtendedListFragment extends SherlockFragment + implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { private static final String TAG = ExtendedListFragment.class.getSimpleName(); private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION"; + private static final String KEY_INDEXES = "INDEXES"; + private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS"; + private static final String KEY_TOPS = "TOPS"; + private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL"; + private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE"; protected ExtendedListView mList; @@@ -49,6 -57,15 +57,15 @@@ private SwipeRefreshLayout mRefreshEmptyLayout; private TextView mEmptyListMessage; + // Save the state of the scroll in browsing + private ArrayList mIndexes; + private ArrayList mFirstPositions; + private ArrayList mTops; + private int mHeightCell = 0; + + private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null; + + public void setListAdapter(ListAdapter listAdapter) { mList.setAdapter(listAdapter); mList.invalidate(); @@@ -62,7 -79,6 +79,6 @@@ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.e(TAG, "onCreateView"); - //mList = new ExtendedListView(getActivity()); View v = inflater.inflate(R.layout.list_fragment, null); mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view); @@@ -90,11 -106,39 +106,39 @@@ } + /** + * {@inheritDoc} + */ + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + if (savedInstanceState != null) { + mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES); + mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS); + mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS); + mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL); + setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE)); + + } else { + mIndexes = new ArrayList(); + mFirstPositions = new ArrayList(); + mTops = new ArrayList(); + mHeightCell = 0; + } + } + + @Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); Log_OC.e(TAG, "onSaveInstanceState()"); savedInstanceState.putInt(KEY_SAVED_LIST_POSITION, getReferencePosition()); + savedInstanceState.putIntegerArrayList(KEY_INDEXES, mIndexes); + savedInstanceState.putIntegerArrayList(KEY_FIRST_POSITIONS, mFirstPositions); + savedInstanceState.putIntegerArrayList(KEY_TOPS, mTops); + savedInstanceState.putInt(KEY_HEIGHT_CELL, mHeightCell); + savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText()); } @@@ -126,6 -170,60 +170,60 @@@ } } + + /* + * Restore index and position + */ + protected void restoreIndexAndTopPosition() { + if (mIndexes.size() > 0) { + // needs to be checked; not every browse-up had a browse-down before + + int index = mIndexes.remove(mIndexes.size() - 1); + + int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1); + + int top = mTops.remove(mTops.size() - 1); + + mList.setSelectionFromTop(firstPosition, top); + + // Move the scroll if the selection is not visible + int indexPosition = mHeightCell*index; + int height = mList.getHeight(); + + if (indexPosition > height) { + if (android.os.Build.VERSION.SDK_INT >= 11) + { + mList.smoothScrollToPosition(index); + } + else if (android.os.Build.VERSION.SDK_INT >= 8) + { + mList.setSelectionFromTop(index, 0); + } + + } + } + } + + /* + * Save index and top position + */ + protected void saveIndexAndTopPosition(int index) { + + mIndexes.add(index); + + int firstPosition = mList.getFirstVisiblePosition(); + mFirstPositions.add(firstPosition); + + View view = mList.getChildAt(0); + int top = (view == null) ? 0 : view.getTop() ; + + mTops.add(top); + + // Save the height of a cell + mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight(); + } + + @Override public void onItemClick (AdapterView parent, View view, int position, long id) { // to be @overriden @@@ -136,7 -234,16 +234,16 @@@ // to be @overriden mRefreshLayout.setRefreshing(false); mRefreshEmptyLayout.setRefreshing(false); + + if (mOnRefreshListener != null) { + mOnRefreshListener.onRefresh(); + } + } + + public void setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener) { + mOnRefreshListener = listener; } + /** * Enables swipe gesture diff --combined src/com/owncloud/android/ui/fragment/FileDetailFragment.java index b7c2d6ac,3506b6b5..2ff29250 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@@ -41,13 -41,13 +41,13 @@@ import com.owncloud.android.files.FileM import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.Log_OC; /** @@@ -191,6 -191,13 +191,13 @@@ public class FileDetailFragment extend item.setVisible(false); item.setEnabled(false); } + + // additional restriction for this fragment + item = menu.findItem(R.id.action_move); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } } diff --combined src/com/owncloud/android/ui/fragment/LocalFileListFragment.java index fe14145e,c6d562c9..a9b6ad2c --- a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@@ -31,8 -31,8 +31,8 @@@ import android.widget.ImageView import android.widget.ListView; import com.owncloud.android.R; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.adapter.LocalFileListAdapter; -import com.owncloud.android.utils.Log_OC; /** @@@ -90,7 -90,7 +90,7 @@@ public class LocalFileListFragment exte public void onActivityCreated(Bundle savedInstanceState) { Log_OC.i(TAG, "onActivityCreated() start"); - super.onCreate(savedInstanceState); + super.onActivityCreated(savedInstanceState); mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity()); setListAdapter(mAdapter); @@@ -111,6 -111,8 +111,8 @@@ listDirectory(file); // notify the click to container Activity mContainerActivity.onDirectoryClick(file); + // save index and top position + saveIndexAndTopPosition(position); } else { /// Click on a file ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox); @@@ -140,6 -142,9 +142,9 @@@ parentDir = mDirectory.getParentFile(); // can be null } listDirectory(parentDir); + + // restore index and top position + restoreIndexAndTopPosition(); } diff --combined src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 85838e6f,c11e864e..099e442f --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -18,10 -18,11 +18,11 @@@ package com.owncloud.android.ui.fragment; import java.io.File; - import java.util.ArrayList; import android.app.Activity; + import android.content.Intent; import android.os.Bundle; + import android.support.v4.widget.SwipeRefreshLayout; import android.view.ContextMenu; import android.view.MenuInflater; import android.view.MenuItem; @@@ -33,14 -34,15 +34,15 @@@ import com.owncloud.android.R import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileMenuFilter; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.activity.FileDisplayActivity; + import com.owncloud.android.ui.activity.MoveActivity; import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; -import com.owncloud.android.utils.Log_OC; /** * A Fragment that lists all files and folders in a given path. @@@ -55,15 -57,14 +57,14 @@@ public class OCFileListFragment extend private static final String TAG = OCFileListFragment.class.getSimpleName(); - private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment"; - private static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE"; + private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? + OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment"; + + public final static String ARG_JUST_FOLDERS = MY_PACKAGE + ".JUST_FOLDERS"; + public final static String ARG_ALLOW_CONTEXTUAL_ACTIONS = MY_PACKAGE + ".ALLOW_CONTEXTUAL"; + + private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE"; - private static final String KEY_INDEXES = "INDEXES"; - private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS"; - private static final String KEY_TOPS = "TOPS"; - private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL"; - private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE"; - private FileFragment.ContainerActivity mContainerActivity; private OCFile mFile = null; @@@ -71,12 -72,6 +72,6 @@@ private OCFile mTargetFile; - // Save the state of the scroll in browsing - private ArrayList mIndexes; - private ArrayList mFirstPositions; - private ArrayList mTops; - - private int mHeightCell = 0; /** * {@inheritDoc} @@@ -87,15 -82,24 +82,24 @@@ Log_OC.e(TAG, "onAttach"); try { mContainerActivity = (FileFragment.ContainerActivity) activity; + } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName()); } + try { + setOnRefreshListener((SwipeRefreshLayout.OnRefreshListener) activity); + + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + " must implement " + + SwipeRefreshLayout.OnRefreshListener.class.getSimpleName()); + } } @Override public void onDetach() { + setOnRefreshListener(null); mContainerActivity = null; super.onDetach(); } @@@ -108,26 -112,17 +112,17 @@@ super.onActivityCreated(savedInstanceState); Log_OC.e(TAG, "onActivityCreated() start"); - mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity); - if (savedInstanceState != null) { - mFile = savedInstanceState.getParcelable(EXTRA_FILE); - mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES); - mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS); - mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS); - mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL); - setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE)); - - } else { - mIndexes = new ArrayList(); - mFirstPositions = new ArrayList(); - mTops = new ArrayList(); - mHeightCell = 0; - + mFile = savedInstanceState.getParcelable(KEY_FILE); } - mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity); - + Bundle args = getArguments(); + boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false); + mAdapter = new FileListListAdapter( + justFolders, + getSherlockActivity(), + mContainerActivity + ); setListAdapter(mAdapter); registerForContextMenu(getListView()); @@@ -140,19 -135,14 +135,14 @@@ @Override public void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); - outState.putParcelable(EXTRA_FILE, mFile); - outState.putIntegerArrayList(KEY_INDEXES, mIndexes); - outState.putIntegerArrayList(KEY_FIRST_POSITIONS, mFirstPositions); - outState.putIntegerArrayList(KEY_TOPS, mTops); - outState.putInt(KEY_HEIGHT_CELL, mHeightCell); - outState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText()); + outState.putParcelable(KEY_FILE, mFile); } /** * Call this, when the user presses the up button. * - * Tries to move up the current folder one level. If the parent folder was removed from the database, - * it continues browsing up until finding an existing folders. + * Tries to move up the current folder one level. If the parent folder was removed from the + * database, it continues browsing up until finding an existing folders. * * return Count of folder levels browsed up. */ @@@ -166,25 -156,25 +156,25 @@@ String parentPath = null; if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) { parentPath = new File(mFile.getRemotePath()).getParent(); - parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR; + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : + parentPath + OCFile.PATH_SEPARATOR; parentDir = storageManager.getFileByPath(parentPath); moveCount++; } else { - parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH); // never returns null; keep the path in root folder + parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH); } while (parentDir == null) { parentPath = new File(parentPath).getParent(); - parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR; + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : + parentPath + OCFile.PATH_SEPARATOR; parentDir = storageManager.getFileByPath(parentPath); moveCount++; } // exit is granted because storageManager.getFileByPath("/") never returns null - mFile = parentDir; - } - - if (mFile != null) { + mFile = parentDir; + listDirectory(mFile); - ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile); + onRefresh(); // restore index and top position restoreIndexAndTopPosition(); @@@ -194,58 -184,6 +184,6 @@@ return moveCount; } - /* - * Restore index and position - */ - private void restoreIndexAndTopPosition() { - if (mIndexes.size() > 0) { - // needs to be checked; not every browse-up had a browse-down before - - int index = mIndexes.remove(mIndexes.size() - 1); - - int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1); - - int top = mTops.remove(mTops.size() - 1); - - mList.setSelectionFromTop(firstPosition, top); - - // Move the scroll if the selection is not visible - int indexPosition = mHeightCell*index; - int height = mList.getHeight(); - - if (indexPosition > height) { - if (android.os.Build.VERSION.SDK_INT >= 11) - { - mList.smoothScrollToPosition(index); - } - else if (android.os.Build.VERSION.SDK_INT >= 8) - { - mList.setSelectionFromTop(index, 0); - } - - } - } - } - - /* - * Save index and top position - */ - private void saveIndexAndTopPosition(int index) { - - mIndexes.add(index); - - int firstPosition = mList.getFirstVisiblePosition(); - mFirstPositions.add(firstPosition); - - View view = mList.getChildAt(0); - int top = (view == null) ? 0 : view.getTop() ; - - mTops.add(top); - - // Save the height of a cell - mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight(); - } - @Override public void onItemClick(AdapterView l, View v, int position, long id) { OCFile file = (OCFile) mAdapter.getItem(position); @@@ -253,7 -191,7 +191,7 @@@ if (file.isFolder()) { // update state and view of this fragment listDirectory(file); - // then, notify parent activity to let it update its state and view, and other fragments + // then, notify parent activity to let it update its state and view mContainerActivity.onBrowsedDownTo(file); // save index and top position saveIndexAndTopPosition(position); @@@ -288,42 -226,46 +226,46 @@@ * {@inheritDoc} */ @Override - public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + public void onCreateContextMenu ( + ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - MenuInflater inflater = getSherlockActivity().getMenuInflater(); - inflater.inflate(R.menu.file_actions_menu, menu); - AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; - OCFile targetFile = (OCFile) mAdapter.getItem(info.position); - - if (mContainerActivity.getStorageManager() != null) { - FileMenuFilter mf = new FileMenuFilter( - targetFile, - mContainerActivity.getStorageManager().getAccount(), - mContainerActivity, - getSherlockActivity() - ); - mf.filter(menu); - } - - /// additional restrictions for this fragment - // TODO allow in the future 'open with' for previewable files - MenuItem item = menu.findItem(R.id.action_open_file_with); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - /// TODO break this direct dependency on FileDisplayActivity... if possible - FileFragment frag = ((FileDisplayActivity)getSherlockActivity()).getSecondFragment(); - if (frag != null && frag instanceof FileDetailFragment && - frag.getFile().getFileId() == targetFile.getFileId()) { - item = menu.findItem(R.id.action_see_details); + Bundle args = getArguments(); + boolean allowContextualActions = + (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); + if (allowContextualActions) { + MenuInflater inflater = getSherlockActivity().getMenuInflater(); + inflater.inflate(R.menu.file_actions_menu, menu); + AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; + OCFile targetFile = (OCFile) mAdapter.getItem(info.position); + + if (mContainerActivity.getStorageManager() != null) { + FileMenuFilter mf = new FileMenuFilter( + targetFile, + mContainerActivity.getStorageManager().getAccount(), + mContainerActivity, + getSherlockActivity() + ); + mf.filter(menu); + } + + /// additional restrictions for this fragment + // TODO allow in the future 'open with' for previewable files + MenuItem item = menu.findItem(R.id.action_open_file_with); if (item != null) { item.setVisible(false); item.setEnabled(false); } + /// TODO break this direct dependency on FileDisplayActivity... if possible + FileFragment frag = ((FileDisplayActivity)getSherlockActivity()).getSecondFragment(); + if (frag != null && frag instanceof FileDetailFragment && + frag.getFile().getFileId() == targetFile.getFileId()) { + item = menu.findItem(R.id.action_see_details); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } + } } - - } @@@ -378,6 -320,14 +320,14 @@@ } return true; } + case R.id.action_move: { + Intent action = new Intent(getActivity(), MoveActivity.class); + + // Pass mTargetFile that contains info of selected file/folder + action.putExtra(MoveActivity.EXTRA_TARGET_FILE, mTargetFile); + getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES); + return true; + } default: return super.onContextItemSelected(item); } @@@ -436,21 -386,4 +386,4 @@@ } } - - @Override - public void onRefresh() { - super.onRefresh(); - - if (mFile != null) { - // Refresh mFile - mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId()); - - listDirectory(mFile); - - ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile); - } - } - - - } diff --combined src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 81049d0a,fa3352d1..8e3afaf5 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@@ -44,10 -44,10 +44,10 @@@ import com.ortiz.touch.TouchImageView import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileMenuFilter; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; -import com.owncloud.android.utils.Log_OC; /** @@@ -231,6 -231,13 +231,13 @@@ public class PreviewImageFragment exten if (item != null) { item.setVisible(false); item.setEnabled(false); + } + + // additional restriction for this fragment + item = menu.findItem(R.id.action_move); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); } } diff --combined src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 1e901494,e91e64f2..ea412ced --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@@ -47,7 -47,6 +47,7 @@@ import com.actionbarsherlock.view.MenuI import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileMenuFilter; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.media.MediaControlView; import com.owncloud.android.media.MediaService; import com.owncloud.android.media.MediaServiceBinder; @@@ -55,6 -54,7 +55,6 @@@ import com.owncloud.android.ui.activity import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; -import com.owncloud.android.utils.Log_OC; /** @@@ -289,6 -289,13 +289,13 @@@ public class PreviewMediaFragment exten item.setVisible(false); item.setEnabled(false); } + + // additional restriction for this fragment + item = menu.findItem(R.id.action_move); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } }