Search in sources :

Example 26 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project Applozic-Android-SDK by AppLozic.

the class AlScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    visibleItemCount = recyclerView.getChildCount();
    if (manager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
        firstVisibleItem = gridLayoutManager.findFirstVisibleItemPosition();
        totalItemCount = gridLayoutManager.getItemCount();
    } else if (manager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
        firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
        totalItemCount = linearLayoutManager.getItemCount();
    }
    if (infiniteScrollingEnabled) {
        if (loading) {
            if (totalItemCount > previousTotal) {
                loading = false;
                previousTotal = totalItemCount;
            }
        }
        if ((totalItemCount - visibleItemCount) == 0) {
            return;
        }
        if (!loading && (totalItemCount - visibleItemCount <= firstVisibleItem + visibleThreshold)) {
            // End has been reached
            // do something
            onLoadMore();
            loading = true;
        }
    }
    if (firstVisibleItem == 0) {
        if (!controlsVisible) {
            onScrollUp();
            controlsVisible = true;
        }
        return;
    }
    if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
        onScrollDown();
        controlsVisible = false;
        scrolledDistance = 0;
    } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
        onScrollUp();
        controlsVisible = true;
        scrolledDistance = 0;
    }
    if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) {
        scrolledDistance += dy;
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 27 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SmoothRefreshLayout by dkzwm.

the class TestHorizontalRecyclerViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_horizontal_recyclerview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_horizontal_recyclerView);
    mRecyclerView = findViewById(R.id.recyclerView_with_horizontal_recyclerView);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3, LinearLayoutManager.HORIZONTAL, false));
    mRecyclerView.setHasFixedSize(true);
    mAdapter = new HorizontalRecyclerViewAdapter(this, getLayoutInflater());
    mRecyclerView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_horizontal_recyclerView);
    MaterialHeader header = new MaterialHeader(this);
    header.setColorSchemeColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    header.setPadding(PixelUtl.dp2px(this, 25), 0, PixelUtl.dp2px(this, 25), 0);
    mRefreshLayout.setHeaderView(header);
    MaterialFooter footer = new MaterialFooter(this);
    footer.setProgressBarColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    mRefreshLayout.setFooterView(footer);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setEnableAutoLoadMore(true);
    mRefreshLayout.setEnablePinContentView(true);
    mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshing() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount = list.size();
                    mAdapter.updateData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 3000);
        }

        @Override
        public void onLoadingMore() {
            Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.has_been_triggered_to_load_more, Toast.LENGTH_SHORT).show();
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount += list.size();
                    mAdapter.appendData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 3000);
        }
    });
    mRefreshLayout.setDurationToClose(800);
    mRefreshLayout.autoRefresh(false);
}
Also used : MaterialHeader(me.dkzwm.widget.srl.extra.header.MaterialHeader) MaterialFooter(me.dkzwm.widget.srl.extra.footer.MaterialFooter) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) HorizontalRecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.HorizontalRecyclerViewAdapter)

Example 28 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SmoothRefreshLayout by dkzwm.

the class TestRecyclerViewInNestedScrollViewInSrlActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_recyclerview_in_nestedscrollview_in_srl);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.arrow_back_white_72x72);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    mRecyclerView = findViewById(R.id.recyclerView_test_recyclerView_in_nestedScrollView);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
    mAdapter = new RecyclerViewAdapter(this, getLayoutInflater());
    mRecyclerView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_recyclerView_in_nestedScrollView);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshing() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 60);
                    mCount = list.size();
                    mAdapter.updateData(list);
                    mRefreshLayout.refreshComplete(500);
                }
            }, 2000);
        }

        @Override
        public void onLoadingMore() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 15);
                    mCount += list.size();
                    mAdapter.appendData(list);
                    mRefreshLayout.refreshComplete(500);
                }
            }, 2000);
        }
    });
    mRefreshLayout.autoRefresh();
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 29 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project CloudReader by youlookwhat.

the class TreeFragment method initRefreshView.

