@Override public void onValidationFinished(ValidationType validationType) { if (validationType.equals(ValidationType.SKIPPED)) { Log.d("ValidationType: ", "SKIPPED. Launching login activity..."); startActivityForResult(new Intent(getBaseContext(), WelcomeActivity.class), 364); Bundle data = new Bundle(); data.putString(WelcomeActivity.VALIDATION_TYPE, ValidationType.SKIPPED.name()); Intent missingToken = new Intent(getBaseContext(), WelcomeActivity.class); missingToken.putExtras(data); startActivityForResult(missingToken, 364); } else if (validationType.equals(ValidationType.MISSING_CREDENTIALS)) { Log.d("ValidationType: ", "MISSING_CREDENTIALS. Launching login activity..."); Bundle data = new Bundle(); data.putString(WelcomeActivity.VALIDATION_TYPE, ValidationType.MISSING_CREDENTIALS.name()); Intent missingToken = new Intent(getBaseContext(), WelcomeActivity.class); missingToken.putExtras(data); startActivityForResult(missingToken, 364); } else if (validationType.equals(ValidationType.MISSING_TOKEN)) { Log.d("ValidationType:", "MISSING_TOKEN. Launching Login Activity"); Bundle data = new Bundle(); data.putString(WelcomeActivity.VALIDATION_TYPE, ValidationType.MISSING_TOKEN.name()); Intent missingToken = new Intent(getBaseContext(), WelcomeActivity.class); missingToken.putExtras(data); startActivityForResult(missingToken, 364); } else if (validationType.equals(ValidationType.SUCCESS)) { Log.d("ValidationType: ", "SUCCESS. Get user info/retrieve updated data from server"); onLoginSuccess( new LinodeUser( LinodeApi.getInstance().getPreferences().getCurrentUsername(), LinodeApi.getInstance().getPreferences().getCurrentPassword(), LinodeApi.getInstance().getPreferences().getCurrentApiKey())); } else if (validationType.equals(ValidationType.UNKNOWN_ERROR)) { AndroidHelper.shortToast(getBaseContext(), "Unknown error. ¯\\_(ツ)_/¯"); } }
@Override public void onLoginSuccess(final LinodeUser linodeUser) { LinodeApi.getInstance().saveLinodeUser(linodeUser); LinodeApi.getInstance().switchAccount(linodeUser); ProfileDrawerItem profileDrawerItem = new ProfileDrawerItem() .withName(linodeUser.getUsername()) .withIcon(linodeUser.getProfileImageUrl()); accountHeader.setActiveProfile(profileDrawerItem); }
private AccountHeader buildHeader() { final AccountHeaderBuilder headerBuilder = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header_img); headerBuilder.withOnAccountHeaderListener(this); final long PROFILE = 100000; ProfileSettingDrawerItem settingDrawerItem = new ProfileSettingDrawerItem() .withName("Add Account") .withDescription("Sign into another Linode account") .withIcon( new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add) .actionBar() .paddingDp(5) .colorRes(R.color.material_drawer_primary_text)) .withIdentifier(PROFILE); headerBuilder.addProfiles(settingDrawerItem); if (!LinodeApi.getInstance().getLinodeUsers().isEmpty()) { String username, password, token; username = LinodePreferences.getInstance(getBaseContext()).getCurrentUsername(); password = LinodePreferences.getInstance(getBaseContext()).getCurrentPassword(); token = LinodePreferences.getInstance(getBaseContext()).getCurrentApiKey(); final LinodeUser user = new LinodeUser(username, password, token); ProfileDrawerItem profileDrawerItem = new ProfileDrawerItem() .withName(LinodePreferences.getInstance(getBaseContext()).getCurrentUsername()) .withIcon(user.getProfileImageUrl()); headerBuilder.addProfiles(profileDrawerItem); } return headerBuilder.build(); }