Browse Source

show correct warning if an account is added twice

tobiasKaminsky 7 năm trước cách đây
mục cha
commit
3403d55568

+ 48 - 33
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -252,14 +252,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         //Log_OC.e(TAG,  "onCreate init");
         //Log_OC.e(TAG,  "onCreate init");
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
 
 
-        CookieSyncManager.createInstance(this);
-        CookieManager cookieManager = CookieManager.getInstance();
-
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-            cookieManager.removeAllCookies(null);
-        } else {
-            cookieManager.removeAllCookie();
-        }
+        // delete cookies for webView
+        deleteCookies();
 
 
         // Workaround, for fixing a problem with Android Library Suppor v7 19
         // Workaround, for fixing a problem with Android Library Suppor v7 19
         //getWindow().requestFeature(Window.FEATURE_NO_TITLE);
         //getWindow().requestFeature(Window.FEATURE_NO_TITLE);
@@ -343,6 +337,17 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         initServerPreFragment(savedInstanceState);
         initServerPreFragment(savedInstanceState);
     }
     }
 
 
+    private void deleteCookies() {
+        CookieSyncManager.createInstance(this);
+        CookieManager cookieManager = CookieManager.getInstance();
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            cookieManager.removeAllCookies(null);
+        } else {
+            cookieManager.removeAllCookie();
+        }
+    }
+
     private static String getWebLoginUserAgent() {
     private static String getWebLoginUserAgent() {
         return android.os.Build.MANUFACTURER.substring(0, 1).toUpperCase() +
         return android.os.Build.MANUFACTURER.substring(0, 1).toUpperCase() +
                 android.os.Build.MANUFACTURER.substring(1).toLowerCase() + " " + android.os.Build.MODEL;
                 android.os.Build.MANUFACTURER.substring(1).toLowerCase() + " " + android.os.Build.MODEL;
@@ -1333,8 +1338,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 setContentView(R.layout.account_setup_webview);
                 setContentView(R.layout.account_setup_webview);
                 mLoginWebView = (WebView) findViewById(R.id.login_webview);
                 mLoginWebView = (WebView) findViewById(R.id.login_webview);
                 initWebViewLogin(mServerInfo.mBaseUrl);
                 initWebViewLogin(mServerInfo.mBaseUrl);
-
-                // checkBasicAuthorization(webViewUser, webViewPassword);
             } else {
             } else {
                 // show old login
                 // show old login
                 mOkButton.setVisibility(View.VISIBLE);
                 mOkButton.setVisibility(View.VISIBLE);
@@ -1686,8 +1689,26 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 }
                 }
             }
             }
 
 
+            // Reset webView
+            webViewPassword = null;
+            webViewUser = null;
+            deleteCookies();
+
             if (success) {
             if (success) {
                 finish();
                 finish();
+            } else {
+                // init webView again
+                mLoginWebView.setVisibility(View.GONE);
+                setContentView(R.layout.account_setup);
+
+                CustomEditText serverAddressField = (CustomEditText) findViewById(R.id.hostUrlInput);
+                serverAddressField.setText(mServerInfo.mBaseUrl);
+
+                findViewById(R.id.oauth_onOff_check).setVisibility(View.GONE);
+                findViewById(R.id.server_status_text).setVisibility(View.GONE);
+                mAuthStatusView = (TextView) findViewById(R.id.auth_status_text);
+
+                showAuthStatus();
             }
             }
 
 
         } else if (result.isServerFail() || result.isException()) {
         } else if (result.isServerFail() || result.isException()) {
@@ -1814,10 +1835,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         if (AccountUtils.exists(newAccount, getApplicationContext())) {
         if (AccountUtils.exists(newAccount, getApplicationContext())) {
             // fail - not a new account, but an existing one; disallow
             // fail - not a new account, but an existing one; disallow
             RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
             RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
-            if (!webViewLoginMethod) {
-                updateAuthStatusIconAndText(result);
-                showAuthStatus();
-            }
+
+            updateAuthStatusIconAndText(result);
+            showAuthStatus();
+
             Log_OC.d(TAG, result.getLogMessage());
             Log_OC.d(TAG, result.getLogMessage());
             return false;
             return false;
 
 
@@ -1919,15 +1940,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * to the last check on the ownCloud server.
      * to the last check on the ownCloud server.
      */
      */
     private void showServerStatus() {
     private void showServerStatus() {
-        if (!webViewLoginMethod) {
-            if (mServerStatusIcon == 0 && mServerStatusText == 0) {
-                mServerStatusView.setVisibility(View.INVISIBLE);
-
-            } else {
-                mServerStatusView.setText(mServerStatusText);
-                mServerStatusView.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);
-                mServerStatusView.setVisibility(View.VISIBLE);
-            }
+        if (mServerStatusIcon == 0 && mServerStatusText == 0) {
+            mServerStatusView.setVisibility(View.INVISIBLE);
+        } else {
+            mServerStatusView.setText(mServerStatusText);
+            mServerStatusView.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);
+            mServerStatusView.setVisibility(View.VISIBLE);
         }
         }
     }
     }
 
 
@@ -1937,15 +1955,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * to the interactions with the OAuth authorization server.
      * to the interactions with the OAuth authorization server.
      */
      */
     private void showAuthStatus() {
     private void showAuthStatus() {
-        if (!webViewLoginMethod) {
-            if (mAuthStatusIcon == 0 && mAuthStatusText == 0) {
-                mAuthStatusView.setVisibility(View.INVISIBLE);
-
-            } else {
-                mAuthStatusView.setText(mAuthStatusText);
-                mAuthStatusView.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon, 0, 0, 0);
-                mAuthStatusView.setVisibility(View.VISIBLE);
-            }
+        if (mAuthStatusIcon == 0 && mAuthStatusText == 0) {
+            mAuthStatusView.setVisibility(View.INVISIBLE);
+        } else {
+            mAuthStatusView.setText(mAuthStatusText);
+            mAuthStatusView.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon, 0, 0, 0);
+            mAuthStatusView.setVisibility(View.VISIBLE);
         }
         }
     }
     }
 
 
@@ -2217,7 +2232,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     /**
     /**
      * Create and show dialog for request authentication to the user
      * Create and show dialog for request authentication to the user
      *
      *
-     * @param webView Web view to emebd into the authentication dialog.
+     * @param webView Web view to embed into the authentication dialog.
      * @param handler Object responsible for catching and recovering HTTP authentication fails.
      * @param handler Object responsible for catching and recovering HTTP authentication fails.
      */
      */
     public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) {
     public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) {