Exemplo n.º 1
0
  private void onAccountChoose(String accountName) {
    try {
      YukonAccount[] secondaryAccountArray = yukonAccountKeeper.getSecondaryAccountArray();

      if (!addingAccount) {
        secondaryAccountArray = removeSecondaryAccount(secondaryAccountArray, accountName);
      }
      secondaryAccountArray =
          addSecondaryAccount(secondaryAccountArray, yukonAccountKeeper.getMainAccount());

      yukonAccountKeeper.setSecondaryAccountArray(secondaryAccountArray);
      yukonAccountKeeper.setMainAccount(new YukonAccount(null, accountName, null));

      commitYukonAccountKeeperRegister();
    } catch (JSONException e) {
      e.printStackTrace();
    }

    generateCredential();
    requestAuthorization();

    if (addingAccount) {
      addingAccount = false;
      Intent refreshIntent = new Intent(this, getClass());
      startActivity(refreshIntent);
      finish();
    }
  }
Exemplo n.º 2
0
  /*
   *  * ========== * ========== * ========== * ========== * ========== * ========== * ========== * ========== *
   *  * Credential methods:
   *  * ========== * ========== * ========== * ========== * ========== * ========== * ========== * ========== *
   */
  protected GoogleAccountCredential generateCredential() {
    String accountName;

    try {
      accountName = yukonAccountKeeper.getMainAccount().getEmail();
    } catch (NullPointerException e) {
      accountName = null;
    }

    GoogleAccountCredential credential =
        GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff())
            .setSelectedAccountName(accountName);

    GoogleRestConnectActivity.credential = credential;
    return credential;
  }
Exemplo n.º 3
0
  protected void updateMainAccountInfo() {
    try {
      YukonAccount mainAccount = yukonAccountKeeper.getMainAccount();

      if (mainAccount.getUserId() == null || mainAccount.getUserId().trim().isEmpty()) {
        new PlusIOHandler(getCredential())
            .readPerson(
                "me",
                new PersonReadCallback() {
                  @Override
                  public void onSuccess(final Person person) {
                    runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            try {
                              YukonAccount mainAccount = yukonAccountKeeper.getMainAccount();

                              mainAccount.setUserId(person.getId());
                              mainAccount.setDisplayName(person.getDisplayName());

                              yukonAccountKeeper.setMainAccount(mainAccount);
                              commitYukonAccountKeeperRegister();

                              onMainAccountInfoUpdateSuccess(yukonAccountKeeper);
                            } catch (JSONException e) {
                              e.printStackTrace();
                              onFailure(e);
                            }
                          }
                        });
                  }

                  @Override
                  public void onFailure(Exception exception) {
                    onMainAccountInfoUpdateFail(yukonAccountKeeper);
                  }
                });
      } else {
        onMainAccountInfoUpdateSuccess(yukonAccountKeeper);
      }
    } catch (NullPointerException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  @Override
  public void onStart() {
    super.onStart();

    // *Try to set the actionToolbar:
    try {
      Toolbar actionToolbar = (Toolbar) findViewById(R.id.actionToolbar);
      setSupportActionBar(actionToolbar);
    } catch (NullPointerException e) {
      System.err.println("No actionBar");
    }

    try {
      yukonAccountKeeper = getYukonAccountKeeperRegister();
    } catch (NullPointerException | JSONException e) {
      yukonAccountKeeper = new YukonAccountKeeper(null, new YukonAccount[] {});
    }

    if (yukonAccountKeeper.getMainAccount() != null) {
      tryToConnect();
    }
  }