Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.SparseIntArray;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
Expand All @@ -17,7 +18,10 @@
import com.transitionseverywhere.TransitionSet;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.PagerSnapHelper;
Expand Down Expand Up @@ -53,6 +57,7 @@ public class OverflowPagerIndicator extends LinearLayout {
private RecyclerView mRecyclerView;
private OverflowDataObserver mDataObserver;

private SparseIntArray mapDrawablesIndicator = new SparseIntArray();
private int dotStrokeColor;
private int dotFillColor;

Expand Down Expand Up @@ -122,6 +127,10 @@ public void attachToRecyclerView(final RecyclerView recyclerView) {
initIndicators();
}

public void registerDrawableIndicator(@DrawableRes Integer imageRes, int viewType) {
mapDrawablesIndicator.put(viewType, imageRes);
}

void updateIndicatorsCount() {
if (mIndicatorCount != mRecyclerView.getAdapter().getItemCount()) {
initIndicators();
Expand Down Expand Up @@ -164,7 +173,7 @@ private void updateOverflowState(int position) {
float[] positionStates = new float[mIndicatorCount + 1];
Arrays.fill(positionStates, STATE_GONE);

int start = position - MAX_INDICATORS + 4;
int start = position - MAX_INDICATORS + 4;
int realStart = Math.max(0, start);

if (realStart + MAX_INDICATORS > mIndicatorCount) {
Expand Down Expand Up @@ -200,7 +209,7 @@ private void updateOverflowState(int position) {

private void updateIndicators(float[] positionStates) {
for (int i = 0; i < mIndicatorCount; i++) {
View v = getChildAt(i);
View v = getChildAt(i);
float state = positionStates[i];

if (state == STATE_GONE) {
Expand All @@ -222,13 +231,23 @@ private void createIndicators(int indicatorSize, int margin) {
}

for (int i = 0; i < mIndicatorCount; i++) {
addIndicator(mIndicatorCount > MAX_INDICATORS, indicatorSize, margin);
addIndicator(mIndicatorCount > MAX_INDICATORS, indicatorSize, margin, i);
}
}

private void addIndicator(boolean isOverflowState, int indicatorSize, int margin) {
private void addIndicator(boolean isOverflowState, int indicatorSize, int margin, int position) {
View view = new View(getContext());
view.setBackground(getDotDrawable());
int viewType = -1;
if (mRecyclerView.getAdapter() != null){
viewType = mRecyclerView.getAdapter().getItemViewType(position);
}

if (mapDrawablesIndicator.indexOfKey(viewType) > -1) {
int res = mapDrawablesIndicator.get(viewType);
view.setBackground(ContextCompat.getDrawable(getContext(), res));
}else {
view.setBackground(getDotDrawable());
}
if (isOverflowState) {
animateViewScale(view, STATE_SMALLEST);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private void initRecyclerWithIndicator(int recyclerViewId, int indicatorViewId,
recyclerView.setAdapter(adapter);

overflowPagerIndicator.attachToRecyclerView(recyclerView);
overflowPagerIndicator.registerDrawableIndicator(R.drawable.ic_play_circle_outline_black_24dp, 0);
overflowPagerIndicator.registerDrawableIndicator(R.drawable.ic_image_black_24dp, 1);

new SimpleSnapHelper(overflowPagerIndicator).attachToRecyclerView(recyclerView);

Expand Down Expand Up @@ -73,6 +75,17 @@ public int getItemCount() {
return itemCount;
}

@Override
public int getItemViewType(int position) {
if (position == 1){
return 1; //video drawable
}
else if (position == 3) {
return 99; //default getDotDrawable (viewType unknown)
}
return super.getItemViewType(position);
}

void updateItemCount(int newCount) {
itemCount = newCount;

Expand Down
9 changes: 9 additions & 0 deletions sample-app/src/main/res/drawable/ic_image_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>