Skip to content

Refactor LoginActivity code for better readability #2690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
madhurgupta10 opened this issue Mar 20, 2019 · 0 comments · Fixed by #2775 or #2795
Closed

Refactor LoginActivity code for better readability #2690

madhurgupta10 opened this issue Mar 20, 2019 · 0 comments · Fixed by #2775 or #2795

Comments

@madhurgupta10
Copy link
Collaborator

madhurgupta10 commented Mar 20, 2019

Summary:
Refactor LoginActivity code for better readability, for example, this can be replaced with a switch statement.

private void handleOtherResults(String result) {
        if (result.equals("NetworkFailure")) {
            // Matches NetworkFailure which is created by the doInBackground method
            showMessageAndCancelDialog(R.string.login_failed_network);
        } else if (result.toLowerCase(Locale.getDefault()).contains("nosuchuser".toLowerCase()) || 
            result.toLowerCase().contains("noname".toLowerCase())) {
            // Matches nosuchuser, nosuchusershort, noname
            showMessageAndCancelDialog(R.string.login_failed_wrong_credentials);
            emptySensitiveEditFields();
        } else if (result.toLowerCase(Locale.getDefault()).contains("wrongpassword".toLowerCase())) {
            // Matches wrongpassword, wrongpasswordempty
            showMessageAndCancelDialog(R.string.login_failed_wrong_credentials);
            emptySensitiveEditFields();
        } else if (result.toLowerCase(Locale.getDefault()).contains("throttle".toLowerCase())) {
            // Matches unknown throttle error codes
            showMessageAndCancelDialog(R.string.login_failed_throttled);
        } else if (result.toLowerCase(Locale.getDefault()).contains("userblocked".toLowerCase())) {
            // Matches login-userblocked
            showMessageAndCancelDialog(R.string.login_failed_blocked);
        } else if (result.equals("2FA")) {
            askUserForTwoFactorAuth();
        } else {
            // Occurs with unhandled login failure codes
            Timber.d("Login failed with reason: %s", result);
            showMessageAndCancelDialog(R.string.login_failed_generic);
        }
    }

also there are many elements which still uses setOnClickListener instead of @OnClick these are small changes but it will surely make the code more maintainable and readable :)

Commons app version:
latest betaDebug

Would you like to work on the issue?
Yes

madhurgupta10 added a commit to madhurgupta10/apps-android-commons that referenced this issue Mar 28, 2019
neslihanturan pushed a commit that referenced this issue Mar 28, 2019
* Refactor LoginActivity #2690

* Fixed Error cannot find symbol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants