if current_notification and current_notification.removed:
            # Stop showing the latest and show that there are no new notifications.
            current_notification = None

        if not current_notification and not all_ids:
            group[0] = NotificationFree(width, height)
        elif all_ids:
            now = time.monotonic()
            if (current_notification and current_notification.id in all_ids
                    and now - last_press < DELAY_AFTER_PRESS):
                index = all_ids.index(current_notification.id)
            else:
                index = len(all_ids) - 1
            if now - last_press >= DEBOUNCE:
                if b.value and index > 0:
                    last_press = now
                    index += -1
                if a.value and index < len(all_ids) - 1:
                    last_press = now
                    index += 1

            notification_id = all_ids[index]
            if not current_notification or current_notification.id != notification_id:
                current_notification = current_notifications[notification_id]
                print(current_notification._raw_date, current_notification)
                group[0] = apple.create_notification_widget(
                    current_notification, width, height)

    active_connection = None
    notification_service = None
            # For now, use _raw_date even though we should use a parsed version of the date.
            # pylint: disable=protected-access
            # Ignore notifications older than the currently shown one.
            if (latest_notification and
                    notification._raw_date < latest_notification._raw_date):
                continue
            new_notification = notification
            break

        if new_notification:
            print(new_notification)
            latest_notification = new_notification
            screen_updated = False
            display.show(
                apple.create_notification_widget(latest_notification,
                                                 display.width,
                                                 display.height))
        elif latest_notification and latest_notification.removed:
            # Stop showing the latest and show that there are no new notifications.
            latest_notification = None
            screen_updated = False
            display.show(NotificationFree(display.width, display.height))

        # Do not refresh the screen more often than every 180 seconds for eInk displays! Rapid
        # refreshes will damage the panel.
        if not screen_updated and display.time_to_refresh == 0:
            display.refresh()
            screen_updated = True

    active_connection = None
    notification_service = None