@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view); Glide.with(this) .load(R.raw.large_giphy_logo) .into(giphyLogoView); RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list); LinearLayoutManager layoutManager = new LinearLayoutManager(this); gifList.setLayoutManager(layoutManager); RequestBuilder<Drawable> gifItemRequest = Glide.with(this).asDrawable(); ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>(); adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider); gifList.setAdapter(adapter); RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, 4); gifList.addOnScrollListener(preloader); }
@Override public void onLoadFinished(Loader<List<MediaStoreData>> loader, List<MediaStoreData> mediaStoreData) { GlideRequests glideRequests = GlideApp.with(this); RecyclerAdapter adapter = new RecyclerAdapter(getActivity(), mediaStoreData, glideRequests); RecyclerViewPreloader<MediaStoreData> preloader = new RecyclerViewPreloader<>(glideRequests, adapter, adapter, 3); recyclerView.addOnScrollListener(preloader); recyclerView.setAdapter(adapter); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view); GlideApp.with(this) .load(R.raw.large_giphy_logo) .into(giphyLogoView); RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list); LinearLayoutManager layoutManager = new LinearLayoutManager(this); gifList.setLayoutManager(layoutManager); RequestBuilder<Drawable> gifItemRequest = GlideApp.with(this) .asDrawable(); ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>(); adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider); gifList.setAdapter(adapter); RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(GlideApp.with(this), adapter, preloadSizeProvider, 4); gifList.addOnScrollListener(preloader); gifList.setRecyclerListener(new RecyclerListener() { @Override public void onViewRecycled(ViewHolder holder) { // This is an optimization to reduce the memory usage of RecyclerView's recycled view pool // and good practice when using Glide with RecyclerView. GifViewHolder gifViewHolder = (GifViewHolder) holder; GlideApp.with(MainActivity.this).clear(gifViewHolder.gifView); } }); }
private void setItems(RecyclerView recyclerView, ArrayList<LayoutElementParcelable> arrayList, boolean invalidate) { if(preloader != null) { recyclerView.removeOnScrollListener(preloader); preloader = null; } itemsDigested.clear(); offset = 0; stoppedAnimation = false; ArrayList<IconDataParcelable> uris = new ArrayList<>(itemsDigested.size()); for (LayoutElementParcelable e : arrayList) { itemsDigested.add(new ListItem(e)); uris.add(e != null? e.iconData:null); } if (mainFrag.IS_LIST && itemsDigested.size() > 0) { itemsDigested.add(new ListItem(EMPTY_LAST_ITEM)); uris.add(null); } for (int i = 0; i < itemsDigested.size(); i++) { itemsDigested.get(i).setAnimate(false); } if (showHeaders) { createHeaders(invalidate, uris); } sizeProvider = new RecyclerPreloadSizeProvider(this); modelProvider = new RecyclerPreloadModelProvider(mainFrag, uris, mainFrag.SHOW_THUMBS); preloader = new RecyclerViewPreloader<>(GlideApp.with(mainFrag), modelProvider, sizeProvider, GlideConstants.MAX_PRELOAD_FILES); recyclerView.addOnScrollListener(preloader); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments(); photoSize = args.getInt(IMAGE_SIZE_KEY); thumbnail = args.getBoolean(THUMBNAIL_KEY); fullRequest = GlideApp.with(this) .asDrawable() .centerCrop() .transition(withNoTransition()); thumbnailRequest = GlideApp.with(this) .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .centerCrop() .override(Api.SQUARE_THUMB_SIZE) .transition(withNoTransition()); preloadRequest = thumbnail ? thumbnailRequest.clone().priority(Priority.HIGH) : fullRequest; final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false); final int gridMargin = getResources().getDimensionPixelOffset(R.dimen.grid_margin); int spanCount = getResources().getDisplayMetrics().widthPixels / (photoSize + (2 * gridMargin)); grid = (RecyclerView) result.findViewById(R.id.flickr_photo_grid); layoutManager = new GridLayoutManager(getActivity(), spanCount); grid.setLayoutManager(layoutManager); grid.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.set(gridMargin, gridMargin, gridMargin, gridMargin); } }); grid.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { PhotoViewHolder photoViewHolder = (PhotoViewHolder) holder; GlideApp.with(FlickrPhotoGrid.this).clear(photoViewHolder.imageView); } }); int heightCount = getResources().getDisplayMetrics().heightPixels / photoSize; grid.getRecycledViewPool().setMaxRecycledViews(0, spanCount * heightCount * 2); grid.setItemViewCacheSize(0); adapter = new PhotoAdapter(); grid.setAdapter(adapter); FixedPreloadSizeProvider<Photo> preloadSizeProvider = new FixedPreloadSizeProvider<>(photoSize, photoSize); RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, args.getInt(PRELOAD_KEY)); grid.addOnScrollListener(preloader); if (currentPhotos != null) { adapter.setPhotos(currentPhotos); } if (savedInstanceState != null) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); grid.scrollToPosition(index); } return result; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View result = inflater.inflate(R.layout.flickr_photo_list, container, false); list = (RecyclerView) result.findViewById(R.id.flickr_photo_list); layoutManager = new LinearLayoutManager(getActivity()); list.setLayoutManager(layoutManager); adapter = new FlickrPhotoListAdapter(); list.setAdapter(adapter); preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), adapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); list.addOnScrollListener(preloader); list.setItemViewCacheSize(0); if (currentPhotos != null) { adapter.setPhotos(currentPhotos); } final GlideRequests glideRequests = GlideApp.with(this); fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Api.SQUARE_THUMB_SIZE) .transition(withCrossFade()); list.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { PhotoTitleViewHolder vh = (PhotoTitleViewHolder) holder; glideRequests.clear(vh.imageView); } }); if (savedInstanceState != null) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); layoutManager.scrollToPositionWithOffset(index, offset); } return result; }
@Override public View onCreateView( @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = Preconditions.checkNotNull(getArguments()); photoSize = args.getInt(IMAGE_SIZE_KEY); thumbnail = args.getBoolean(THUMBNAIL_KEY); fullRequest = GlideApp.with(this) .asDrawable() .centerCrop(); thumbnailRequest = GlideApp.with(this) .asDrawable() .centerCrop() .override(Api.SQUARE_THUMB_SIZE); preloadRequest = thumbnail ? thumbnailRequest.clone().priority(Priority.HIGH) : fullRequest; final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false); final int gridMargin = getResources().getDimensionPixelOffset(R.dimen.grid_margin); int spanCount = getResources().getDisplayMetrics().widthPixels / (photoSize + (2 * gridMargin)); grid = (RecyclerView) result.findViewById(R.id.flickr_photo_grid); layoutManager = new GridLayoutManager(getActivity(), spanCount); grid.setLayoutManager(layoutManager); grid.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.set(gridMargin, gridMargin, gridMargin, gridMargin); } }); grid.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { PhotoViewHolder photoViewHolder = (PhotoViewHolder) holder; GlideApp.with(FlickrPhotoGrid.this).clear(photoViewHolder.imageView); } }); int heightCount = getResources().getDisplayMetrics().heightPixels / photoSize; grid.getRecycledViewPool().setMaxRecycledViews(0, spanCount * heightCount * 2); grid.setItemViewCacheSize(0); adapter = new PhotoAdapter(); grid.setAdapter(adapter); FixedPreloadSizeProvider<Photo> preloadSizeProvider = new FixedPreloadSizeProvider<>(photoSize, photoSize); RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, args.getInt(PRELOAD_KEY)); grid.addOnScrollListener(preloader); if (currentPhotos != null) { adapter.setPhotos(currentPhotos); } if (savedInstanceState != null) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); grid.scrollToPosition(index); } return result; }
@Override public View onCreateView( @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View result = inflater.inflate(R.layout.flickr_photo_list, container, false); list = (RecyclerView) result.findViewById(R.id.flickr_photo_list); layoutManager = new LinearLayoutManager(getActivity()); list.setLayoutManager(layoutManager); adapter = new FlickrPhotoListAdapter(); list.setAdapter(adapter); preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), adapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); list.addOnScrollListener(preloader); list.setItemViewCacheSize(0); if (currentPhotos != null) { adapter.setPhotos(currentPhotos); } final GlideRequests glideRequests = GlideApp.with(this); fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Api.SQUARE_THUMB_SIZE) .transition(withCrossFade()); list.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { PhotoTitleViewHolder vh = (PhotoTitleViewHolder) holder; glideRequests.clear(vh.imageView); } }); if (savedInstanceState != null) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); layoutManager.scrollToPositionWithOffset(index, offset); } return result; }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setRefreshing(false); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new UserAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<User> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<User> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setRefreshing(false); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new PhotoAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photos> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setRefreshing(false); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new CollectionAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Collection> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Collection> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); if (null == getActivity()) return; mLocalBroadcastManager = LocalBroadcastManager.getInstance(getActivity()); mRefreshBroadcastReceiver = new RefreshBroadcastReceiver(); mLocalBroadcastManager.registerReceiver(mRefreshBroadcastReceiver, new IntentFilter("refresh")); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new PhotoAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photos> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(320) .transition(withCrossFade()); mAdapter = new PhotoAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photos> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new PhotoAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photos> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); if (null == getActivity()) return; mLocalBroadcastManager = LocalBroadcastManager.getInstance(getActivity()); mRefreshBroadcastReceiver = new RefreshBroadcastReceiver(); mLocalBroadcastManager.registerReceiver(mRefreshBroadcastReceiver, new IntentFilter("refresh")); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new PhotoAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setItemViewCacheSize(10); mRecyclerView.setDrawingCacheEnabled(true); mRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Photos> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Photos> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); if (null == getActivity()) return; mLocalBroadcastManager = LocalBroadcastManager.getInstance(getActivity()); mRefreshBroadcastReceiver = new RefreshBroadcastReceiver(); mLocalBroadcastManager.registerReceiver(mRefreshBroadcastReceiver, new IntentFilter("refresh")); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new CollectionAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Collection> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Collection> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } }
@Override public void bindEvenListener(@Nullable Bundle savedInstanceState) { super.bindEvenListener(savedInstanceState); allowSwipeBack(false); unbinder = ButterKnife.bind(this, viewDelegate.getRootView()); mDataManager = new DataManager(); mSwipeRefreshLayout.setOnRefreshListener(this); mDatas = new ArrayList<>(); final GlideRequests glideRequests = GlideApp.with(PixelsApplication.getInstance()); GlideRequest<Drawable> fullRequest = glideRequests .asDrawable() .centerCrop() .placeholder(new ColorDrawable(Color.GRAY)); GlideRequest<Drawable> thumbRequest = glideRequests .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .transition(withCrossFade()); mAdapter = new CollectionAdapter(fullRequest, thumbRequest); mAdapter.setOnLoadMoreListener(this, mRecyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); ViewPreloadSizeProvider<Collection> preloadSizeProvider = new ViewPreloadSizeProvider<>(); RecyclerViewPreloader<Collection> preloader = new RecyclerViewPreloader<>( GlideApp.with(this), mAdapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS); mRecyclerView.addOnScrollListener(preloader); mRecyclerView.setItemViewCacheSize(0); mRecyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() { @Override public void onViewRecycled(RecyclerView.ViewHolder holder) { BaseViewHolder holder1 = (BaseViewHolder) holder; AppCompatImageView imageView = holder1.getView(R.id.item_image); if (null != imageView) { glideRequests.clear(imageView); } } }); if (null != savedInstanceState) { int index = savedInstanceState.getInt(STATE_POSITION_INDEX); int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET); mLayoutManager.scrollToPositionWithOffset(index, offset); } RxView.clicks(mRetryBtn).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() { @Override public void accept(Object o) throws Exception { mSwipeRefreshLayout.setVisibility(View.VISIBLE); mStateView.setVisibility(View.GONE); startRefresh(); } }); }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); PreloadingAdapter adapter = new PreloadingAdapter(Glide.with(this), generateImages()); listView.setAdapter(adapter); listView.addOnScrollListener(new RecyclerViewPreloader<>(adapter, adapter, 5)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); ButterKnife.bind(this); setupSearchView(); dataManager = new SearchDataManager(this) { @Override public void onDataLoaded(List<? extends PlaidItem> data) { if (data != null && data.size() > 0) { if (results.getVisibility() != View.VISIBLE) { TransitionManager.beginDelayedTransition(container, getTransition(R.transition.search_show_results)); progress.setVisibility(View.GONE); results.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE); } adapter.addAndResort(data); } else { TransitionManager.beginDelayedTransition( container, getTransition(R.transition.auto)); progress.setVisibility(View.GONE); setNoResultsVisibility(View.VISIBLE); } } }; ViewPreloadSizeProvider<Shot> shotPreloadSizeProvider = new ViewPreloadSizeProvider<>(); adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this), shotPreloadSizeProvider); setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this)); results.setAdapter(adapter); results.setItemAnimator(new SlideInItemAnimator()); GridLayoutManager layoutManager = new GridLayoutManager(this, columns); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return adapter.getItemColumnSpan(position); } }); results.setLayoutManager(layoutManager); results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) { @Override public void onLoadMore() { dataManager.loadMore(); } }); results.setHasFixedSize(true); RecyclerViewPreloader<Shot> shotPreloader = new RecyclerViewPreloader<>(this, adapter, shotPreloadSizeProvider, 4); results.addOnScrollListener(shotPreloader); setupTransitions(); onNewIntent(getIntent()); ShortcutHelper.reportSearchUsed(this); }