use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.
the class RewardVerificationFragment method checkRewardApproved.
private void checkRewardApproved(final boolean firstCheck) {
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestInProgress(true);
}
optionsPager.setVisibility(View.INVISIBLE);
optionsTabs.setVisibility(View.INVISIBLE);
FetchCurrentUserTask task = new FetchCurrentUserTask(getContext(), new FetchCurrentUserTask.FetchUserTaskHandler() {
@Override
public void onSuccess(User user) {
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_REWARDS);
}
Lbryio.currentUser = user;
if (user.isIdentityVerified() && user.isRewardApproved()) {
// verified for rewards
LbryAnalytics.logEvent(LbryAnalytics.EVENT_REWARD_ELIGIBILITY_COMPLETED);
textSummary.setText(R.string.reward_eligible);
return;
}
if (!firstCheck) {
// show manual verification if the user is not yet reward approved
// and this is not the check when the page loads
optionsPager.setCurrentItem(3);
}
optionsPager.setVisibility(View.VISIBLE);
optionsTabs.setVisibility(View.VISIBLE);
}
@Override
public void onError(Exception error) {
showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
optionsPager.setVisibility(View.VISIBLE);
optionsTabs.setVisibility(View.VISIBLE);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_REWARDS);
}
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.
the class SignInFragment method performSignIn.
private void performSignIn(final String email, final String password) {
if (requestInProgress) {
return;
}
if (!emailSignInChecked) {
requestInProgress = true;
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestInProgress(false);
}
beforeSignInTransition();
executor.execute(new Runnable() {
@Override
public void run() {
Map<String, String> options = new HashMap<>();
options.put("email", email);
try {
Object response = Lbryio.parseResponse(Lbryio.call("user", "exists", options, Helper.METHOD_POST, getContext()));
requestInProgress = false;
if (response instanceof JSONObject) {
JSONObject json = (JSONObject) response;
boolean hasPassword = Helper.getJSONBoolean("has_password", false, json);
if (!hasPassword) {
setCurrentEmail(email);
handleUserSignInWithoutPassword(email);
return;
}
// email exists, we can use sign in flow. Show password field
setCurrentEmail(email);
emailSignInChecked = true;
displaySignInControls();
displayMagicLink();
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (ex instanceof LbryioResponseException) {
LbryioResponseException rex = (LbryioResponseException) ex;
if (rex.getStatusCode() == 412) {
// old email verification flow
setCurrentEmail(email);
handleUserSignInWithoutPassword(email);
Bundle bundle = new Bundle();
bundle.putString("email", currentEmail);
LbryAnalytics.logEvent(LbryAnalytics.EVENT_EMAIL_ADDED, bundle);
LbryAnalytics.logEvent("");
requestInProgress = false;
return;
}
}
requestInProgress = false;
restoreControls(true);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_ACCOUNT);
}
showError(ex.getMessage());
}
}
});
return;
}
if (Helper.isNullOrEmpty(password)) {
showError(getString(R.string.please_enter_signin_password));
return;
}
beforeSignInTransition();
requestInProgress = true;
executor.execute(new Runnable() {
@Override
public void run() {
Map<String, String> options = new HashMap<>();
options.put("email", email);
options.put("password", password);
try {
Object response = Lbryio.parseResponse(Lbryio.call("user", "signin", options, Helper.METHOD_POST, getContext()));
requestInProgress = false;
if (response instanceof JSONObject) {
Type type = new TypeToken<User>() {
}.getType();
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
User user = gson.fromJson(response.toString(), type);
Lbryio.currentUser = user;
addOdyseeAccountExplicitly(user.getPrimaryEmail());
finishWithWalletSync();
return;
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (ex instanceof LbryioResponseException) {
if (((LbryioResponseException) ex).getStatusCode() == 409) {
handleEmailVerificationFlow(email);
return;
}
}
showError(ex.getMessage());
requestInProgress = false;
restoreControls(true);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_ACCOUNT);
}
return;
}
requestInProgress = false;
restoreControls(true);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_ACCOUNT);
}
showError(getString(R.string.unknown_error_occurred));
}
});
}
Aggregations