private void initializeListData() { mListData = new ArrayList<Integer>(); // Add duration and suppression at the top mListData.add(LIST_POS_DURATION, mNotifDesc.getDuration()); mListData.add(LIST_POS_SUPPRESSION, mNotifDesc.getSuppression()); // Add something at the repeat header pos to make the array index // consistent mListData.add(LIST_POS_REPEAT_HEADER, 0); // Now add all the repeat items at the end mListData.addAll(mNotifDesc.getSortedRepeats()); }
/* * Helper function to prepare the list of active surveys corresponding * to trigger. * * A trigger is active if it has not expired (the notification duration * has not been reached) after going off the last time. * * All surveys associated with an active active trigger are active * - EXCEPT those which have already been taken by the user within * the suppression window. */ private static HashSet<String> getActiveSurveys(Context context, Cursor trig) { HashSet<String> actSurveys = new HashSet<String>(); String runTime = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_RUNTIME_DESCRIPT)); String notif = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_NOTIF_DESCRIPT)); String actions = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_TRIG_ACTION_DESCRIPT)); String campaignUrn = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_CAMPAIGN_URN)); Log.i(DEBUG_TAG, "NotifSurveyAdaptor: Calculating active surveys for trigger"); TriggerRunTimeDesc rtDesc = new TriggerRunTimeDesc(); NotifDesc notifDesc = new NotifDesc(); TriggerActionDesc actDesc = new TriggerActionDesc(); if (!rtDesc.loadString(runTime) || !notifDesc.loadString(notif) || !actDesc.loadString(actions)) { Log.w(DEBUG_TAG, "NotifSurveyAdaptor: Descritptor(s) failed to parse"); return actSurveys; } if (!rtDesc.hasTriggerTimeStamp()) { Log.i(DEBUG_TAG, "NotifSurveyAdaptor: Trigger time stamp is invalid"); return actSurveys; } long now = System.currentTimeMillis(); long trigTS = rtDesc.getTriggerTimeStamp(); if (trigTS > now) { Log.w(DEBUG_TAG, "NotifSurveyAdaptor: Trigger time stamp is in the future!"); return actSurveys; } // How long it has been since the trigger went off long elapsedMS = now - trigTS; long durationMS = notifDesc.getDuration() * 60000; long suppressMS = notifDesc.getSuppression() * 60000; if (elapsedMS < durationMS) { // The trigger has not expired, check each survey String[] surveys = actDesc.getSurveys(); for (int i = 0; i < surveys.length; i++) { // Has the survey been taken in within the // suppression window? if (IsSurveyTaken(context, campaignUrn, surveys[i], trigTS - suppressMS)) { continue; } // Add the active survey to the set actSurveys.add(surveys[i]); } } return actSurveys; }