Browse Source

Fix #420

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 years ago
parent
commit
7a26e1d069

+ 10 - 3
app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java

@@ -50,6 +50,7 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.nextcloud.talk.utils.preferences.AppPreferences;
 import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
 
+import io.reactivex.android.schedulers.AndroidSchedulers;
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
@@ -181,6 +182,7 @@ public class AccountVerificationController extends BaseController {
 
         ncApi.getServerStatus(queryUrl)
                 .subscribeOn(Schedulers.newThread())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Observer<Status>() {
                     @Override
                     public void onSubscribe(Disposable d) {
@@ -195,7 +197,12 @@ public class AccountVerificationController extends BaseController {
                             baseUrl = "http://" + baseUrl;
                         }
 
-                        checkEverything();
+                        if (isAccountImport) {
+                            getRouter().pushController(RouterTransaction.with(new WebViewLoginController(baseUrl,
+                                    false, username, "")));
+                        } else {
+                            checkEverything();
+                        }
                     }
 
                     @Override
@@ -248,7 +255,7 @@ public class AccountVerificationController extends BaseController {
                 });
     }
 
-    private void storeProfile(String credentials, String displayName, String userId) {
+    private void storeProfile(String displayName, String userId) {
         userUtils.createOrUpdateUser(username, token,
                 baseUrl, displayName, null, true,
                 userId, null, null,
@@ -314,7 +321,7 @@ public class AccountVerificationController extends BaseController {
                         }
 
                         if (!TextUtils.isEmpty(displayName)) {
-                            storeProfile(credentials, displayName, userProfileOverall.getOcs().getData().getUserId());
+                            storeProfile(displayName, userProfileOverall.getOcs().getData().getUserId());
                         } else {
                             if (getActivity() != null) {
                                 getActivity().runOnUiThread(() -> progressText.setText(progressText.getText().toString() + "\n" +

+ 10 - 5
app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java

@@ -168,6 +168,10 @@ public class SwitchAccountController extends BaseController {
         NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
         swipeRefreshLayout.setEnabled(false);
 
+        if (getActionBar() != null) {
+            getActionBar().show();
+        }
+
         if (adapter == null) {
             adapter = new FlexibleAdapter<>(userItems, getActivity(), false);
 
@@ -196,9 +200,6 @@ public class SwitchAccountController extends BaseController {
                 adapter.addListener(onSwitchItemClickListener);
                 adapter.updateDataSet(userItems, false);
             } else {
-                if (getActionBar() != null) {
-                    getActionBar().show();
-                }
                 Account account;
                 ImportAccount importAccount;
                 for (Object accountObject : AccountUtils.findAccounts(userUtils.getUsers())) {
@@ -239,8 +240,12 @@ public class SwitchAccountController extends BaseController {
 
     private void reauthorizeFromImport(Account account) {
         ImportAccount importAccount = AccountUtils.getInformationFromAccount(account);
-        getRouter().pushController(RouterTransaction.with(new WebViewLoginController(importAccount.getBaseUrl(),
-                false, importAccount.getUsername(), ""))
+        Bundle bundle = new Bundle();
+        bundle.putString(BundleKeys.KEY_BASE_URL, importAccount.getBaseUrl());
+        bundle.putString(BundleKeys.KEY_USERNAME, importAccount.getUsername());
+        bundle.putString(BundleKeys.KEY_TOKEN, importAccount.getToken());
+        bundle.putBoolean(BundleKeys.KEY_IS_ACCOUNT_IMPORT, true);
+        getRouter().pushController(RouterTransaction.with(new AccountVerificationController(bundle))
                 .pushChangeHandler(new HorizontalChangeHandler())
                 .popChangeHandler(new HorizontalChangeHandler()));
     }

+ 1 - 2
app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java

@@ -214,8 +214,7 @@ public class WebViewLoginController extends BaseController {
                     } else if (!automatedLoginAttempted) {
                         automatedLoginAttempted = true;
                         if (TextUtils.isEmpty(password)) {
-                            webView.loadUrl("javascript: {" +
-                                    "document.getElementById('user').value = '" + username + "'; };");
+                            webView.loadUrl("javascript:var justStore = document.getElementById('user').value = '" + username + "';");
                         } else {
                             webView.loadUrl("javascript: {" +
                                     "document.getElementById('user').value = '" + username + "';" +