Search in sources :

Example 1 with AutoGridLayoutManager

use of com.hippo.widget.recyclerview.AutoGridLayoutManager in project EhViewer by seven332.

the class GalleryPreviewsScene method onCreateView3.

@Nullable
@Override
public View onCreateView3(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    ContentLayout contentLayout = (ContentLayout) inflater.inflate(R.layout.scene_gallery_previews, container, false);
    contentLayout.hideFastScroll();
    mRecyclerView = contentLayout.getRecyclerView();
    Context context = getContext2();
    Assert.assertNotNull(context);
    Resources resources = context.getResources();
    mAdapter = new GalleryPreviewAdapter();
    mRecyclerView.setAdapter(mAdapter);
    int columnWidth = resources.getDimensionPixelOffset(Settings.getThumbSizeResId());
    AutoGridLayoutManager layoutManager = new AutoGridLayoutManager(context, columnWidth);
    layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    int padding = LayoutUtils.dp2pix(context, 4);
    MarginItemDecoration decoration = new MarginItemDecoration(padding, padding, padding, padding, padding);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);
    mHelper = new GalleryPreviewHelper();
    contentLayout.setHelper(mHelper);
    // Only refresh for the first time
    if (!mHasFirstRefresh) {
        mHasFirstRefresh = true;
        mHelper.firstRefresh();
    }
    return contentLayout;
}
Also used : Context(android.content.Context) ContentLayout(com.hippo.widget.ContentLayout) AutoGridLayoutManager(com.hippo.widget.recyclerview.AutoGridLayoutManager) Resources(android.content.res.Resources) MarginItemDecoration(com.hippo.easyrecyclerview.MarginItemDecoration) SuppressLint(android.annotation.SuppressLint) Nullable(android.support.annotation.Nullable)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Nullable (android.support.annotation.Nullable)1 MarginItemDecoration (com.hippo.easyrecyclerview.MarginItemDecoration)1 ContentLayout (com.hippo.widget.ContentLayout)1 AutoGridLayoutManager (com.hippo.widget.recyclerview.AutoGridLayoutManager)1