@Test public void bindTimelineTestNoEvents() { spyOnPresenterView(); final Timeline timeline = mock(Timeline.class); timeline.getEvents().clear(); fragment.bindTimeline(timeline); verify(fragment.presenterView).transitionIntoNoDataState(any()); }
public void bindTimeline(@NonNull final Timeline timeline) { final boolean hasEvents = !Lists.isEmpty(timeline.getEvents()); if (!DateFormatter.isLastNight(timeline.getDate())) { Tutorial.SWIPE_TIMELINE.markShown(getActivity()); } if (hasEvents) { this.presenterView.transitionOutOfNoDataState(); final Runnable backgroundAnimations = this.stateSafeExecutor.bind(() -> { final int targetColor = ContextCompat.getColor(getActivity(), R.color.timeline_background_fill); this.presenterView.startBackgroundFade(targetColor); }); final Runnable adapterAnimations = this.stateSafeExecutor.bind(() -> { this.presenterView.addItemAnimatorListener(new HandholdingOneShotListener()); this.presenterView.bindEventsToTimeline(timeline.getEvents()); }); this.presenterView.bindTimelineToHeader(timeline, backgroundAnimations, adapterAnimations); this.localUsageTracker.incrementAsync(LocalUsageTracker.Identifier.TIMELINE_SHOWN_WITH_DATA); } else { this.presenterView.transitionIntoNoDataState((header -> { final LocalDate creationDate = this.preferences.getLocalDate(PreferencesInteractor.ACCOUNT_CREATION_DATE); final boolean isAccountNew = (creationDate == null || creationDate.equals(LocalDate.now())); if (isAccountNew) { header.setDiagramResource(R.drawable.timeline_state_first_night); header.setTitle(R.string.title_timeline_first_night); header.setMessage(R.string.message_timeline_first_night); header.setAction(R.string.action_timeline_bad_data_support, null); } else if (timeline.getScoreCondition() == ScoreCondition.INCOMPLETE) { header.setDiagramResource(R.drawable.timeline_state_not_enough_data); header.setTitle(R.string.title_timeline_not_enough_data); header.setMessage(getString(R.string.title_timeline_not_enough_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NOT_ENOUGH_SLEEP_DATA)); } else { header.setDiagramResource(R.drawable.timeline_state_no_data); header.setTitle(R.string.title_timeline_no_data); header.setMessage(getString(R.string.title_timeline_no_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NO_SLEEP_DATA)); } })); } this.presenterView.setHeaderScoreEnabled(!Lists.isEmpty(timeline.getMetrics()) && hasEvents); }
TimelineFragment extends ControllerPresenterFragment<TimelineView> implements TimelineAdapter.OnItemClickListener,
        BaseFragmentPagerAdapter.Controller { public void bindTimeline(@NonNull final Timeline timeline) { final boolean hasEvents = !Lists.isEmpty(timeline.getEvents()); if (!DateFormatter.isLastNight(timeline.getDate())) { Tutorial.SWIPE_TIMELINE.markShown(getActivity()); } if (hasEvents) { this.presenterView.transitionOutOfNoDataState(); final Runnable backgroundAnimations = this.stateSafeExecutor.bind(() -> { final int targetColor = ContextCompat.getColor(getActivity(), R.color.timeline_background_fill); this.presenterView.startBackgroundFade(targetColor); }); final Runnable adapterAnimations = this.stateSafeExecutor.bind(() -> { this.presenterView.addItemAnimatorListener(new HandholdingOneShotListener()); this.presenterView.bindEventsToTimeline(timeline.getEvents()); }); this.presenterView.bindTimelineToHeader(timeline, backgroundAnimations, adapterAnimations); this.localUsageTracker.incrementAsync(LocalUsageTracker.Identifier.TIMELINE_SHOWN_WITH_DATA); } else { this.presenterView.transitionIntoNoDataState((header -> { final LocalDate creationDate = this.preferences.getLocalDate(PreferencesInteractor.ACCOUNT_CREATION_DATE); final boolean isAccountNew = (creationDate == null || creationDate.equals(LocalDate.now())); if (isAccountNew) { header.setDiagramResource(R.drawable.timeline_state_first_night); header.setTitle(R.string.title_timeline_first_night); header.setMessage(R.string.message_timeline_first_night); header.setAction(R.string.action_timeline_bad_data_support, null); } else if (timeline.getScoreCondition() == ScoreCondition.INCOMPLETE) { header.setDiagramResource(R.drawable.timeline_state_not_enough_data); header.setTitle(R.string.title_timeline_not_enough_data); header.setMessage(getString(R.string.title_timeline_not_enough_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NOT_ENOUGH_SLEEP_DATA)); } else { header.setDiagramResource(R.drawable.timeline_state_no_data); header.setTitle(R.string.title_timeline_no_data); header.setMessage(getString(R.string.title_timeline_no_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NO_SLEEP_DATA)); } })); } this.presenterView.setHeaderScoreEnabled(!Lists.isEmpty(timeline.getMetrics()) && hasEvents); } }
