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
  protected void removeCredential() {
    AndroidUtil androidUtil = new AndroidUtil(this);

    try {
      YukonAccountKeeper yukonAccountKeeper =
          new YukonAccountKeeper(
              androidUtil.readFromSharedPreferences(ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, null));
      yukonAccountKeeper.setMainAccount(null);
      androidUtil.writeToSharedPreferences(
          ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, yukonAccountKeeper.toString());
    } catch (NullPointerException | JSONException e) {
      androidUtil.writeToSharedPreferences(ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, null);
    }

    credential = null;
  }
Exemplo n.º 3
0
 protected void commitYukonAccountKeeperRegister() {
   try {
     new AndroidUtil(this)
         .writeToSharedPreferences(
             ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, yukonAccountKeeper.toString());
   } catch (NullPointerException e) {
     new AndroidUtil(this).writeToSharedPreferences(ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, null);
   }
 }
Exemplo n.º 4
0
 protected void onConnectOnce() {
   System.out.println(">> CONNECTED ONCE <<");
   try {
     System.out.println(credential.getSelectedAccountName());
     System.out.println(yukonAccountKeeper.toString());
     System.out.println(getYukonAccountKeeperRegister().toString());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 5
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.º 6
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.º 7
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();
    }
  }