Exemplo n.º 1
0
  // region Method called after login request returns success
  private void completeLogin(BaasUser u) {
    // Create a new instance of the model, this will auto create the current user correctly
    model = Model.resetInstance();
    // model = Model.getInstance(this);   //Switch to singleton methodology

    // Attempt to retrieve the current user's model from the server
    modelRT = BaasDocument.fetchAll("model", onModelComplete);
  }
Exemplo n.º 2
0
  // region Method called after model request returns success
  private void completeModel(List<BaasDocument> r) {
    if (r == null) {
      // NO DATA TO RETRIEVE
      // THIS CASE SHOULD NEVER HAPPEN
      Log.d(LOG_TAG, "Model object from server was null!");
      showProgress(false);
      return;
    } else if (r.size() == 0 || r.size() > 1) {
      // NO DATA TO RETRIEVE
      // THIS CASE SHOULD NEVER HAPPEN
      Log.d(LOG_TAG, "Model object from server was not the correct size!: " + r.size());
      Toast.makeText(this, "Your data is corrupted, contact server admin.", Toast.LENGTH_SHORT)
          .show();
      showProgress(false);
      // launchMainActivity();
      return;
    }
    // MODEL EXISTS, set the server object in the model for later use of getting id
    // This call also extracts the id list to an instance variable
    model.setServerVersion(r.remove(0));

    // Check to see if there is any data to retrieve
    if (model.idListEmpty()) {
      // NO DATA HAS EVER BEEN WRITTEN TO THE SERVER FOR THIS USER
      // JUST LAUNCH THE MAIN ACTIVITY WITH THE CURRENT MODEL OBJECT
      launchMainActivity();
      return;
    }
    if (model.getIdList().get(4).size() != 0) { // Check if the friend array is empty
      // There is friend profiles, retrieve them
      BaasQuery fquery = BaasQuery.builder().users().build();
      for (String s : model.getIdList().get(5)) {
        fquery = fquery.buildUpon().or("user.name=" + "'" + s + "'").build();
      }
      Log.d(LOG_TAG, "Friend list request sent.");
      friendRT = BaasUser.fetchAll(fquery.buildUpon().criteria(), onFriendComplete);
    }

    if (model.getIdList().get(0).size() != 0) { // Check if the group array is empty
      BaasQuery queryG = BaasQuery.builder().build();
      for (String y : model.getIdList().get(0)) {
        Log.d(LOG_TAG, "Group added to query params: " + y);
        queryG = queryG.buildUpon().or("id=" + "'" + y + "'").build();
      }
      Log.d(LOG_TAG, "Group list request sent.");
      groupRT = BaasDocument.fetchAll("group", queryG.buildUpon().criteria(), onGroupComplete);
    }
    // Check if the event arrays are empty
    if (model.getIdList().get(1).size() != 0
        || model.getIdList().get(2).size() != 0
        || model.getIdList().get(3).size() != 0) {
      BaasQuery queryE = BaasQuery.builder().build();
      for (int i = 1; i < (model.getIdList().size() - 1); i++) {
        for (String y : model.getIdList().get(i)) {
          Log.d(LOG_TAG, "Event added to query params: " + y);
          queryE = queryE.buildUpon().or("id=" + "'" + y + "'").build();
        }
      }
      Log.d(LOG_TAG, "Event list request sent.");
      eventRT = BaasDocument.fetchAll("event", queryE.buildUpon().criteria(), onEventComplete);
    }

    // Signup current user for push notifications
    BaasCloudMessagingService box = BaasBox.messagingService();
    cloudRT = box.enable(onCloudComplete);
  }