TimelineFragment extends ControllerPresenterFragment<TimelineView> implements TimelineAdapter.OnItemClickListener,
        BaseFragmentPagerAdapter.Controller { public void bindTimeline(@NonNull final Timeline timeline) { final boolean hasEvents = !Lists.isEmpty(timeline.getEvents()); if (!DateFormatter.isLastNight(timeline.getDate())) { Tutorial.SWIPE_TIMELINE.markShown(getActivity()); } if (hasEvents) { this.presenterView.transitionOutOfNoDataState(); final Runnable backgroundAnimations = this.stateSafeExecutor.bind(() -> { final int targetColor = ContextCompat.getColor(getActivity(), R.color.timeline_background_fill); this.presenterView.startBackgroundFade(targetColor); }); final Runnable adapterAnimations = this.stateSafeExecutor.bind(() -> { this.presenterView.addItemAnimatorListener(new HandholdingOneShotListener()); this.presenterView.bindEventsToTimeline(timeline.getEvents()); }); this.presenterView.bindTimelineToHeader(timeline, backgroundAnimations, adapterAnimations); this.localUsageTracker.incrementAsync(LocalUsageTracker.Identifier.TIMELINE_SHOWN_WITH_DATA); } else { this.presenterView.transitionIntoNoDataState((header -> { final LocalDate creationDate = this.preferences.getLocalDate(PreferencesInteractor.ACCOUNT_CREATION_DATE); final boolean isAccountNew = (creationDate == null || creationDate.equals(LocalDate.now())); if (isAccountNew) { header.setDiagramResource(R.drawable.timeline_state_first_night); header.setTitle(R.string.title_timeline_first_night); header.setMessage(R.string.message_timeline_first_night); header.setAction(R.string.action_timeline_bad_data_support, null); } else if (timeline.getScoreCondition() == ScoreCondition.INCOMPLETE) { header.setDiagramResource(R.drawable.timeline_state_not_enough_data); header.setTitle(R.string.title_timeline_not_enough_data); header.setMessage(getString(R.string.title_timeline_not_enough_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NOT_ENOUGH_SLEEP_DATA)); } else { header.setDiagramResource(R.drawable.timeline_state_no_data); header.setTitle(R.string.title_timeline_no_data); header.setMessage(getString(R.string.title_timeline_no_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NO_SLEEP_DATA)); } })); } this.presenterView.setHeaderScoreEnabled(!Lists.isEmpty(timeline.getMetrics()) && hasEvents); }  }
TimelineFragment extends ControllerPresenterFragment<TimelineView> implements TimelineAdapter.OnItemClickListener,
        BaseFragmentPagerAdapter.Controller { public void bindTimeline(@NonNull final Timeline timeline) { final boolean hasEvents = !Lists.isEmpty(timeline.getEvents()); if (!DateFormatter.isLastNight(timeline.getDate())) { Tutorial.SWIPE_TIMELINE.markShown(getActivity()); } if (hasEvents) { this.presenterView.transitionOutOfNoDataState(); final Runnable backgroundAnimations = this.stateSafeExecutor.bind(() -> { final int targetColor = ContextCompat.getColor(getActivity(), R.color.timeline_background_fill); this.presenterView.startBackgroundFade(targetColor); }); final Runnable adapterAnimations = this.stateSafeExecutor.bind(() -> { this.presenterView.addItemAnimatorListener(new HandholdingOneShotListener()); this.presenterView.bindEventsToTimeline(timeline.getEvents()); }); this.presenterView.bindTimelineToHeader(timeline, backgroundAnimations, adapterAnimations); this.localUsageTracker.incrementAsync(LocalUsageTracker.Identifier.TIMELINE_SHOWN_WITH_DATA); } else { this.presenterView.transitionIntoNoDataState((header -> { final LocalDate creationDate = this.preferences.getLocalDate(PreferencesInteractor.ACCOUNT_CREATION_DATE); final boolean isAccountNew = (creationDate == null || creationDate.equals(LocalDate.now())); if (isAccountNew) { header.setDiagramResource(R.drawable.timeline_state_first_night); header.setTitle(R.string.title_timeline_first_night); header.setMessage(R.string.message_timeline_first_night); header.setAction(R.string.action_timeline_bad_data_support, null); } else if (timeline.getScoreCondition() == ScoreCondition.INCOMPLETE) { header.setDiagramResource(R.drawable.timeline_state_not_enough_data); header.setTitle(R.string.title_timeline_not_enough_data); header.setMessage(getString(R.string.title_timeline_not_enough_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NOT_ENOUGH_SLEEP_DATA)); } else { header.setDiagramResource(R.drawable.timeline_state_no_data); header.setTitle(R.string.title_timeline_no_data); header.setMessage(getString(R.string.title_timeline_no_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NO_SLEEP_DATA)); } })); } this.presenterView.setHeaderScoreEnabled(!Lists.isEmpty(timeline.getMetrics()) && hasEvents); }  static TimelineFragment newInstance(@NonNull final LocalDate date,
                                               @Nullable final Timeline cachedTimeline); @Override void setVisibleToUser(final boolean isVisible); @Override void initializePresenterView(); @Override void onCreate(final Bundle savedInstanceState); @Override void onViewCreated(final View view, final Bundle savedInstanceState); @Override void onTrimMemory(final int level); @Override void onPause(); @Override void onDestroyView(); @Override void onDetach(); @Override void onActivityResult(final int requestCode, final int resultCode, final Intent data); @Override void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults); void showTimelineNavigator(@NonNull final LocalDate date,
                                      @Nullable final Timeline timeline); void share(); void showBreakdown(@NonNull final View sender); void dismissVisibleOverlaysAndDialogs(); @SuppressWarnings("ConstantConditions") @NonNull LocalDate getDate(); @Nullable Timeline getCachedTimeline(); void onSwipeBetweenDatesStarted(); void scrollToTop(); void update(); boolean isAtLeastThreeDaysOld(); void bindTimeline(@NonNull final Timeline timeline); void timelineUnavailable(final Throwable e); @Override void onSegmentItemClicked(final int position, final View view, @NonNull final TimelineEvent event); @Override void onEventItemClicked(final int eventPosition, @NonNull final TimelineEvent event); }
