@Test public void visibilityRunnable_run_withNonVisibleView_shouldCallOnNonVisibleCallback() throws Exception { when(view.getVisibility()).thenReturn(View.INVISIBLE); subject.addView(view, MIN_PERCENTAGE_VIEWED); subject.new VisibilityRunnable().run(); ArgumentCaptor<List> visibleCaptor = ArgumentCaptor.forClass(List.class); ArgumentCaptor<List> invisibleCaptor = ArgumentCaptor.forClass(List.class); verify(visibilityTrackerListener).onVisibilityChanged(visibleCaptor.capture(), invisibleCaptor.capture()); assertThat(visibleCaptor.getValue().size()).isEqualTo(0); assertThat(invisibleCaptor.getValue().size()).isEqualTo(1); }
void addView(@NonNull final View view, final int minPercentageViewed) { TrackingInfo trackingInfo = mTrackedViews.get(view); if (trackingInfo == null) { trackingInfo = new TrackingInfo(); mTrackedViews.put(view, trackingInfo); scheduleVisibilityCheck(); } trackingInfo.mMinViewablePercent = minPercentageViewed; trackingInfo.mAccessOrder = mAccessCounter; mAccessCounter++; if (mAccessCounter % NUM_ACCESSES_BEFORE_TRIMMING == 0) { trimTrackedViews(mAccessCounter - NUM_ACCESSES_BEFORE_TRIMMING); } }
VisibilityTracker { void addView(@NonNull final View view, final int minPercentageViewed) { TrackingInfo trackingInfo = mTrackedViews.get(view); if (trackingInfo == null) { trackingInfo = new TrackingInfo(); mTrackedViews.put(view, trackingInfo); scheduleVisibilityCheck(); } trackingInfo.mMinViewablePercent = minPercentageViewed; trackingInfo.mAccessOrder = mAccessCounter; mAccessCounter++; if (mAccessCounter % NUM_ACCESSES_BEFORE_TRIMMING == 0) { trimTrackedViews(mAccessCounter - NUM_ACCESSES_BEFORE_TRIMMING); } } }
VisibilityTracker { void addView(@NonNull final View view, final int minPercentageViewed) { TrackingInfo trackingInfo = mTrackedViews.get(view); if (trackingInfo == null) { trackingInfo = new TrackingInfo(); mTrackedViews.put(view, trackingInfo); scheduleVisibilityCheck(); } trackingInfo.mMinViewablePercent = minPercentageViewed; trackingInfo.mAccessOrder = mAccessCounter; mAccessCounter++; if (mAccessCounter % NUM_ACCESSES_BEFORE_TRIMMING == 0) { trimTrackedViews(mAccessCounter - NUM_ACCESSES_BEFORE_TRIMMING); } } VisibilityTracker(@NonNull final Context context); @VisibleForTesting  VisibilityTracker(@NonNull final Context context,
            @NonNull final Map<View, TrackingInfo> trackedViews,
            @NonNull final VisibilityChecker visibilityChecker,
            @NonNull final Handler visibilityHandler); }
VisibilityTracker { void addView(@NonNull final View view, final int minPercentageViewed) { TrackingInfo trackingInfo = mTrackedViews.get(view); if (trackingInfo == null) { trackingInfo = new TrackingInfo(); mTrackedViews.put(view, trackingInfo); scheduleVisibilityCheck(); } trackingInfo.mMinViewablePercent = minPercentageViewed; trackingInfo.mAccessOrder = mAccessCounter; mAccessCounter++; if (mAccessCounter % NUM_ACCESSES_BEFORE_TRIMMING == 0) { trimTrackedViews(mAccessCounter - NUM_ACCESSES_BEFORE_TRIMMING); } } VisibilityTracker(@NonNull final Context context); @VisibleForTesting  VisibilityTracker(@NonNull final Context context,
            @NonNull final Map<View, TrackingInfo> trackedViews,
            @NonNull final VisibilityChecker visibilityChecker,
            @NonNull final Handler visibilityHandler);  }
VisibilityTracker { void addView(@NonNull final View view, final int minPercentageViewed) { TrackingInfo trackingInfo = mTrackedViews.get(view); if (trackingInfo == null) { trackingInfo = new TrackingInfo(); mTrackedViews.put(view, trackingInfo); scheduleVisibilityCheck(); } trackingInfo.mMinViewablePercent = minPercentageViewed; trackingInfo.mAccessOrder = mAccessCounter; mAccessCounter++; if (mAccessCounter % NUM_ACCESSES_BEFORE_TRIMMING == 0) { trimTrackedViews(mAccessCounter - NUM_ACCESSES_BEFORE_TRIMMING); } } VisibilityTracker(@NonNull final Context context); @VisibleForTesting  VisibilityTracker(@NonNull final Context context,
            @NonNull final Map<View, TrackingInfo> trackedViews,
            @NonNull final VisibilityChecker visibilityChecker,
            @NonNull final Handler visibilityHandler);   }