/** * Removes matching entries from the receiver’s dispatch table. */ public synchronized void removeObserver(final String notification, final ApptentiveNotificationObserver observer) { final ApptentiveNotificationObserverList list = findObserverList(notification); if (list != null) { list.removeObserver(observer); } }
@Override public void onReceiveNotification(ApptentiveNotification notification) { ApptentiveNotificationObserver observer = get(); if (observer != null) { observer.onReceiveNotification(notification); } }
/** * Adds an entry to the receiver’s dispatch table with an observer. * * @param useWeakReference - weak reference is used if <code>true</code> */ public synchronized void addObserver(String notification, ApptentiveNotificationObserver observer, boolean useWeakReference) { final ApptentiveNotificationObserverList list = resolveObserverList(notification); list.addObserver(observer, useWeakReference); }
@Override protected void execute() { ApptentiveNotificationCenter.defaultCenter() .postNotification(NOTIFICATION_ACTIVITY_STOPPED, NOTIFICATION_KEY_ACTIVITY, activity); } });
/** * Creates a notification with a given name and user info and posts it to the receiver. */ public synchronized void postNotification(final String name, final Map<String, Object> userInfo) { ApptentiveLog.v(NOTIFICATIONS, "Post notification: name=%s userInfo={%s}", name, StringUtils.toString(userInfo)); final ApptentiveNotificationObserverList list = findObserverList(name); if (list != null) { list.notifyObservers(new ApptentiveNotification(name, userInfo)); } }
protected void registerNotifications() { ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_INTERACTIONS_SHOULD_DISMISS, this) .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this); }
@Override public void onReceiveNotification(ApptentiveNotification notification) { list.removeObserver(o1); addResult("anonymous-observer1"); } }, STRONG_REFERENCE);
public <T> T getRequiredUserInfo(String key, Class<? extends T> valueClass) { final T userInfo = getUserInfo(key, valueClass); // TODO: Why was this assert here? Not all requests will have response data. //Assert.assertNotNull(userInfo, "Missing required user info '%s' for '%s' notification", key, name); return userInfo; }
/** * Adds an entry to the receiver’s dispatch table with an observer using strong reference. */ public synchronized ApptentiveNotificationCenter addObserver(String notification, ApptentiveNotificationObserver observer) { addObserver(notification, observer, false); return this; }
/** * Creates a notification with a given name and posts it to the receiver. */ public synchronized void postNotification(String name) { postNotification(name, EMPTY_USER_INFO); }
/** * Checks if observer or its weak references are in the list. */ private boolean contains(ApptentiveNotificationObserver observer) { return indexOf(observer) != -1; }
/** * Returns true if observer's memory was freed. */ boolean isReferenceLost() { return get() == null; } }
private void notifyFetchStarted(Conversation conversation) { ApptentiveNotificationCenter.defaultCenter() .postNotification(NOTIFICATION_CONVERSATION_TOKEN_WILL_FETCH, NOTIFICATION_KEY_CONVERSATION, conversation); }
private void registerNotifications() { ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_CONVERSATION_DATA_DID_CHANGE, this) .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this) .addObserver(NOTIFICATION_MESSAGE_STORE_DID_CHANGE, this); }
@Override public void onReceiveNotification(ApptentiveNotification notification) { list.removeObserver(o2); addResult("anonymous-observer2"); } }, STRONG_REFERENCE);
private void notifyFetchFinished(Conversation conversation, boolean successful) { ApptentiveNotificationCenter.defaultCenter() .postNotification(NOTIFICATION_CONVERSATION_TOKEN_DID_FETCH, NOTIFICATION_KEY_CONVERSATION, conversation, NOTIFICATION_KEY_SUCCESSFUL, successful ? Boolean.TRUE : Boolean.FALSE); }
private void registerNotifications() { ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_ACTIVITY_STARTED, this) .addObserver(NOTIFICATION_ACTIVITY_RESUMED, this) .addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, this) .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, this) .addObserver(NOTIFICATION_PAYLOAD_WILL_START_SEND, this) .addObserver(NOTIFICATION_PAYLOAD_DID_FINISH_SEND, this); }
private void notifyStartPolling(long interval) { ApptentiveNotificationCenter.defaultCenter() .postNotification(NOTIFICATION_MESSAGES_STARTED_POLLING, NOTIFICATION_KEY_INTERVAL, interval); }
@Override protected void execute() { ApptentiveNotificationCenter.defaultCenter() .postNotification(NOTIFICATION_PAYLOAD_WILL_START_SEND, NOTIFICATION_KEY_PAYLOAD, payload); } });
private static void notifyClientInfoChanged(AdvertisingIdClientInfo clientInfo) { ApptentiveNotificationCenter.defaultCenter() .postNotification(NOTIFICATION_ADVERTISER_ID_DID_RESOLVE, NOTIFICATION_KEY_SUCCESSFUL, clientInfo != null, NOTIFICATION_KEY_ADVERTISER_CLIENT_INFO, clientInfo); }