Skip to content

Commit

Permalink
Testing caching stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pokkst committed Mar 4, 2021
1 parent b4c4eb2 commit 296dc6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class CarouselView extends FrameLayout {
private final Context context;
private PageIndicatorView pageIndicatorView;
private RecyclerView carouselRecyclerView;
private CarouselViewAdapter carouselViewAdapter;
private CarouselLinearLayoutManager layoutManager;
private CarouselViewListener carouselViewListener;
private CarouselScrollListener carouselScrollListener;
Expand Down Expand Up @@ -114,7 +115,14 @@ private void setAdapter() {
if (this.getScaleOnScroll()) this.layoutManager.setScaleOnScroll(true);
this.layoutManager.setAllowScrolling(this.getAllowScrolling());
carouselRecyclerView.setLayoutManager(this.layoutManager);
this.carouselRecyclerView.setAdapter(new CarouselViewAdapter(getCarouselViewListener(), getResource(), getSize(), carouselRecyclerView, this.getSpacing(), this.getCarouselOffset() == OffsetType.CENTER));
if(this.carouselViewAdapter == null) {
this.carouselViewAdapter = new CarouselViewAdapter(getCarouselViewListener(), getResource(), getSize(), carouselRecyclerView, this.getSpacing(), this.getCarouselOffset() == OffsetType.CENTER);
} else {
if(this.carouselViewAdapter.getItemCount() != this.getSize()) {
this.carouselViewAdapter.setSize(this.getSize());
}
}
this.carouselRecyclerView.setAdapter(this.carouselViewAdapter);
this.snapHelper.attachToRecyclerView(this.carouselRecyclerView);
this.setScrollListener();
this.enableAutoPlay();
Expand Down Expand Up @@ -333,6 +341,7 @@ private void validate() {
public void show() {
this.validate();
this.setAdapter();
this.carouselViewAdapter.notifyDataSetChanged();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CarouselViewAdapter extends RecyclerView.Adapter<CarouselViewAdapte

private final CarouselViewListener carouselViewListener;
private final int resource;
private final int size;
private int size;
private final RecyclerView recyclerView;
private final CarouselOffset carouselOffset;
private final boolean isOffsetCenter;
Expand Down Expand Up @@ -47,6 +47,10 @@ public int getItemCount() {
return this.size;
}

public void setSize(int newSize) {
this.size = newSize;
}

static class CarouselAdapterViewHolder extends RecyclerView.ViewHolder {

CarouselAdapterViewHolder(@NonNull View itemView) {
Expand Down

0 comments on commit 296dc6d

Please sign in to comment.