TimelineFragment extends ControllerPresenterFragment<TimelineView> implements TimelineAdapter.OnItemClickListener,
        BaseFragmentPagerAdapter.Controller { public void bindTimeline(@NonNull final Timeline timeline) { final boolean hasEvents = !Lists.isEmpty(timeline.getEvents()); if (!DateFormatter.isLastNight(timeline.getDate())) { Tutorial.SWIPE_TIMELINE.markShown(getActivity()); } if (hasEvents) { this.presenterView.transitionOutOfNoDataState(); final Runnable backgroundAnimations = this.stateSafeExecutor.bind(() -> { final int targetColor = ContextCompat.getColor(getActivity(), R.color.timeline_background_fill); this.presenterView.startBackgroundFade(targetColor); }); final Runnable adapterAnimations = this.stateSafeExecutor.bind(() -> { this.presenterView.addItemAnimatorListener(new HandholdingOneShotListener()); this.presenterView.bindEventsToTimeline(timeline.getEvents()); }); this.presenterView.bindTimelineToHeader(timeline, backgroundAnimations, adapterAnimations); this.localUsageTracker.incrementAsync(LocalUsageTracker.Identifier.TIMELINE_SHOWN_WITH_DATA); } else { this.presenterView.transitionIntoNoDataState((header -> { final LocalDate creationDate = this.preferences.getLocalDate(PreferencesInteractor.ACCOUNT_CREATION_DATE); final boolean isAccountNew = (creationDate == null || creationDate.equals(LocalDate.now())); if (isAccountNew) { header.setDiagramResource(R.drawable.timeline_state_first_night); header.setTitle(R.string.title_timeline_first_night); header.setMessage(R.string.message_timeline_first_night); header.setAction(R.string.action_timeline_bad_data_support, null); } else if (timeline.getScoreCondition() == ScoreCondition.INCOMPLETE) { header.setDiagramResource(R.drawable.timeline_state_not_enough_data); header.setTitle(R.string.title_timeline_not_enough_data); header.setMessage(getString(R.string.title_timeline_not_enough_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NOT_ENOUGH_SLEEP_DATA)); } else { header.setDiagramResource(R.drawable.timeline_state_no_data); header.setTitle(R.string.title_timeline_no_data); header.setMessage(getString(R.string.title_timeline_no_data_message)); header.setAction(R.string.action_timeline_bad_data_support, ignored -> UserSupport.showForDeviceIssue(getActivity(), UserSupport.DeviceIssue.TIMELINE_NO_SLEEP_DATA)); } })); } this.presenterView.setHeaderScoreEnabled(!Lists.isEmpty(timeline.getMetrics()) && hasEvents); }  static TimelineFragment newInstance(@NonNull final LocalDate date,
                                               @Nullable final Timeline cachedTimeline); @Override void setVisibleToUser(final boolean isVisible); @Override void initializePresenterView(); @Override void onCreate(final Bundle savedInstanceState); @Override void onViewCreated(final View view, final Bundle savedInstanceState); @Override void onTrimMemory(final int level); @Override void onPause(); @Override void onDestroyView(); @Override void onDetach(); @Override void onActivityResult(final int requestCode, final int resultCode, final Intent data); @Override void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults); void showTimelineNavigator(@NonNull final LocalDate date,
                                      @Nullable final Timeline timeline); void share(); void showBreakdown(@NonNull final View sender); void dismissVisibleOverlaysAndDialogs(); @SuppressWarnings("ConstantConditions") @NonNull LocalDate getDate(); @Nullable Timeline getCachedTimeline(); void onSwipeBetweenDatesStarted(); void scrollToTop(); void update(); boolean isAtLeastThreeDaysOld(); void bindTimeline(@NonNull final Timeline timeline); void timelineUnavailable(final Throwable e); @Override void onSegmentItemClicked(final int position, final View view, @NonNull final TimelineEvent event); @Override void onEventItemClicked(final int eventPosition, @NonNull final TimelineEvent event); static final int ZOOMED_OUT_TIMELINE_REQUEST; }