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
1 change: 1 addition & 0 deletions app/res/layout/home_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:layout_marginBottom="2dp"
android:clickable="true"
android:focusable="true"
android:visibility="gone"
android:shadowColor="@color/connect_light_grey_transparent"
android:shadowDx="30"
android:shadowDy="30"
Expand Down
30 changes: 16 additions & 14 deletions app/src/org/commcare/activities/DispatchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class DispatchActivity extends AppCompatActivity {
public static final String START_FROM_LOGIN = "process_successful_login";
public static final String EXECUTE_RECOVERY_MEASURES = "execute_recovery_measures";
public static final String SESSION_REBUILD_REQUEST = "session_rebuild_request";

public static final String REDIRECT_TO_CONNECT_OPPORTUNITY_INFO = "redirect-to-connect-opportunity-info";
private static final int LOGIN_USER = 0;
private static final int HOME_SCREEN = 1;
public static final int INIT_APP = 2;
Expand Down Expand Up @@ -80,6 +82,8 @@ public class DispatchActivity extends AppCompatActivity {

boolean alreadyCheckedForAppFilesChange;
static final String REBUILD_SESSION = "rebuild_session";
private boolean redirectToConnectHome = false;
private boolean redirectToConnectOpportunityInfo = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -197,18 +201,15 @@ private void dispatch() {
!shortcutExtraWasConsumed) {
// CommCare was launched from a shortcut
handleShortcutLaunch();
} else if(redirectToConnectHome) {
redirectToConnectHome = false;
CommCareApplication.instance().closeUserSession();
ConnectIDManager.getInstance().goToConnectJobsList(this);
} else if(redirectToConnectOpportunityInfo) {
redirectToConnectOpportunityInfo = false;
ConnectIDManager.getInstance().goToActiveInfoForJob(this, true);
} else {
int connectAction = ConnectIDManager.getInstance().getPendingAction();
switch (connectAction) {
case ConnectIDManager.PENDING_ACTION_CONNECT_HOME -> {
CommCareApplication.instance().closeUserSession();
ConnectIDManager.getInstance().goToConnectJobsList(this);
}
case ConnectIDManager.PENDING_ACTION_OPP_STATUS -> {
ConnectIDManager.getInstance().goToActiveInfoForJob(this, true);
}
default -> launchHomeScreen();
}
launchHomeScreen();
}
} catch (SessionUnavailableException sue) {
launchLoginScreen();
Expand Down Expand Up @@ -441,8 +442,9 @@ private boolean triggerLoginIfNeeded() {

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (intent != null && intent.getBooleanExtra(EXECUTE_RECOVERY_MEASURES, false)) {
this.needToExecuteRecoveryMeasures = true;
if (intent != null) {
needToExecuteRecoveryMeasures = intent.getBooleanExtra(EXECUTE_RECOVERY_MEASURES, false);
redirectToConnectOpportunityInfo = intent.getBooleanExtra(REDIRECT_TO_CONNECT_OPPORTUNITY_INFO, false);
}

// if handling new return code (want to return to home screen) but a return at the end of your statement
Expand Down Expand Up @@ -479,7 +481,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
if (resultCode == RESULT_CANCELED) {
shouldFinish = !connectManagedLogin;
if(connectManagedLogin) {
ConnectIDManager.getInstance().setPendingAction(ConnectIDManager.PENDING_ACTION_CONNECT_HOME);
redirectToConnectHome = true;
}
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/src/org/commcare/activities/HomeButtons.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class HomeButtons {

private final static String[] buttonNames =
new String[]{"start", "training", "saved", "incomplete", "sync", "report", "logout"};
new String[]{"start", "training", "saved", "incomplete","connect", "sync", "report", "logout"};

/**
* Note: The order in which home cards are returned by this method should be consistent with
Expand Down
4 changes: 3 additions & 1 deletion app/src/org/commcare/activities/HomeScreenBaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.commcare.activities.DispatchActivity.EXIT_AFTER_FORM_SUBMISSION;
import static org.commcare.activities.DispatchActivity.EXIT_AFTER_FORM_SUBMISSION_DEFAULT;
import static org.commcare.activities.DispatchActivity.REDIRECT_TO_CONNECT_OPPORTUNITY_INFO;
import static org.commcare.activities.DispatchActivity.SESSION_ENDPOINT_ARGUMENTS_BUNDLE;
import static org.commcare.activities.DispatchActivity.SESSION_ENDPOINT_ARGUMENTS_LIST;
import static org.commcare.activities.DispatchActivity.SESSION_ENDPOINT_ID;
Expand Down Expand Up @@ -578,7 +579,8 @@ protected void userTriggeredLogout() {
}

protected void userPressedOpportunityStatus() {
ConnectIDManager.getInstance().setPendingAction(ConnectIDManager.PENDING_ACTION_OPP_STATUS);
Intent i = new Intent();
i.putExtra(REDIRECT_TO_CONNECT_OPPORTUNITY_INFO, true);
setResult(RESULT_OK);
finish();
}
Expand Down
89 changes: 57 additions & 32 deletions app/src/org/commcare/activities/LoginActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.commcare.activities;

import static org.commcare.activities.DispatchActivity.REDIRECT_TO_CONNECT_OPPORTUNITY_INFO;
import static org.commcare.connect.ConnectIDManager.ConnectAppMangement.Connect;
import static org.commcare.connect.ConnectIDManager.ConnectAppMangement.ConnectId;
import static org.commcare.connect.ConnectIDManager.ConnectAppMangement.Unmanaged;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -113,6 +118,7 @@ public class LoginActivity extends CommCareActivity<LoginActivity>
public static final String CONNECTID_MANAGED_LOGIN = "connectid-managed-login";
public static final String CONNECT_MANAGED_LOGIN = "connect-managed-login";
private ConnectIDManager connectIDManager;
private ConnectIDManager.ConnectAppMangement connectAppState = Unmanaged;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -208,7 +214,7 @@ protected void initiateLoginAttempt(boolean restoreSession) {
if (appLaunchedFromConnect) {
//Auto login
doLogin(loginMode, restoreSession, "AUTO");
} else if (uiController.loginManagedByConnectId()) {
} else if (loginManagedByConnectId()) {
//Unlock and then auto login
connectIDManager.unlockConnect(this, success -> {
if (success) {
Expand Down Expand Up @@ -376,9 +382,8 @@ private boolean forceAutoLogin() {

private String getUniformUsername() {
String username = uiController.getEnteredUsername();
String connectIdUsername = connectIDManager.getConnectUsername(this);
if (connectIDManager.isLoggedIN() && appLaunchedFromConnect && connectIdUsername != null) {
username = connectIdUsername;
if (connectIDManager.isLoggedIN() && appLaunchedFromConnect) {
username = connectIDManager.getConnectUsername(this);
}
return username.toLowerCase().trim();
}
Expand Down Expand Up @@ -417,7 +422,7 @@ protected void deliverUpdate(LoginActivity receiver, String... update) {

return true;
} catch (Exception e) {
e.printStackTrace();
Logger.exception("Error while local login", e);
return false;
}
}
Expand Down Expand Up @@ -462,7 +467,7 @@ private boolean handleConnectSignIn(CommCareActivity<?> context, String username
} else {
//Possibly offer to link or de-link ConnectId-managed login
connectIDManager.checkConnectIdLink(context,
uiController.loginManagedByConnectId(),
loginManagedByConnectId(),
appId,
username,
enteredPasswordPin,
Expand All @@ -481,23 +486,31 @@ private boolean handleConnectSignIn(CommCareActivity<?> context, String username


private void setResultAndFinish(boolean navigateToConnectJobs) {
if (navigateToConnectJobs) {
connectIDManager.setPendingAction(connectIDManager.PENDING_ACTION_OPP_STATUS);
}

Intent i = new Intent();
i.putExtra(REDIRECT_TO_CONNECT_OPPORTUNITY_INFO, navigateToConnectJobs);
i.putExtra(LOGIN_MODE, uiController.getLoginMode());
i.putExtra(MANUAL_SWITCH_TO_PW_MODE, uiController.userManuallySwitchedToPasswordMode());
i.putExtra(CONNECTID_MANAGED_LOGIN, appLaunchedFromConnect || uiController.loginManagedByConnectId());
i.putExtra(CONNECTID_MANAGED_LOGIN, appLaunchedFromConnect || loginManagedByConnectId());
i.putExtra(CONNECT_MANAGED_LOGIN, appLaunchedFromConnect);
setResult(RESULT_OK, i);
finish();
}

public void handleConnectButtonPress() {
selectedAppIndex = -1;
connectIDManager.unlockConnect(this, success -> {
if(success) {
connectIDManager.goToConnectJobsList(this);
setResult(RESULT_OK);
finish();
}
});
}

private void handleFailedConnectSignIn() {
if (uiController.loginManagedByConnectId()) {
if (loginManagedByConnectId()) {
ApplicationRecord record = CommCareApplication.instance().getCurrentApp().getAppRecord();
ConnectIDManager.ConnectAppMangement appState = connectIDManager.evalAppState(this,
ConnectIDManager.ConnectAppMangement appState = connectIDManager.evaluateAppState(this,
record.getUniqueId(), getUniformUsername());
switch (appState) {
case Connect -> {
Expand Down Expand Up @@ -560,8 +573,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
case MENU_CONNECT_FORGET:
connectIDManager.forgetUser(AnalyticsParamValue.CCC_FORGOT_USER_LOGIN_PAGE);
uiController.setPasswordOrPin("");
setConnectAppState(Unmanaged);
uiController.refreshView();
uiController.setConnectIdLoginState(ConnectIDManager.ConnectAppMangement.Unmanaged);
return true;
default:
return otherResult;
Expand Down Expand Up @@ -899,29 +912,41 @@ protected boolean seatAppIfNeeded(String appId) {
return selectedNewApp;
}

public void setConnectAppState() {
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
ConnectIDManager.ConnectAppMangement appState = connectIDManager.evalAppState(this,
seatedAppId, uiController.getEnteredUsername());

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

uiController.setConnectButtonVisible(false);
if (!seatAppIfNeeded(presetAppId)) {
initiateLoginAttempt(uiController.isRestoreSessionChecked());
protected void evaluateConnectAppState() {
if (connectIDManager.isLoggedIN()) {
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
ConnectIDManager.ConnectAppMangement appState = connectIDManager.evaluateAppState(this,
seatedAppId, uiController.getEnteredUsername());

if (appLaunchedFromConnect && presetAppId != null) {
appState = Connect;
if (!seatAppIfNeeded(presetAppId)) {
initiateLoginAttempt(uiController.isRestoreSessionChecked());
}
}
}

if (appState == ConnectIDManager.ConnectAppMangement.ConnectId) {
int selectorIndex = uiController.getSelectedAppIndex();
String selectedAppId = !appIdDropdownList.isEmpty() ? appIdDropdownList.get(selectorIndex) : "";
if (uiController.isAppSelectorVisible() && !selectedAppId.equals(seatedAppId)) {
appState = ConnectIDManager.ConnectAppMangement.Unmanaged;
if (appState == ConnectId) {
int selectorIndex = uiController.getSelectedAppIndex();
String selectedAppId = !appIdDropdownList.isEmpty() ? appIdDropdownList.get(selectorIndex) : "";
if (uiController.isAppSelectorVisible() && !selectedAppId.equals(seatedAppId)) {
appState = Unmanaged;
}
}
setConnectAppState(appState);
} else {
setConnectAppState(Unmanaged);
}
}

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

uiController.setConnectIdLoginState(appState);
public void setConnectAppState(ConnectIDManager.ConnectAppMangement connectAppState) {
this.connectAppState = connectAppState;
}

protected ConnectIDManager.ConnectAppMangement getConnectAppState() {
return connectAppState;
}
}
Loading