private void isUsernameRegistred(String username, final ImageView icon) {
    final Runnable runNotReachable =
        new Runnable() {
          public void run() {
            errorMessage.setText(R.string.wizard_server_unavailable);
            usernameOk = false;
            icon.setImageResource(R.drawable.wizard_notok);
            createAccount.setEnabled(usernameOk && passwordOk && emailOk);
          }
        };

    try {
      XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));

      XMLRPCCallback listener =
          new XMLRPCCallback() {
            Runnable runNotOk =
                new Runnable() {
                  public void run() {
                    errorMessage.setText(R.string.wizard_username_unavailable);
                    usernameOk = false;
                    icon.setImageResource(R.drawable.wizard_notok);
                    createAccount.setEnabled(usernameOk && passwordOk && emailOk);
                  }
                };

            Runnable runOk =
                new Runnable() {
                  public void run() {
                    errorMessage.setText("");
                    icon.setImageResource(R.drawable.wizard_ok);
                    usernameOk = true;
                    createAccount.setEnabled(usernameOk && passwordOk && emailOk);
                  }
                };

            public void onResponse(long id, Object result) {
              int answer = (Integer) result;
              if (answer != 0) {
                mHandler.post(runNotOk);
              } else {
                mHandler.post(runOk);
              }
            }

            public void onError(long id, XMLRPCException error) {
              mHandler.post(runNotReachable);
            }

            public void onServerError(long id, XMLRPCServerException error) {
              mHandler.post(runNotReachable);
            }
          };

      client.callAsync(listener, "check_account", username);
    } catch (Exception ex) {
      mHandler.post(runNotReachable);
    }
  }
 /**
  * Login to server and get token
  *
  * @return Token
  */
 private void login(XMLRPCCallback callback) {
   try {
     XMLRPCClient client =
         new XMLRPCClient(new URL(mApiUrl.replace("http://", "https://")), mUserAgent);
     client.callAsync(callback, "LogIn", "", "", "en", mUserAgent);
   } catch (MalformedURLException e) {
     e.printStackTrace();
     // Just catch and fail
   }
 }
 /**
  * Search for subtitles by imdbId, season and episode
  *
  * @param episode Episode
  * @param token Login token
  * @return SRT URL
  */
 private void search(Episode episode, String token, XMLRPCCallback callback) {
   try {
     XMLRPCClient client = new XMLRPCClient(new URL(mApiUrl), mUserAgent);
     Map<String, String> option = new HashMap<>();
     option.put("imdbid", episode.imdbId.replace("tt", ""));
     option.put("season", String.format(Locale.US, "%d", episode.season));
     option.put("episode", String.format(Locale.US, "%d", episode.episode));
     option.put("sublanguageid", "all");
     client.callAsync(callback, "SearchSubtitles", token, new Object[] {option});
   } catch (MalformedURLException e) {
     e.printStackTrace();
   }
 }
  private void createAccount(
      final String username, final String password, String email, boolean suscribe) {
    final Runnable runNotReachable =
        new Runnable() {
          public void run() {
            errorMessage.setText(R.string.wizard_server_unavailable);
          }
        };

    final Context context =
        SetupActivity.instance() == null
            ? LinphoneService.instance().getApplicationContext()
            : SetupActivity.instance();

    try {
      XMLRPCClient client = new XMLRPCClient(new URL(context.getString(R.string.wizard_url)));

      XMLRPCCallback listener =
          new XMLRPCCallback() {
            Runnable runNotOk =
                new Runnable() {
                  public void run() {
                    errorMessage.setText(R.string.wizard_failed);
                  }
                };

            Runnable runOk =
                new Runnable() {
                  public void run() {
                    SetupActivity.instance()
                        .saveCreatedAccount(
                            username, password, context.getString(R.string.default_domain));
                    SetupActivity.instance().displayWizardConfirm(username);
                  }
                };

            public void onResponse(long id, Object result) {
              int answer = (Integer) result;
              if (answer != 0) {
                mHandler.post(runNotOk);
              } else {
                mHandler.post(runOk);
              }
            }

            public void onError(long id, XMLRPCException error) {
              mHandler.post(runNotReachable);
            }

            public void onServerError(long id, XMLRPCServerException error) {
              mHandler.post(runNotReachable);
            }
          };

      client.callAsync(
          listener,
          "create_account_with_useragent",
          username,
          password,
          email,
          LinphoneManager.getInstance().getUserAgent());
    } catch (Exception ex) {
      mHandler.post(runNotReachable);
    }
  }