-
public class CampaignManagerHandles 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceCampaignManager.JITElectionCampaignListener
-
Field Summary
Fields Modifier and Type Field Description private final List<LocalCampaign>campaignListprivate LocalCampaignsResponse.GlobalCappingscappings
-
Constructor Summary
Constructors Constructor Description CampaignManager(LocalCampaignsTracker viewTracker)
-
Method Summary
Modifier and Type Method Description List<LocalCampaign>getCampaignList()Returns a copy of the loaded campaigns LocalCampaignsResponse.GlobalCappingsgetCappings()Get the global in-app cappings voidsetCappings(LocalCampaignsResponse.GlobalCappings cappings)Set the global in-app cappings static CampaignManagerprovide()voidupdateCampaignList(@NonNull() List<LocalCampaign> updatedCampaignList)Update the currently stored campaign list. voiddeleteAllCampaigns(Context context, boolean persist)Delete all campaigns List<LocalCampaign>getEligibleCampaignsSortedByPriority(@NonNull() Signal signal)Get all campaign between all of those that are satisfied by the latest application eventand sort them by priorityThis is the campaign that you'll want to display List<LocalCampaign>getFirstEligibleCampaignsRequiringSync(List<LocalCampaign> eligibleCampaigns)Get eligible campaigns requiring a JIT sync LocalCampaigngetFirstCampaignNotRequiringJITSync(@NonNull() List<LocalCampaign> eligibleCampaigns)Get the first eligible campaign not requiring a JIT sync voidverifyCampaignsEligibilityFromServer(@NonNull() List<LocalCampaign> eligibleCampaignsRequiringSync, @NonNull() CampaignManager.JITElectionCampaignListener listener)Checking with server if campaigns are still eligible synchronized booleanisJITServiceAvailable()Check if JIT sync is availableMeaning MIN_DELAY_BETWEEN_JIT_SYNC or last 'retryAfter' time respond by server is passed. LocalCampaign.SyncedJITResult.StategetSyncedJITCampaignState(LocalCampaign campaign)Check if the given campaign has been already synced recently booleanisEventWatched(@NonNull() String name)Checks if an event name will triggers at least one campaign, allowing for a fast pre-filter to check if it is worthchecking other conditions for campaigns with an event triggers List<LocalCampaign>cleanCampaignList(@NonNull() 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) booleanisOverGlobalCappings()Check if Global Cappings has been reached voidsaveCampaigns(@NonNull() Context context, @NonNull() LocalCampaignsResponse response)voidsaveCampaignsAsync(@NonNull() Context context, @NonNull() LocalCampaignsResponse response)voiddeleteSavedCampaigns(@NonNull() Context context)voiddeleteSavedCampaignsAsync(@NonNull() Context context)booleanhasSavedCampaigns(Context context)booleanloadSavedCampaignResponse(@NonNull() Context context)booleanareCampaignsLoaded()voidopenViewTracker()voidcloseViewTracker()-
-
Constructor Detail
-
CampaignManager
CampaignManager(LocalCampaignsTracker viewTracker)
-
-
Method Detail
-
getCampaignList
List<LocalCampaign> getCampaignList()
Returns a copy of the loaded campaigns
-
getCappings
LocalCampaignsResponse.GlobalCappings getCappings()
Get the global in-app cappings
-
setCappings
void setCappings(LocalCampaignsResponse.GlobalCappings cappings)
Set the global in-app cappings
-
provide
static CampaignManager provide()
-
updateCampaignList
void updateCampaignList(@NonNull() 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.
-
deleteAllCampaigns
void deleteAllCampaigns(Context context, boolean persist)
Delete all campaigns
-
getEligibleCampaignsSortedByPriority
@NonNull() List<LocalCampaign> getEligibleCampaignsSortedByPriority(@NonNull() Signal signal)
Get all campaign between all of those that are satisfied by the latest application eventand sort them by priorityThis is the campaign that you'll want to display
-
getFirstEligibleCampaignsRequiringSync
@NonNull() List<LocalCampaign> getFirstEligibleCampaignsRequiringSync(List<LocalCampaign> eligibleCampaigns)
Get eligible campaigns requiring a JIT sync
- Parameters:
eligibleCampaigns- regardless of the JIT sync
-
getFirstCampaignNotRequiringJITSync
@Nullable() LocalCampaign getFirstCampaignNotRequiringJITSync(@NonNull() List<LocalCampaign> eligibleCampaigns)
Get the first eligible campaign not requiring a JIT sync
- Parameters:
eligibleCampaigns- regardless of the JIT sync
-
verifyCampaignsEligibilityFromServer
void verifyCampaignsEligibilityFromServer(@NonNull() List<LocalCampaign> eligibleCampaignsRequiringSync, @NonNull() CampaignManager.JITElectionCampaignListener listener)
Checking with server if campaigns are still eligible
- Parameters:
eligibleCampaignsRequiringSync- campaigns to checklistener- callback
-
isJITServiceAvailable
synchronized boolean isJITServiceAvailable()
Check if JIT sync is availableMeaning MIN_DELAY_BETWEEN_JIT_SYNC or last 'retryAfter' time respond by server is passed.
-
getSyncedJITCampaignState
LocalCampaign.SyncedJITResult.State getSyncedJITCampaignState(LocalCampaign campaign)
Check if the given campaign has been already synced recently
- Parameters:
campaign- to check
-
isEventWatched
boolean isEventWatched(@NonNull() String name)
Checks if an event name will triggers at least one campaign, allowing for a fast pre-filter to check if it is worthchecking other conditions for campaigns with an event triggers
-
cleanCampaignList
List<LocalCampaign> cleanCampaignList(@NonNull() 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)
-
isOverGlobalCappings
boolean isOverGlobalCappings()
Check if Global Cappings has been reached
-
saveCampaigns
void saveCampaigns(@NonNull() Context context, @NonNull() LocalCampaignsResponse response)
-
saveCampaignsAsync
void saveCampaignsAsync(@NonNull() Context context, @NonNull() LocalCampaignsResponse response)
-
deleteSavedCampaigns
void deleteSavedCampaigns(@NonNull() Context context)
-
deleteSavedCampaignsAsync
void deleteSavedCampaignsAsync(@NonNull() Context context)
-
hasSavedCampaigns
boolean hasSavedCampaigns(Context context)
-
loadSavedCampaignResponse
boolean loadSavedCampaignResponse(@NonNull() Context context)
-
areCampaignsLoaded
boolean areCampaignsLoaded()
-
openViewTracker
void openViewTracker()
-
closeViewTracker
void closeViewTracker()
-
-
-
-