private void initRefreshView() {
    RefreshHelper.setSwipeRefreshView(bindingView.srlWan);
    bindingView.srlWan.setOnRefreshListener(() -> bindingView.srlWan.postDelayed(this::getTree, 150));
    LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
    bindingView.xrvWan.setLayoutManager(layoutManager);
    mTreeAdapter = new TreeAdapter(activity);
    bindingView.xrvWan.setAdapter(mTreeAdapter);
    HeaderItemTreeBinding oneBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.header_item_tree, null, false);
    bindingView.xrvWan.addHeaderView(oneBinding.getRoot());
    oneBinding.tvPosition.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!mTreeAdapter.isSelect()) {
                GridLayoutManager layoutManager = new GridLayoutManager(activity, 2);
                bindingView.xrvWan.setLayoutManager(layoutManager);
                oneBinding.tvPosition.setText("选择类别");
                mTreeAdapter.setSelect(true);
                mTreeAdapter.notifyDataSetChanged();
                bindingView.xrvWan.addItemDecoration(new SpacesItemDecoration(activity).setNoShowDivider(1, 0).setDrawable(R.drawable.shape_line));
            } else {
                LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
                bindingView.xrvWan.setLayoutManager(layoutManager);
                oneBinding.tvPosition.setText("发现页内容订制");
                mTreeAdapter.setSelect(false);
                mTreeAdapter.notifyDataSetChanged();
                if (bindingView.xrvWan.getItemDecorationCount() > 0) {
                    bindingView.xrvWan.removeItemDecorationAt(0);
                }
            }
        }
    });
    bindingView.xrvWan.setOnItemClickListener(new OnItemFilterClickListener() {

        @Override
        public void onSingleClick(View v, int position) {
            if (mTreeAdapter.isSelect()) {
                if (mTreeAdapter.getSelectedPosition() == position) {
                    ToastUtil.showToastLong("当前已经是\"" + mTreeAdapter.getData().get(position).getName() + "\"");
                    return;
                }
                LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
                bindingView.xrvWan.setLayoutManager(layoutManager);
                oneBinding.tvPosition.setText("发现页内容订制");
                mTreeAdapter.setSelect(false);
                mTreeAdapter.notifyDataSetChanged();
                if (bindingView.xrvWan.getItemDecorationCount() > 0) {
                    bindingView.xrvWan.removeItemDecorationAt(0);
                }
                layoutManager.scrollToPositionWithOffset(position + bindingView.xrvWan.getCustomTopItemViewCount(), 0);
                RxBus.getDefault().post(RxCodeConstants.FIND_CUSTOM, position);
            }
        }
    });
}
Also used : HeaderItemTreeBinding(com.example.jingbin.cloudreader.databinding.HeaderItemTreeBinding) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) OnItemFilterClickListener(me.jingbin.library.view.OnItemFilterClickListener) TreeAdapter(com.example.jingbin.cloudreader.adapter.TreeAdapter) SpacesItemDecoration(me.jingbin.library.decoration.SpacesItemDecoration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View)

Example 30 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project fresco by facebook.

the class DraweeRecyclerViewFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    final RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
    recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            final int imageSize = (right - left) / SPAN_COUNT;
            mResizeOptions = new ResizeOptions(imageSize, imageSize);
        }
    });
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), SPAN_COUNT);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    final SimpleAdapter adapter = new SimpleAdapter(new ArrayList<Uri>());
    recyclerView.setAdapter(adapter);
    final Spinner imageSource = view.findViewById(R.id.spinner_image_source);
    ImageSourceSpinner.INSTANCE.setup(imageSource, sampleUris(), new Function1<List<Uri>, Unit>() {

        @Override
        public Unit invoke(List<Uri> uris) {
            adapter.setData(uris);
            return null;
        }
    });
}
Also used : ImageSourceSpinner(com.facebook.fresco.samples.showcase.misc.ImageSourceSpinner) Spinner(android.widget.Spinner) Unit(kotlin.Unit) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Uri(android.net.Uri) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) RecyclerView(androidx.recyclerview.widget.RecyclerView) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)122 RecyclerView (androidx.recyclerview.widget.RecyclerView)63 View (android.view.View)45 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)16 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 ImageView (android.widget.ImageView)12 Nullable (androidx.annotation.Nullable)11 Toolbar (androidx.appcompat.widget.Toolbar)10 ViewGroup (android.view.ViewGroup)7 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 ArrayList (java.util.ArrayList)6 NonNull (androidx.annotation.NonNull)5 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)5 List (java.util.List)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 Drawable (android.graphics.drawable.Drawable)4 Handler (android.os.Handler)3