Ejemplo n.º 1
0
 // region Method called after data request returns success
 private void completeData(List<BaasDocument> data) {
   Log.d(LOG_TAG, "Received list size: " + data.size());
   for (BaasDocument d : data) { // Figure out what to do with returned data objects
     Log.d(LOG_TAG, "Iterating through received document list.");
     // BaasDocument d = BaasDocument.from(x);    //Convert to BaasDocument
     if (d.getCollection().equals("group")) {
       Group2 g = new Group2(d); // Create group instance with BaasDocument
       // model.activeGroups.add(g);     //Old methodology
       model.getActiveGroups().add(g); // Synchronized implementation 1
       /*synchronized (model) {          //Synchronized implementation 2
           model.activeGroups.add(g);
       }*/
       Log.d(LOG_TAG, "Added group to active group list.");
     } else if (d.getCollection().equals("event")) {
       Event e = new Event(d); // Create event instance with BaasDocument
       for (int i = 1;
           i < (model.getIdList().size() - 1);
           i++) { // Iterate through all event lists
         if (model
             .getIdList()
             .get(i)
             .contains(e.getId())) { // If it contains the current event ID, add event
           switch (i) {
             case 1:
               model.getAcceptedEvents().add(e);
               Log.d(LOG_TAG, "Added event to accepted.");
               break;
             case 2:
               model.getWaitingEvents().add(e);
               Log.d(LOG_TAG, "Added event to waiting.");
               break;
             case 3:
               model.getRejectedEvents().add(e);
               Log.d(LOG_TAG, "Added event to rejected.");
               break;
             default:
               Log.d(LOG_TAG, "Event not placed: " + e);
           }
         }
       }
     } else {
       Log.d(LOG_TAG, "Data object was not group or event: " + d);
     }
   }
   // Launch main activity if the friend pulldowns are done
   if (friendRT == null && eventRT == null && groupRT == null && cloudRT == null) {
     launchMainActivity();
   }
 }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
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);
  }