Class CampaignManager


  • public class CampaignManager
    extends java.lang.Object
    Handles many local campaigns related features: - Remembers campaigns got from the backend - Saves/Restores campaigns from disk - Checks campaign condition satisfaction and triggers them - Automatically if in auto mode (if dev didn't ask Batch to delay campaigns) - Broadcasts an event/callback to the developer if in manual mode - TODO: update once decided
    • Method Detail

      • updateCampaignList

        public void updateCampaignList​(@NonNull
                                       java.util.List<LocalCampaign> updatedCampaignList)
        Update the currently stored campaign list. Clear the previous list. Calling this will triggers campaigns that have seen their conditions met.
        Parameters:
        updatedCampaignList - Updated campaign list. Can't be null
      • getEligibleCampaignsSortedByPriority

        @NonNull
        public java.util.List<LocalCampaign> getEligibleCampaignsSortedByPriority​(@NonNull
                                                                                  Signal signal)
        Get all campaign between all of those that are satisfied by the latest application event and sort them by priority This is the campaign that you'll want to display
      • getFirstEligibleCampaignsRequiringSync

        @NonNull
        public java.util.List<LocalCampaign> getFirstEligibleCampaignsRequiringSync​(java.util.List<LocalCampaign> eligibleCampaigns)
        Get eligible campaigns requiring a JIT sync
        Parameters:
        eligibleCampaigns - regardless of the JIT sync
        Returns:
        all eligible campaigns requiring a JIT sync (max: MAX_CAMPAIGNS_JIT_THRESHOLD)
      • getFirstCampaignNotRequiringJITSync

        @Nullable
        public LocalCampaign getFirstCampaignNotRequiringJITSync​(@NonNull
                                                                 java.util.List<LocalCampaign> eligibleCampaigns)
        Get the first eligible campaign not requiring a JIT sync
        Parameters:
        eligibleCampaigns - regardless of the JIT sync
        Returns:
        the first eligible campaign not requiring a JIT sync
      • verifyCampaignsEligibilityFromServer

        public void verifyCampaignsEligibilityFromServer​(@NonNull
                                                         java.util.List<LocalCampaign> eligibleCampaignsRequiringSync,
                                                         @NonNull
                                                         CampaignManager.JITElectionCampaignListener listener)
        Checking with server if campaigns are still eligible
        Parameters:
        eligibleCampaignsRequiringSync - campaigns to check
        listener - callback
      • isJITServiceAvailable

        public boolean isJITServiceAvailable()
        Check if JIT sync is available Meaning MIN_DELAY_BETWEEN_JIT_SYNC or last 'retryAfter' time respond by server is passed.
        Returns:
        true if JIT service is available
      • isEventWatched

        public boolean isEventWatched​(@NonNull
                                      java.lang.String name)
        Checks if an event name will triggers at least one campaign, allowing for a fast pre-filter to check if it is worth checking other conditions for campaigns with an event triggers
      • getCampaignList

        public java.util.List<LocalCampaign> getCampaignList()
        Returns a copy of the loaded campaigns
      • cleanCampaignList

        public java.util.List<LocalCampaign> cleanCampaignList​(@NonNull
                                                               java.util.List<LocalCampaign> campaignsToClean)
        Removes campaign that will never be ok, even in the future: - Expired campaigns - Campaigns that hit their capping - Campaigns that have a max api level too low (min api level doesn't not mean that it is busted forever)
      • isCampaignDisplayable

        protected boolean isCampaignDisplayable​(LocalCampaign campaign)
        Checks if the campaign is displayable according to general conditions: - Capping checks - Current date over start date - Minimum API level - etc...
      • isOverGlobalCappings

        public boolean isOverGlobalCappings()
        Check if Global Cappings has been reached
        Returns:
        true if cappings are reached
      • saveCampaigns

        public void saveCampaigns​(@NonNull
                                  android.content.Context context,
                                  @NonNull
                                  LocalCampaignsResponse response)
      • saveCampaignsAsync

        public void saveCampaignsAsync​(@NonNull
                                       android.content.Context context,
                                       @NonNull
                                       LocalCampaignsResponse response)
      • deleteSavedCampaigns

        public void deleteSavedCampaigns​(@NonNull
                                         android.content.Context context)
      • deleteSavedCampaignsAsync

        public void deleteSavedCampaignsAsync​(@NonNull
                                              android.content.Context context)
      • hasSavedCampaigns

        public boolean hasSavedCampaigns​(android.content.Context context)
      • loadSavedCampaignResponse

        public boolean loadSavedCampaignResponse​(@NonNull
                                                 android.content.Context context)
      • areCampaignsLoaded

        public boolean areCampaignsLoaded()
      • openViewTracker

        public void openViewTracker()
      • closeViewTracker

        public void closeViewTracker()