Search in sources :

Example 6 with SnapHelper

use of android.support.v7.widget.SnapHelper in project AndelaMedManager by jumaallan.

the class MainActivity method setListData.

public void setListData(final List<Medicine> medicineList) {
    this.medicineList = medicineList;
    if (medicineList.isEmpty()) {
        emptyFrame.setVisibility(View.VISIBLE);
    } else {
        cardMedDaily.setVisibility(View.VISIBLE);
        DailyMedicineStatisticsAdapter dailyMedicineStatisticsAdapter = new DailyMedicineStatisticsAdapter(this, medicineList, (v, position) -> {
            Medicine medicine = medicineList.get(position);
            Intent intent = new Intent(getApplicationContext(), MedicineActivity.class);
            Bundle b = new Bundle();
            b.putString("name", medicine.getName());
            b.putString("description", medicine.getDescription());
            b.putString("interval", medicine.getInterval());
            b.putString("pills", medicine.getPills());
            b.putString("pillsTaken", medicine.getPillsTaken());
            b.putBoolean("true", medicine.isHasNotification());
            b.putString("startDate", medicine.getStartDate());
            b.putString("endDate", medicine.getEndDate());
            b.putInt("days", medicine.getDays());
            intent.putExtras(b);
            startActivity(intent);
        });
        recyclerViewDailyMedicineStatistics.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        // add pager behavior
        PagerSnapHelper snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(recyclerViewDailyMedicineStatistics);
        // pager indicator
        recyclerViewDailyMedicineStatistics.addItemDecoration(new CirclePagerIndicatorDecoration());
        recyclerViewDailyMedicineStatistics.setAdapter(dailyMedicineStatisticsAdapter);
        DailyMedicineAdapter dailyMedicineAdapter = new DailyMedicineAdapter(this, medicineList, (v, position) -> {
            Medicine medicine = medicineList.get(position);
            Intent intent = new Intent(MainActivity.this.getApplicationContext(), MedicineActivity.class);
            Bundle b = new Bundle();
            b.putString("name", medicine.getName());
            b.putString("description", medicine.getDescription());
            b.putString("interval", medicine.getInterval());
            b.putString("pills", medicine.getPills());
            b.putString("pillsTaken", medicine.getPillsTaken());
            b.putBoolean("true", medicine.isHasNotification());
            b.putString("startDate", medicine.getStartDate());
            b.putString("endDate", medicine.getEndDate());
            b.putInt("days", medicine.getDays());
            intent.putExtras(b);
            MainActivity.this.startActivity(intent);
        });
        recyclerViewDailyMedicine.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerViewDailyMedicine.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        recyclerViewDailyMedicine.setAdapter(dailyMedicineAdapter);
    }
}
Also used : Medicine(com.androidstudy.andelamedmanager.data.model.Medicine) DailyMedicineAdapter(com.androidstudy.andelamedmanager.ui.medicine.adapter.DailyMedicineAdapter) Bundle(android.os.Bundle) DailyMedicineStatisticsAdapter(com.androidstudy.andelamedmanager.ui.medicine.adapter.DailyMedicineStatisticsAdapter) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) CirclePagerIndicatorDecoration(com.androidstudy.andelamedmanager.util.CirclePagerIndicatorDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration)

Example 7 with SnapHelper

use of android.support.v7.widget.SnapHelper in project PLDroidPlayer by pili-engineering.

the class ShortVideoListFragment method initView.

private void initView(View root) {
    mVideoList = root.findViewById(R.id.video_list);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    mVideoList.setLayoutManager(layoutManager);
    mVideoList.setHasFixedSize(true);
    PagerSnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(mVideoList);
    mVideoView = new PLShortVideoTextureView(getContext());
    mVideoView.setOnPreparedListener(new PLOnPreparedListener() {

        @Override
        public void onPrepared(int preparedTime) {
            mVideoView.start();
        }
    });
    mShortVideoListAdapter = new ShortVideoListAdapter(mItemList, mVideoView);
    mVideoList.setAdapter(mShortVideoListAdapter);
    mVideoList.addOnScrollListener(mOnScrollListener);
    if (mShouldPlay) {
        mVideoList.post(new Runnable() {

            @Override
            public void run() {
                startCurVideoView();
                mShouldPlay = false;
            }
        });
    }
}
Also used : PLOnPreparedListener(com.pili.pldroid.player.PLOnPreparedListener) PLShortVideoTextureView(com.pili.pldroid.player.widget.PLShortVideoTextureView) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 PagerSnapHelper (android.support.v7.widget.PagerSnapHelper)5 RecyclerView (android.support.v7.widget.RecyclerView)3 SnapHelper (android.support.v7.widget.SnapHelper)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 LinearSnapHelper (android.support.v7.widget.LinearSnapHelper)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 SimpleDateFormat (java.text.SimpleDateFormat)2 PendingIntent (android.app.PendingIntent)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 Unbinder (butterknife.Unbinder)1