Package com.batch.android.localcampaigns
Class CampaignManager
- java.lang.Object
-
- com.batch.android.localcampaigns.CampaignManager
-
public class CampaignManager extends java.lang.ObjectHandles 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 static interfaceCampaignManager.JITElectionCampaignListener
-
Constructor Summary
Constructors Constructor Description CampaignManager(LocalCampaignsTracker viewTracker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanareCampaignsLoaded()java.util.List<LocalCampaign>cleanCampaignList(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)voidcloseViewTracker()voiddeleteAllCampaigns(android.content.Context context, boolean persist)Delete all campaignsvoiddeleteSavedCampaigns(android.content.Context context)voiddeleteSavedCampaignsAsync(android.content.Context context)java.util.List<LocalCampaign>getCampaignList()Returns a copy of the loaded campaignsLocalCampaignsResponse.GlobalCappingsgetCappings()Get the global in-app cappingsjava.util.List<LocalCampaign>getEligibleCampaignsSortedByPriority(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 displayLocalCampaigngetFirstCampaignNotRequiringJITSync(java.util.List<LocalCampaign> eligibleCampaigns)Get the first eligible campaign not requiring a JIT syncjava.util.List<LocalCampaign>getFirstEligibleCampaignsRequiringSync(java.util.List<LocalCampaign> eligibleCampaigns)Get eligible campaigns requiring a JIT syncLocalCampaign.SyncedJITResult.StategetSyncedJITCampaignState(LocalCampaign campaign)Check if the given campaign has been already synced recentlyViewTrackergetViewTracker()booleanhasSavedCampaigns(android.content.Context context)protected booleanisCampaignDisplayable(LocalCampaign campaign)Checks if the campaign is displayable according to general conditions: - Capping checks - Current date over start date - Minimum API level - etc...protected booleanisCampaignOverCapping(LocalCampaign campaign, boolean ignoreMinInterval)Checks if a campaign is over its global capping.booleanisEventWatched(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 triggersbooleanisJITServiceAvailable()Check if JIT sync is available Meaning MIN_DELAY_BETWEEN_JIT_SYNC or last 'retryAfter' time respond by server is passed.booleanisOverGlobalCappings()Check if Global Cappings has been reachedbooleanloadSavedCampaignResponse(android.content.Context context)voidopenViewTracker()static CampaignManagerprovide()voidsaveCampaigns(android.content.Context context, LocalCampaignsResponse response)voidsaveCampaignsAsync(android.content.Context context, LocalCampaignsResponse response)voidsetCappings(LocalCampaignsResponse.GlobalCappings cappings)Set the global in-app cappingsvoidupdateCampaignList(java.util.List<LocalCampaign> updatedCampaignList)Update the currently stored campaign list.voidverifyCampaignsEligibilityFromServer(java.util.List<LocalCampaign> eligibleCampaignsRequiringSync, CampaignManager.JITElectionCampaignListener listener)Checking with server if campaigns are still eligible
-
-
-
Constructor Detail
-
CampaignManager
public CampaignManager(@NonNull LocalCampaignsTracker viewTracker)
-
-
Method Detail
-
provide
public static CampaignManager provide()
-
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
-
deleteAllCampaigns
public void deleteAllCampaigns(android.content.Context context, boolean persist) throws PersistenceExceptionDelete all campaigns- Throws:
PersistenceException
-
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 checklistener- 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
-
getSyncedJITCampaignState
public LocalCampaign.SyncedJITResult.State getSyncedJITCampaignState(LocalCampaign campaign)
Check if the given campaign has been already synced recently- Parameters:
campaign- to check- Returns:
- a
LocalCampaign.SyncedJITResult.State
-
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
-
getCappings
public LocalCampaignsResponse.GlobalCappings getCappings()
Get the global in-app cappings- Returns:
- cappings
-
setCappings
public void setCappings(LocalCampaignsResponse.GlobalCappings cappings)
Set the global in-app cappings- Parameters:
cappings-
-
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)
-
isCampaignOverCapping
protected boolean isCampaignOverCapping(LocalCampaign campaign, boolean ignoreMinInterval) throws ViewTrackerUnavailableException
Checks if a campaign is over its global capping.- Throws:
ViewTrackerUnavailableException
-
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()
-
getViewTracker
public ViewTracker getViewTracker()
-
-