001package org.intellimate.izou.sdk.frameworks.presence.provider; 002 003import org.intellimate.izou.events.EventListenerModel; 004import org.intellimate.izou.events.EventModel; 005import org.intellimate.izou.identification.Identifiable; 006import org.intellimate.izou.sdk.frameworks.presence.events.LeavingEvent; 007import org.intellimate.izou.sdk.frameworks.presence.events.PresenceEvent; 008import org.intellimate.izou.sdk.frameworks.presence.resources.PresenceResourceHelper; 009import org.intellimate.izou.sdk.util.ResourceUser; 010 011/** 012 * util class to provide information about the type of presence this addon can guarantee. 013 * You have to register the class implementing this interface as a EventListenerModel 014 * @author LeanderK 015 * @version 1.0 016 */ 017public interface PresenceProvider extends PresenceResourceHelper, Identifiable, EventListenerModel, ResourceUser { 018 /** 019 * true if the addon can guarantee that the user is around, false if not 020 * @return true if it can guarantee it, false if not 021 */ 022 boolean isStrict(); 023 024 /** 025 * gets the PresenceIndicatorLevel of the addon (mainly used for communication between presence-providing addons) 026 * @return the Level 027 */ 028 PresenceIndicatorLevel getLevel(); 029 030 /** 031 * returns true if the user might be/is present 032 * @return true if present 033 */ 034 boolean isPresent(); 035 036 /** 037 * whether it is known that the user caused the presence 038 * @return true if known, false if not 039 */ 040 boolean isKnown(); 041 042 /** 043 * when this method is called the present-status was changed 044 * @param present true if present, false if not 045 */ 046 void setGlobalPresent(boolean present); 047 048 /** 049 * returns true if the user is first encountered in the current mode 050 */ 051 boolean isFirstEncountering(); 052 053 /** 054 * when this method is called, the strict-present status was changed 055 * @param present true if present, false if not 056 */ 057 void setGlobalStrictPresent(boolean present); 058 059 /** 060 * Invoked when an activator-event occurs. 061 * 062 * @param event an instance of Event 063 */ 064 @Override 065 default void eventFired(EventModel event) { 066 if (event.containsDescriptor(LeavingEvent.ID) || event.containsDescriptor(PresenceEvent.ID)) { 067 if (event.containsDescriptor(LeavingEvent.ID)) { 068 if (event.containsDescriptor(LeavingEvent.GENERAL_DESCRIPTOR)) { 069 setGlobalPresent(false); 070 setGlobalStrictPresent(false); 071 } else if (event.containsDescriptor(LeavingEvent.STRICT_DESCRIPTOR)) { 072 nonStrictAvailable().thenAccept(available -> { 073 if (!available) 074 setGlobalPresent(false); 075 setGlobalStrictPresent(false); 076 }); 077 } 078 } else { 079 setGlobalPresent(true); 080 if (event.containsDescriptor(PresenceEvent.STRICT_DESCRIPTOR)) 081 setGlobalStrictPresent(true); 082 } 083 } 084 } 085}