@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 setAdapter(Adapter adapter) { if (adapter instanceof BaseQuickAdapter) { mReqAdapter = (BaseQuickAdapter) adapter; removeOnScrollListener(mOnScrollListener); addOnScrollListener(mOnScrollListener); } if (adapter instanceof ListPreloaderQuickAdapter) { ListPreloaderQuickAdapter tempAdapter = (ListPreloaderQuickAdapter)adapter; RecyclerViewPreloader preloader =new RecyclerViewPreloader(Glide.with(getContext()), tempAdapter, new ViewPreloadSizeProvider(), tempAdapter.getMaxPreload()); addOnScrollListener(preloader); } super.setAdapter(adapter); if (needInitAddItemDescration && null != mFamiliarDefaultItemDecoration) { needInitAddItemDescration = false; super.addItemDecoration(mFamiliarDefaultItemDecoration); } }
@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); } }); }
FeedAdapter(Activity hostActivity, @Nullable DataLoadingSubject dataLoading, int columns, boolean pocketInstalled, ViewPreloadSizeProvider<Shot> shotPreloadSizeProvider) { this.host = hostActivity; this.dataLoading = dataLoading; if (dataLoading != null) { dataLoading.registerCallback(this); } this.columns = columns; this.pocketIsInstalled = pocketInstalled; this.shotPreloadSizeProvider = shotPreloadSizeProvider; layoutInflater = LayoutInflater.from(host); comparator = new PlaidItemSorting.PlaidItemComparator(); items = new ArrayList<>(); setHasStableIds(true); // get the dribbble shot placeholder colors & badge color from the theme final TypedArray a = host.obtainStyledAttributes(R.styleable.DribbbleFeed); final int loadingColorArrayId = a.getResourceId(R.styleable.DribbbleFeed_shotLoadingPlaceholderColors, 0); if (loadingColorArrayId != 0) { int[] placeholderColors = host.getResources().getIntArray(loadingColorArrayId); shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length]; for (int i = 0; i < placeholderColors.length; i++) { shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors[i]); } } else { shotLoadingPlaceholders = new ColorDrawable[] { new ColorDrawable(Color.DKGRAY) }; } final int initialGifBadgeColorId = a.getResourceId(R.styleable.DribbbleFeed_initialBadgeColor, 0); initialGifBadgeColor = initialGifBadgeColorId != 0 ? ContextCompat.getColor(host, initialGifBadgeColorId) : 0x40ffffff; a.recycle(); }
protected FuliAdapter(Response mResponse, Context context, ViewPreloadSizeProvider<Entry> preloadSizeProvider) { super(mResponse); mContext = context; mPreloadSizeProvider = preloadSizeProvider; mPool = Glide.get(context).getBitmapPool(); }
public AppsAdapter(Context context, ThemedActivity ba, UtilitiesProviderInterface utilsProvider, AppsAdapterPreloadModel modelProvider, ViewPreloadSizeProvider<String> sizeProvider, int resourceId, AppsListFragment app) { super(context, resourceId); themedActivity = ba; this.utilsProvider = utilsProvider; this.modelProvider = modelProvider; this.sizeProvider = sizeProvider; this.context = context; this.app = app; /*for (int i = 0; i < items.size(); i++) { myChecked.put(i, false); }*/ }
public GifAdapter(Activity activity, RequestBuilder<Drawable> requestBuilder, ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider) { this.activity = activity; this.requestBuilder = requestBuilder; this.preloadSizeProvider = preloadSizeProvider; }
@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; }
GifAdapter(Activity activity, RequestBuilder<Drawable> requestBuilder, ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider) { this.activity = activity; this.requestBuilder = requestBuilder; this.preloadSizeProvider = preloadSizeProvider; }
@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 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); }