private void notifyChange() { Runtime.postToMainThread( () -> { for (ModelChangedListener<UserVM> l : listeners) { l.onChanged(UserVM.this); } }); }
public void requestSms( String phone, final JsAuthSuccessClosure success, final JsAuthErrorClosure error) { try { long res = Long.parseLong(phone); messenger .requestStartPhoneAuth(res) .start( new CommandCallback<AuthState>() { @Override public void onResult(AuthState res) { success.onResult(Enums.convert(res)); } @Override public void onError(Exception e) { String tag = "INTERNAL_ERROR"; String message = "Internal error"; boolean canTryAgain = false; if (e instanceof RpcException) { tag = ((RpcException) e).getTag(); message = e.getMessage(); canTryAgain = ((RpcException) e).isCanTryAgain(); } error.onError(tag, message, canTryAgain, getAuthState()); } }); } catch (Exception e) { Log.e(TAG, e); im.actor.runtime.Runtime.postToMainThread( new Runnable() { @Override public void run() { error.onError("PHONE_NUMBER_INVALID", "Invalid phone number", false, getAuthState()); } }); } }
public void sendCode( String code, final JsAuthSuccessClosure success, final JsAuthErrorClosure error) { try { messenger .validateCode(code) .start( new CommandCallback<AuthState>() { @Override public void onResult(AuthState res) { success.onResult(Enums.convert(res)); } @Override public void onError(Exception e) { String tag = "INTERNAL_ERROR"; String message = "Internal error"; boolean canTryAgain = false; if (e instanceof RpcException) { tag = ((RpcException) e).getTag(); message = e.getMessage(); canTryAgain = ((RpcException) e).isCanTryAgain(); } error.onError(tag, message, canTryAgain, getAuthState()); } }); } catch (Exception e) { e.printStackTrace(); im.actor.runtime.Runtime.postToMainThread( new Runnable() { @Override public void run() { error.onError("PHONE_CODE_INVALID", "Invalid code number", false, getAuthState()); } }); } }