Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/res/layout/screen_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
android:textSize="@dimen/text_medium"
android:visibility="gone" />

<org.commcare.views.connect.connecttextview.ConnectMediumTextView
android:id="@+id/login_via_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/content_min_margin"
android:text="@string/login_via_connect"
android:textColor="@color/cc_neutral_color"
android:textSize="@dimen/text_medium"
android:visibility="gone"/>

<AutoCompleteTextView
android:id="@+id/edit_username"
style="@style/LoginEditTextV2"
Expand All @@ -133,6 +144,7 @@
</AutoCompleteTextView>

<RelativeLayout
android:id="@+id/password_wrapper"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:padding="0dp"
Expand Down
1 change: 0 additions & 1 deletion app/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@
<string name="login_password_by_connect">Via ConnectID (ou pressione aqui)</string>
<string name="login_welcome_connect_signed_in">Bemvindo %s!</string>
<string name="login_connect_secondary_phone_message">Por favor, confirme seu telefone secundário até %s para continuar usando o ConnectID.</string>
<string name="login_input_auto">AUTO</string>
<string name="choice_or">OU</string>
<string name="busy_message">Ainda estamos ocupados processando sua solicitação anterior. Por favor, tente novamente em alguns momentos.</string>
<string name="connect_button_logged_in">Vá para o Conectar menu</string>
Expand Down
1 change: 0 additions & 1 deletion app/res/values-ti/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@
<string name="login_password_by_connect">ብመንገዲ ConnectID (ወይ ኣብዚ ጽቐጥ)</string>
<string name="login_welcome_connect_signed_in">እንቋዕ ብደሓን መጻእኩም %s!</string>
<string name="login_connect_secondary_phone_message">በጃኹም ካልኣይ ደረጃ ስልክኹም ብ %s ኣረጋግጹ ConnectID ምጥቃምም ክትቅጽል።</string>
<string name="login_input_auto">ኣውቶማቲክ</string>
<string name="choice_or">_____________ ወይ _____________</string>
<string name="busy_message">ሕጂ ውን ቅድሚ ሕጂ ዝገበርካዮ ሕቶ ኣብ ምስራሕ ተጸሚድና ኣለና። በጃኻ ድሕሪ ውሱን ግዜ ደጊምካ ፈትን።</string>
<string name="connect_button_logged_in">ናብ Connect መማረፂ ኪድ</string>
Expand Down
2 changes: 1 addition & 1 deletion app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@
<string name="login_welcome_connect_signed_out">Unlock ConnectID first and then enter your app.</string>
<string name="login_welcome_connect_signed_in">Welcome %s!</string>
<string name="login_connect_secondary_phone_message">Please confirm your secondary phone by %s to keep using ConnectID.</string>
<string name="login_input_auto">AUTO</string>
<string name="choice_or">_____________ OR _____________</string>
<string name="busy_message">We are still busy processing your previous request. Please try again in some time.</string>

<string name="connect_button_logged_in">Go to Connect menu</string>
<string name="login_via_connect">Ready to login!</string>

<string name="connect_consent_title">Consent</string>

