Merge branch 'develop' into modify_password
authorDavid A. Velasco <dvelasco@solidgear.es>
Tue, 2 Jul 2013 11:08:27 +0000 (13:08 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 2 Jul 2013 11:08:27 +0000 (13:08 +0200)
1  2 
res/values/strings.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/ui/activity/AccountSelectActivity.java

diff --combined res/values/strings.xml
@@@ -51,7 -51,7 +51,7 @@@
      <string name="auth_host_url">Server address</string>
      <string name="auth_username">Username</string>
      <string name="auth_password">Password</string>
 -    <string name="auth_register">I am new to %1$s</string>
 +    <string name="auth_register">New to %1$s?</string>
      <string name="new_session_uri_error">Incorrect address given</string>
      <string name="new_session_session_name_error">Incorrect session name</string>
      <string name="sync_string_files">Files</string>
@@@ -95,7 -95,6 +95,7 @@@
      <string name="common_loading">Loading &#8230;</string>
      <string name="common_error_unknown">Unknown error</string>
      <string name="about_title">About</string>
 +    <string name="change_password">Change password</string>
      <string name="delete_account">Delete account</string>
      <string name="create_account">Create account</string>
      <string name="upload_chooser_title">Upload from &#8230;</string>
      <string name="sync_string_contacts">Contacts</string>
      <string name="sync_fail_ticker">Synchronization failed</string>
      <string name="sync_fail_content">Synchronization of %1$s could not be completed</string>
 -    <string name="sync_fail_content_unauthorized">Invalid credentials for %1$s</string>
 +    <string name="sync_fail_content_unauthorized">Invalid password for %1$s</string>
        <string name="sync_conflicts_in_favourites_ticker">Conflicts found</string>
        <string name="sync_conflicts_in_favourites_content">%1$d kept-in-sync files could not be sync\'ed</string>
      <string name="sync_fail_in_favourites_ticker">Kept-in-sync files failed</string>
      <string name="sync_fail_in_favourites_content">Contents of %1$d files could not be sync\'ed (%2$d conflicts)</string>
      <string name="sync_foreign_files_forgotten_ticker">Some local files were forgotten</string>
      <string name="sync_foreign_files_forgotten_content">%1$d files out of the %2$s directory could not be copied into</string>
-     <string name="sync_foreign_files_forgotten_explanation">"As of version 1.3.16, files uploaded from this device are copied into the local %1$s folder to prevent data loss when a single file is synced with multiple accounts.\n\nDue to this change, all files uploaded in previous versions of this app were copied into the %2$s folder. However, an error prevented the completion of this operation during account synchronization. You may either leave the file(s) as is and remove the link to %3$s, or move the file(s) into the %1$s directory and retain the link to %4$s.\n\nListed below are the local file(s), and the the remote file(s) in %5$s they were linked to.</string>
+     <string name="sync_foreign_files_forgotten_explanation">As of version 1.3.16, files uploaded from this device are copied into the local %1$s folder to prevent data loss when a single file is synced with multiple accounts.\n\nDue to this change, all files uploaded in previous versions of this app were copied into the %2$s folder. However, an error prevented the completion of this operation during account synchronization. You may either leave the file(s) as is and remove the link to %3$s, or move the file(s) into the %1$s directory and retain the link to %4$s.\n\nListed below are the local file(s), and the the remote file(s) in %5$s they were linked to.</string>
      <string name="foreign_files_move">"Move all"</string>
      <string name="foreign_files_success">"All files were moved"</string>
      <string name="foreign_files_fail">"Some files could not be moved"</string>
          <item>60</item>
      </string-array>
  
 -    <string name="auth_trying_to_login">Trying to login...</string>
 +    <string name="auth_trying_to_login">Trying to login&#8230;</string>
      <string name="auth_no_net_conn_title">No network connection</string>
      <string name="auth_no_net_conn_message">No network connection has been detected, check your Internet connection and try again.</string>
      <string name="auth_connect_anyway">Connect anyway</string>
      <string name="auth_nossl_plain_ok_title">Secure connection unavailable.</string>
      <string name="auth_nossl_plain_ok_message">The Application cannot establish a secure connection to the server. A non secure connection is available. You may continue or cancel.</string>
      <string name="auth_connection_established">Connection established</string>
 -    <string name="auth_testing_connection">Testing connection...</string>
 +    <string name="auth_testing_connection">Testing connection&#8230;</string>
      <string name="auth_not_configured_title">Malformed server configuration</string>
      <string name="auth_not_configured_message">It seems that your server instance is not correctly configured. Contact your administrator for more details.</string>
      <string name="auth_unknown_error_title">Unknown error occurred!</string>
      <string name="auth_bad_oc_version_title">Unrecognized server version</string>
      <string name="auth_wrong_connection_title">Couldn\'t establish connection</string>
      <string name="auth_secure_connection">Secure connection established</string>
 -    <string name="auth_unauthorized">Invalid credentials</string>
 +    <string name="auth_unauthorized">Wrong username or password</string>
        <string name="auth_oauth_error">Unsuccessful authorization</string>
        <string name="auth_oauth_error_access_denied">Access denied by authorization server</string>
      <string name="auth_not_found">Wrong path given</string>
      <string name="auth_internal">Internal server error, code %1$d</string>
      <string name="auth_wtf_reenter_URL">Unexpected state; please, enter the server URL again</string>
      <string name="auth_expired_oauth_token_toast">Your authorization expired.\nPlease, authorize again</string>
 -    <string name="auth_expired_basic_auth_toast">Your saved credentials are invalid.\nPlease, enter the current credentials</string>
 +    <string name="auth_expired_basic_auth_toast">Please, enter the current password</string>
      
      <string name="crashlog_message">Application terminated unexpectedly. Would you like to submit a crash report?</string>
      <string name="crashlog_send_report">Send report</string>
@@@ -18,9 -18,6 +18,6 @@@
  \r
  package com.owncloud.android.authentication;\r
  \r
- import java.security.spec.MGF1ParameterSpec;\r
\r
- import com.owncloud.android.AccountUtils;\r
  import com.owncloud.android.Log_OC;\r
  import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
  import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
@@@ -63,7 -60,6 +60,7 @@@ import android.view.inputmethod.EditorI
  import android.widget.CheckBox;\r
  import android.widget.EditText;\r
  import android.widget.Button;\r
 +import android.widget.ImageButton;\r
  import android.widget.TextView;\r
  import android.widget.Toast;\r
  import android.widget.TextView.OnEditorActionListener;\r
@@@ -87,7 -83,6 +84,7 @@@ implements  OnRemoteOperationListener, 
      public static final String EXTRA_USER_NAME = "USER_NAME";\r
      public static final String EXTRA_HOST_NAME = "HOST_NAME";\r
      public static final String EXTRA_ACTION = "ACTION";\r
 +    public static final String EXTRA_ENFORCED_UPDATE = "ENFORCE_UPDATE";\r
  \r
      private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
      private static final String KEY_OC_VERSION = "OC_VERSION";\r
  \r
      public static final byte ACTION_CREATE = 0;\r
      public static final byte ACTION_UPDATE_TOKEN = 1;\r
 -    \r
 +\r
      private String mHostBaseUrl;\r
      private OwnCloudVersion mDiscoveredVersion;\r
  \r
      private Account mAccount;\r
  \r
      private EditText mHostUrlInput;\r
 +    private ImageButton mRefreshButton;\r
      private EditText mUsernameInput;\r
      private EditText mPasswordInput;\r
      private CheckBox mOAuth2Check;\r
          /// set view and get references to view elements\r
          setContentView(R.layout.account_setup);\r
          mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);\r
 +        mRefreshButton = (ImageButton) findViewById(R.id.refeshButton);\r
          mUsernameInput = (EditText) findViewById(R.id.account_username);\r
          mPasswordInput = (EditText) findViewById(R.id.account_password);\r
          mOAuthAuthEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_1);\r
          mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE); \r
          mAccount = null;\r
          mHostBaseUrl = "";\r
 +        boolean refreshButtonEnabled = false;\r
  \r
          if (savedInstanceState == null) {\r
              /// connection state and info\r
              }\r
              mOAuth2Check.setChecked(oAuthRequired);\r
              changeViewByOAuth2Check(oAuthRequired);\r
 -\r
 +            mJustCreated = true;\r
 +            \r
 +            if (mAction == ACTION_UPDATE_TOKEN) {\r
 +                checkOcServer(); \r
 +            }\r
  \r
          } else {\r
              /// connection state and info\r
              }            \r
              \r
              // refresh button enabled\r
 -            mRefreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED);\r
 +            refreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED);\r
 +            \r
  \r
          }\r
  \r
          showServerStatus();\r
          showAuthStatus();\r
 -        if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();\r
 -        mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 -\r
 -        if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
 -            mOAuth2Check.setVisibility(View.GONE);\r
 -        }\r
  \r
          if (mAction == ACTION_UPDATE_TOKEN) {\r
              /// lock things that should not change\r
              mHostUrlInput.setEnabled(false);\r
 +            mHostUrlInput.setFocusable(false);\r
              mUsernameInput.setEnabled(false);\r
 +            mUsernameInput.setFocusable(false);\r
 +            mOAuth2Check.setVisibility(View.GONE);\r
 +        }\r
 +        \r
 +        //if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();\r
 +        if (mServerIsChecked && !mServerIsValid && refreshButtonEnabled) showRefreshButton();\r
 +        mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 +\r
 +        if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
              mOAuth2Check.setVisibility(View.GONE);\r
 -            if (!mServerIsValid && mOcServerChkOperation == null) {\r
 -                checkOcServer(); \r
 -            }\r
          }\r
  \r
          mPasswordInput.setText("");     // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)\r
 -        mJustCreated = true;\r
  \r
          /// bind view elements to listeners\r
          mHostUrlInput.setOnFocusChangeListener(this);\r
 -        mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
 -            @Override\r
 -            public boolean onDrawableTouch(final MotionEvent event) {\r
 -                if (event.getAction() == MotionEvent.ACTION_UP) {\r
 -                    AuthenticatorActivity.this.onRefreshClick();\r
 -                }\r
 -                return true;\r
 -            }\r
 -        });\r
          mHostUrlInput.addTextChangedListener(new TextWatcher() {\r
  \r
              @Override\r
          }\r
          \r
          // refresh button enabled\r
 -        outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, mRefreshButtonEnabled);\r
 +        //outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, mRefreshButtonEnabled);\r
 +        outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
  \r
      }\r
  \r
          super.onResume();\r
          // the state of mOAuth2Check is automatically recovered between configuration changes, but not before onCreate() finishes; so keep the next lines here\r
          changeViewByOAuth2Check(mOAuth2Check.isChecked());  \r
 -        if (mAction == ACTION_UPDATE_TOKEN && mJustCreated) {\r
 +        if (mAction == ACTION_UPDATE_TOKEN && mJustCreated && getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE, false)) {\r
              if (mOAuth2Check.isChecked())\r
                  Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show();\r
              else\r
  \r
  \r
      private void showRefreshButton() {\r
 -        mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
 -        mRefreshButtonEnabled = true;\r
 +        /*mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
 +        mRefreshButtonEnabled = true;*/\r
 +        mRefreshButton.setVisibility(View.VISIBLE);\r
      }\r
  \r
      private void hideRefreshButton() {\r
 -        mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
 -        mRefreshButtonEnabled = false;\r
 +        /*mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
 +        mRefreshButtonEnabled = false;*/\r
 +        mRefreshButton.setVisibility(View.GONE);\r
      }\r
  \r
      /**\r
       * \r
       * @param view      Refresh 'button'\r
       */\r
 -    public void onRefreshClick() {\r
 +    public void onRefreshClick(View view) {\r
          checkOcServer();\r
      }\r
      \r
       * Called from SslValidatorDialog when a new server certificate was correctly saved.\r
       */\r
      public void onSavedCertificate() {\r
-         mOperationThread = mOcServerChkOperation.retry(this, mHandler);                \r
+         checkOcServer();\r
      }\r
  \r
      /**\r
@@@ -47,9 -47,8 +47,9 @@@ import com.actionbarsherlock.app.Sherlo
  import com.actionbarsherlock.view.Menu;
  import com.actionbarsherlock.view.MenuInflater;
  import com.actionbarsherlock.view.MenuItem;
- import com.owncloud.android.AccountUtils;
  import com.owncloud.android.authentication.AccountAuthenticator;
 +import com.owncloud.android.authentication.AuthenticatorActivity;
+ import com.owncloud.android.authentication.AccountUtils;
  import com.owncloud.android.Log_OC;
  
  import com.owncloud.android.R;
@@@ -143,17 -142,11 +143,17 @@@ public class AccountSelectActivity exte
          return false;
      }
  
 +    /**
 +     * Called when the user clicked on an item into the context menu created at 
 +     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for every
 +     * ownCloud {@link Account} , containing 'secondary actions' for them.
 +     * 
 +     * {@inheritDoc}}
 +     */
      @SuppressWarnings("unchecked")
      @Override
      public boolean onContextItemSelected(android.view.MenuItem item) {
 -        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
 -                .getMenuInfo();
 +        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
          int index = info.position;
          HashMap<String, String> map = null;
          try {
          
          String accountName = map.get("NAME");
          AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
 -        Account accounts[] = am
 -                .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
 +        Account accounts[] = am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
          for (Account a : accounts) {
              if (a.name.equals(accountName)) {
 -                am.removeAccount(a, this, mHandler);
 +                if (item.getItemId() == R.id.change_password) {
 +                    Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
 +                    updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, a);
 +                    updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_TOKEN);
 +                    startActivity(updateAccountCredentials);
 +                    
 +                } else if (item.getItemId() == R.id.delete_account) {
 +                    am.removeAccount(a, this, mHandler);
 +                }
              }
          }