Expand Down
82 changes: 51 additions & 31 deletions app/src/org/commcare/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ protected void initiateLoginAttempt(boolean restoreSession) {
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
String username = uiController.getEnteredUsername();

if(!appLaunchedFromConnect && uiController.loginManagedByConnectId()) {
if(appLaunchedFromConnect) {
//Auto login
doLogin(loginMode, restoreSession, "AUTO");
}
else if(uiController.loginManagedByConnectId()) {
//Unlock and then auto login
ConnectManager.unlockConnect(this, success -> {
if(success) {
String pass = ConnectManager.getStoredPasswordForApp(seatedAppId, username);
Expand All @@ -230,6 +235,7 @@ protected void initiateLoginAttempt(boolean restoreSession) {
});
}
else {
//Manual login
String passwordOrPin = uiController.getEnteredPasswordOrPin();
doLogin(loginMode, restoreSession, passwordOrPin);
}
Expand Down Expand Up @@ -521,12 +527,19 @@ public boolean handleConnectSignIn() {

public void handleFailedConnectSignIn() {
ApplicationRecord record = CommCareApplication.instance().getCurrentApp().getAppRecord();
if(appLaunchedFromConnect) {
FirebaseAnalyticsUtil.reportCccAppFailedAutoLogin(record.getApplicationId());
} else if(ConnectManager.isLoginManagedByConnectId(record.getUniqueId(), getUniformUsername())) {
//TODO: Display an additional message that the user will need to login with their password to restore CID login
//ConnectManager.forgetAppCredentials(record.getUniqueId(), getUniformUsername());
//checkForSavedCredentials();

ConnectManager.ConnectAppMangement appState = ConnectManager.getAppManagement(this,
record.getUniqueId(), getUniformUsername());

switch(appState) {
case Connect -> {
FirebaseAnalyticsUtil.reportCccAppFailedAutoLogin(record.getApplicationId());
}
case ConnectId -> {
//TODO: Display an additional message that the user will need to login with their password to restore CID login
//ConnectManager.forgetAppCredentials(record.getUniqueId(), getUniformUsername());
//checkForSavedCredentials();
}
}
}

Expand All @@ -538,34 +551,35 @@ public void registerConnectIdUser() {
}

private void checkForSavedCredentials() {
boolean loginWithConnectIDVisible = false;
if (ConnectManager.isConnectIdConfigured()) {
if (appLaunchedFromConnect && !connectLaunchPerformed) {
loginWithConnectIDVisible = true;
uiController.setConnectButtonVisible(false);
uiController.setUsername(getString(R.string.login_input_auto));
uiController.setPasswordOrPin(getString(R.string.login_input_auto));
if(!seatAppIfNeeded(presetAppId)) {
connectLaunchPerformed = true;
initiateLoginAttempt(uiController.isRestoreSessionChecked());
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
ConnectManager.ConnectAppMangement appState = ConnectManager.getAppManagement(this,
seatedAppId, uiController.getEnteredUsername());

if(appLaunchedFromConnect && presetAppId != null) {
appState = ConnectManager.ConnectAppMangement.Connect;

uiController.setConnectButtonVisible(false);
if (!seatAppIfNeeded(presetAppId)) {
connectLaunchPerformed = true;
initiateLoginAttempt(uiController.isRestoreSessionChecked());
}
}

if(appState == ConnectManager.ConnectAppMangement.ConnectId) {
int selectorIndex = uiController.getSelectedAppIndex();
if (selectorIndex > 0) {
String selectedAppId = appIdDropdownList.size() > 0 ? appIdDropdownList.get(selectorIndex) : "";

if (uiController.isAppSelectorVisible() && !selectedAppId.equals(seatedAppId)) {
appState = ConnectManager.ConnectAppMangement.Unmanaged;
}
} else {
int selectorIndex = uiController.getSelectedAppIndex();
if(selectorIndex > 0) {
String selectedAppId = appIdDropdownList.size() > 0 ? appIdDropdownList.get(selectorIndex) : "";
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
if (!uiController.isAppSelectorVisible() || selectedAppId.equals(seatedAppId)) {
loginWithConnectIDVisible = ConnectManager.isLoginManagedByConnectId(seatedAppId,
uiController.getEnteredUsername());
}
} else {
//Connect jobs selected from dropdown
loginWithConnectIDVisible = true;
}
//Connect jobs selected from dropdown
appState = ConnectManager.ConnectAppMangement.Connect;
}
}

uiController.setConnectIdLoginState(loginWithConnectIDVisible);
uiController.setConnectIdLoginState(appState);
}

@Override
Expand Down Expand Up @@ -623,7 +637,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
ConnectManager.forgetUser("User initiated from login page");
uiController.setPasswordOrPin("");
uiController.refreshView();
uiController.setConnectIdLoginState(false);
uiController.setConnectIdLoginState(ConnectManager.ConnectAppMangement.Unmanaged);
return true;
default:
return otherResult;
Expand Down Expand Up @@ -743,9 +757,15 @@ protected void populateAppSpinner(ArrayList<ApplicationRecord> readyApps) {
int position = 0;
if (selectedAppIndex >= 0) {
position = selectedAppIndex;

if(position >= appNames.size()) {
//Special case when user forgets ConnectID account and last app in the list is selected
position = appNames.size() - 1;
}
} else if (appIdDropdownList.contains(currAppId)) {
position = appIdDropdownList.indexOf(currAppId);
}

uiController.setMultipleAppsUiState(appNames, position);
selectedAppIndex = -1;
}
Expand Down
44 changes: 31 additions & 13 deletions app/src/org/commcare/activities/LoginActivityUiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

Expand Down Expand Up @@ -75,12 +76,18 @@ public class LoginActivityUiController implements CommCareActivityUIController {
@UiElement(value = R.id.login_or)
private ConnectMediumTextView orLabel;

@UiElement(value = R.id.login_via_connect)
private ConnectMediumTextView loginViaConnectLabel;

@UiElement(value = R.id.edit_username, locale = "login.username")
private AutoCompleteTextView username;

@UiElement(value = R.id.edit_password)
private EditText passwordOrPin;

@UiElement(value = R.id.password_wrapper)
private RelativeLayout passwordWrapper;

@UiElement(value = R.id.show_password)
private Button showPasswordButton;

Expand All @@ -107,7 +114,7 @@ public class LoginActivityUiController implements CommCareActivityUIController {
private LoginMode loginMode;

private boolean manuallySwitchedToPasswordMode;
private boolean loginManagedByConnectId;
private ConnectManager.ConnectAppMangement connectAppState;

private final TextWatcher usernameTextWatcher = new TextWatcher() {
@Override
Expand Down Expand Up @@ -143,6 +150,7 @@ public void afterTextChanged(Editable s) {
public LoginActivityUiController(LoginActivity activity) {
this.activity = activity;
this.loginMode = LoginMode.PASSWORD;
this.connectAppState = ConnectManager.ConnectAppMangement.Unmanaged;
}

@Override
Expand All @@ -168,7 +176,7 @@ public void setupUI() {

passwordOrPin.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
setConnectIdLoginState(false);
setConnectIdLoginState(ConnectManager.ConnectAppMangement.Unmanaged);
}
});

Expand Down Expand Up @@ -265,7 +273,8 @@ public void refreshView() {

public void setLoginInputsVisibility(boolean visible) {
username.setVisibility(visible ? View.VISIBLE : View.GONE);
passwordOrPin.setVisibility(visible ? View.VISIBLE : View.GONE);
passwordWrapper.setVisibility(visible ? View.VISIBLE : View.GONE);
loginViaConnectLabel.setVisibility(visible ? View.GONE : View.VISIBLE);
}

public void updateConnectLoginState() {
Expand Down Expand Up @@ -535,21 +544,27 @@ protected void setPasswordOrPin(String s) {
}

protected boolean loginManagedByConnectId() {
return loginManagedByConnectId;
return connectAppState == ConnectManager.ConnectAppMangement.ConnectId ||
connectAppState == ConnectManager.ConnectAppMangement.Connect;
}

protected void setConnectIdLoginState(boolean useConnectId) {
if (!useConnectId && loginManagedByConnectId) {
protected void setConnectIdLoginState(ConnectManager.ConnectAppMangement appState) {
boolean unmanaged = appState == ConnectManager.ConnectAppMangement.Unmanaged;
if (unmanaged &&
connectAppState != ConnectManager.ConnectAppMangement.Unmanaged) {
setPasswordOrPin("");
}

loginManagedByConnectId = useConnectId;
connectAppState = appState;

boolean connect = connectAppState == ConnectManager.ConnectAppMangement.Connect;
setLoginInputsVisibility(!connect);

String text;
if (useConnectId) {
text = activity.getString(R.string.login_button_connectid);
} else {
if (unmanaged) {
text = Localization.get("login.button");
} else {
text = activity.getString(R.string.login_button_connectid);
}
loginButton.setText(text);

Expand All @@ -558,13 +573,16 @@ protected void setConnectIdLoginState(boolean useConnectId) {
* the strings should be translate correctly when they return to the app. That's why I added this code.
*/
connectLoginButton.setText(activity.getString(R.string.connect_button_logged_in));
passwordOrPin.setBackgroundColor(getResources().getColor(useConnectId ? R.color.grey_light : R.color.white));
if (useConnectId) {

passwordOrPin.setBackgroundColor(getResources().getColor(unmanaged ? R.color.white : R.color.grey_light));
if (!unmanaged) {
passwordOrPin.setText(R.string.login_password_by_connect);
passwordOrPin.clearFocus();
}

passwordOrPin.setInputType(useConnectId ? InputType.TYPE_CLASS_TEXT : (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD));
passwordOrPin.setInputType(unmanaged ?
(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD) :
InputType.TYPE_CLASS_TEXT);
}

private void updateBanner() {
Expand Down
Loading