Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java recycler视图不是第一次加载,但它会在我刷新页面时加载_Java_Android Studio_Android Fragments_Android Recyclerview_Android Adapter - Fatal编程技术网

Java recycler视图不是第一次加载,但它会在我刷新页面时加载

Java recycler视图不是第一次加载,但它会在我刷新页面时加载,java,android-studio,android-fragments,android-recyclerview,android-adapter,Java,Android Studio,Android Fragments,Android Recyclerview,Android Adapter,片段代码 public class MyMallFragment extends Fragment { public MyMallFragment() { } public static SwipeRefreshLayout swipeRefreshLayout; private RecyclerView homepageRecyclerview; private MyMallAdapter myMallAdapter; private I

片段代码

public class MyMallFragment extends Fragment {


    public MyMallFragment() {

    }

    public static SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView homepageRecyclerview;
    private MyMallAdapter myMallAdapter;
    private ImageView noInternet;
    private Button retryBtn;
    private List<MyMallModel> myMallModelFakeList = new ArrayList<>();

    NetworkInfo networkInfo;
    ConnectivityManager connectivityManager;


    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_my_mall, container, false);

        swipeRefreshLayout = view.findViewById(R.id.refresh_layout);
        noInternet = view.findViewById(R.id.no_internet);
        retryBtn = view.findViewById(R.id.retry_btn);
        homepageRecyclerview = view.findViewById(R.id.my_mall_recyclerview);
        swipeRefreshLayout.setColorSchemeColors(getContext().getResources().getColor(R.color.colorPrimary), getContext().getResources().getColor(R.color.colorPrimary), getContext().getResources().getColor(R.color.colorPrimary));


        LinearLayoutManager testingLayoutManager = new LinearLayoutManager(getContext());
        testingLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        homepageRecyclerview.setLayoutManager(testingLayoutManager);


////////home page fake list

        List<SliderModel> sliderModelFakeList = new ArrayList<>();

        sliderModelFakeList.add(new SliderModel("null", "#dfdfdf"));
        sliderModelFakeList.add(new SliderModel("null", "#dfdfdf"));
        sliderModelFakeList.add(new SliderModel("null", "#dfdfdf"));
        sliderModelFakeList.add(new SliderModel("null", "#dfdfdf"));
        sliderModelFakeList.add(new SliderModel("null", "#dfdfdf"));

        List<HorizontalProductScrollModel> horizontalProductScrollModelFakeList = new ArrayList<>();
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));
        horizontalProductScrollModelFakeList.add(new HorizontalProductScrollModel("", "", "", "", ""));

        myMallModelFakeList.add(new MyMallModel(0, sliderModelFakeList));
        myMallModelFakeList.add(new MyMallModel(1, "", "#dfdfdf"));
        myMallModelFakeList.add(new MyMallModel(2, "", "#dfdfdf", horizontalProductScrollModelFakeList, new ArrayList<WishlistModel>()));
        myMallModelFakeList.add(new MyMallModel(3, "", "#dfdfdf", horizontalProductScrollModelFakeList));

////////home page fake list



        myMallAdapter = new MyMallAdapter(myMallModelFakeList);


        connectivityManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
        networkInfo = connectivityManager.getActiveNetworkInfo();


        if (networkInfo != null && networkInfo.isConnected() == true) {
            MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            noInternet.setVisibility(View.GONE);
            retryBtn.setVisibility(View.GONE);
            homepageRecyclerview.setVisibility(View.VISIBLE);

            if (lists.size() == 0) {
                lists.add(new ArrayList<MyMallModel>());
                myMallAdapter = new MyMallAdapter(lists.get(0));
                loadFragmentData(homepageRecyclerview, getContext(), 0, "Home");
            } else {
                myMallAdapter = new MyMallAdapter(lists.get(0));
                myMallAdapter.notifyDataSetChanged();
            }

            homepageRecyclerview.setAdapter(myMallAdapter);

        } else {
            MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            homepageRecyclerview.setVisibility(View.GONE);
            Glide.with(this).load(R.drawable.no_internet).into(noInternet);
            noInternet.setVisibility(View.VISIBLE);
            retryBtn.setVisibility(View.VISIBLE);
        }


        ///refresh layout
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefreshLayout.setRefreshing(true);
                reloadPage();
            }
        });
        ///refresh layout

        retryBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                reloadPage();
            }
        });

        return view;

    }


    private void reloadPage() {
        networkInfo = connectivityManager.getActiveNetworkInfo();
        categoryModelList.clear();
        lists.clear();
        loadedCategoriesNames.clear();
        DBquerries.clearData();

        if (networkInfo != null && networkInfo.isConnected() == true) {
            MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            noInternet.setVisibility(View.GONE);
            retryBtn.setVisibility(View.GONE);
            homepageRecyclerview.setVisibility(View.VISIBLE);
            myMallAdapter = new MyMallAdapter(myMallModelFakeList);
            homepageRecyclerview.setAdapter(myMallAdapter);


            loadedCategoriesNames.add("HOME");
            lists.add(new ArrayList<MyMallModel>());
            loadFragmentData(homepageRecyclerview, getContext(), 0, "Home");
        } else {
            MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            Toast.makeText(getContext(), "No internet Connction!", Toast.LENGTH_SHORT).show();
            ///   categoryRecyclerView.setVisibility(View.GONE);
            homepageRecyclerview.setVisibility(View.INVISIBLE);
            Glide.with(getContext()).load(R.drawable.no_internet).into(noInternet);
            noInternet.setVisibility(View.VISIBLE);
            retryBtn.setVisibility(View.VISIBLE);
            swipeRefreshLayout.setRefreshing(false);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
    }

公共类MyMallFragment扩展了片段{
公共MyMallFragment(){
}
公共静态SwiperFreshLayout SwiperFreshLayout;
私人RecyclerView主页RecyclerView;
私有MyMallAdapter MyMallAdapter;
私有ImageView-noInternet;
专用按钮转发;
私有列表myMallModelFakeList=新的ArrayList();
网络信息网络信息;
ConnectivityManager ConnectivityManager;
创建视图时的公共视图(@NonNull LayoutInflater inflater、ViewGroup容器、Bundle savedInstanceState){
视图=充气机。充气(R.layout.fragment\u my\u mall,container,false);
swipeRefreshLayout=view.findviewbyd(R.id.refresh\u布局);
noInternet=view.findviewbyd(R.id.no\u internet);
retryBtn=view.findviewbyd(R.id.retry\u btn);
homepageRecyclerview=view.findViewById(R.id.my\u mall\u recyclerview);
swipeRefreshLayout.setColorSchemeColors(getContext().getResources().getColor(R.color.colorPrimary),getContext().getResources().getColor(R.color.colorPrimary),getColor(R.color.colorPrimary),getContext().getResources().getColor(R.color.colorPrimary));
LinearLayoutManager testingLayoutManager=新建LinearLayoutManager(getContext());
测试LayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
homepageRecyclerview.setLayoutManager(testingLayoutManager);
////////主页假名单
List sliderModelFakeList=新建ArrayList();
添加(新的SliderModel(“null”,“dfdfdf”);
添加(新的SliderModel(“null”,“dfdfdf”);
添加(新的SliderModel(“null”,“dfdfdf”);
添加(新的SliderModel(“null”,“dfdfdf”);
添加(新的SliderModel(“null”,“dfdfdf”);
List horizontalProductScrollModelFakeList=new ArrayList();
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的horizontalProductScrollModelFakeList(“,”,“,”,“,”,”);
添加(新的MyMallModel(0,sliderModelFakeList));
添加(新的MyMallModel(1,“,”#dfdfdf”);
添加(新的MyMallModel(2,“,”#dfdff),horizontalProductScrollModelFakeList,新的ArrayList());
添加(新的MyMallModel(3,“,”dfdfdff“,horizontalProductScrollModelFakeList));
////////主页假名单
myMallAdapter=新的myMallAdapter(myMallModelFakeList);
connectivityManager=(connectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_服务);
networkInfo=connectivityManager.getActiveNetworkInfo();
if(networkInfo!=null&&networkInfo.isConnected()==true){
MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
noInternet.setVisibility(View.GONE);
retryBtn.setVisibility(View.GONE);
homepageRecyclerview.setVisibility(View.VISIBLE);
如果(lists.size()==0){
添加(新的ArrayList());
myMallAdapter=newmymalladapter(lists.get(0));
loadFragmentData(homepageRecyclerview,getContext(),0,“Home”);
}否则{
myMallAdapter=newmymalladapter(lists.get(0));
myMallAdapter.notifyDataSetChanged();
}
homepageRecyclerview.setAdapter(myMallAdapter);
}否则{
MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK\u MODE\u LOCKED\u CLOSED);
homepageRecyclerview.setVisibility(View.GONE);
滑翔。与(这个)。加载(R.drawable.no_internet)。进入(noInternet);
noInternet.setVisibility(View.VISIBLE);
retryBtn.setVisibility(View.VISIBLE);
}
///刷新布局
swipeRefreshLayout.setOnRefreshListener(新的swipeRefreshLayout.OnRefreshListener()){
@凌驾
公共void onRefresh(){
swipeRefreshLayout.setRefreshing(true);
重新加载页面();
}
});
///刷新布局
retryBtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
重新加载页面();
}
});
返回视图;
}
私有void重载页面(){
networkInfo=connectivityManager.getActiveNetworkInfo();
categoryModelList.clear();
lists.clear();
loadedCategoriesNames.clear();
dbquerys.clearData();
if(networkInfo!=null&&networkInfo.isConnected()==true){
MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
noInternet.setVisibility(View.GONE);
retryBtn.setVisibility(View.GONE);
homepageRecyclerview.setVisibility(View.VISIBLE);
myMallAdapter=新的myMallAdapter(myMallModelFakeList);
homepageRecyclerview.setAdapter(myMallAdapter);
loadedCategoriesNames.add(“HOME”);
添加(新的ArrayList());
loadFragmentData(homepageRecyclerview,getContext(),0,“Home”);
}否则{
MainActivity.drawer.setDrawerLockMode(DrawerLayout.LOCK\u MODE\u LOCKED\u CLOSED);
Toast.makeText(getContext(),“没有internet连接!”,Toast.LENGTH\u SHORT.show();
///
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/category_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:elevation="3dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.454"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="gone" />

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/refresh_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/category_recycler_view">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/my_mall_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <ImageView
        android:id="@+id/no_internet"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/retry_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Retry"
        android:textSize="16sp"
        android:textAllCaps="false"
        android:backgroundTint="@color/black"
        android:stateListAnimator="@null"
        android:textColor="@color/colorAccent"
        android:translationZ="8dp"
        android:background="@drawable/slider_background"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/category_recycler_view"
        app:layout_constraintVertical_bias="0.75" />


</androidx.constraintlayout.widget.ConstraintLayout>
public class MyMallAdapter extends RecyclerView.Adapter {

    private List<MyMallModel> myMallModelList;
    private RecyclerView.RecycledViewPool recycledViewPool;
    private FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
    private int lastPos=-1;

    public MyMallAdapter(List<MyMallModel> myMallModelList) {
        this.myMallModelList = myMallModelList;
        recycledViewPool=new RecyclerView.RecycledViewPool();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {

        switch (myMallModelList.get(position).getType()){
            case 0:
                return MyMallModel.BANNER_SLIDER;
            case 1:
                return MyMallModel.STRIP_AD_BANNER;
            case 2:
                return MyMallModel.HORIZONTAL_PRODUCT_VIEW;
            case 3:
                return MyMallModel.GRID_PRODUCT_VIEW;
            default:
                return -1;

        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        switch (viewType){
            case MyMallModel.BANNER_SLIDER:
                View BannerSliderview= LayoutInflater.from(parent.getContext()).inflate(R.layout.sliding_ad_layout,parent,false);
                return new BannerSliderViewHolder(BannerSliderview);
            case MyMallModel.STRIP_AD_BANNER:
                View StripAdview= LayoutInflater.from(parent.getContext()).inflate(R.layout.strip_ad_layout,parent,false);
                return new StripAdBannerViewHolder(StripAdview);
            case MyMallModel.HORIZONTAL_PRODUCT_VIEW:
                View horizontalproductview= LayoutInflater.from(parent.getContext()).inflate(R.layout.horizontal_scoll_layout,parent,false);
                return new HorizontalProductViewHolder(horizontalproductview);
            case MyMallModel.GRID_PRODUCT_VIEW:
                View gridproductview= LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_product_layout,parent,false);
                return new GridProductViewHolder(gridproductview);
            default:
                return null;

        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        switch (myMallModelList.get(position).getType()){
            case MyMallModel.BANNER_SLIDER:
                List<SliderModel> sliderModelList=myMallModelList.get(position).getSliderModelList();
                ((BannerSliderViewHolder) holder).setBannerSliderViewPager(sliderModelList);
                break;
            case MyMallModel.STRIP_AD_BANNER:
                String resource=myMallModelList.get(position).getResource();
                String color=myMallModelList.get(position).getBackgroundColor();
                ((StripAdBannerViewHolder)holder).StripAd(resource,color);
                break;
            case MyMallModel.HORIZONTAL_PRODUCT_VIEW:
                String title=myMallModelList.get(position).getTitle();
                String colorr=myMallModelList.get(position).getBackgroundColor();
                List<HorizontalProductScrollModel> horizontalProductScrollModelList=myMallModelList.get(position).getHorizontalProductScrollModelList();
                List<WishlistModel> viewAllProductList=myMallModelList.get(position).getViewAllProductList();
                ((HorizontalProductViewHolder) holder).setHorizontalProductLayout(horizontalProductScrollModelList,title,colorr,viewAllProductList);
                break;
            case MyMallModel.GRID_PRODUCT_VIEW:
                String gridcolorr=myMallModelList.get(position).getBackgroundColor();
                String gridtitle=myMallModelList.get(position).getTitle();
                List<HorizontalProductScrollModel> gridProductScrollModelList=myMallModelList.get(position).getHorizontalProductScrollModelList();
                ((GridProductViewHolder) holder).setGridProductLayout(gridProductScrollModelList,gridtitle,gridcolorr);
                break;
            default:
                return;
        }
        if(lastPos<position) {
            Animation animation = AnimationUtils.loadAnimation(holder.itemView.getContext(), R.anim.fade_in);
            holder.itemView.setAnimation(animation);
            lastPos=position;
        }
    }

    @Override
    public int getItemCount() {
        return myMallModelList.size();
    }

    public class BannerSliderViewHolder extends RecyclerView.ViewHolder {

        private ViewPager bannerSliderViewPager;
        private int currentPage;
        private Timer timer;
        final private long DELAY_TIME=3000;
        final private long PERIOD_TIME=3000;
        private List<SliderModel> arrangedList;


        public BannerSliderViewHolder(@NonNull View itemView) {
            super(itemView);

            bannerSliderViewPager=itemView.findViewById(R.id.banner_slider_view_pager);

        }

        public void setBannerSliderViewPager(final List<SliderModel> sliderModelList){
            currentPage=2;
            if(timer!=null){
                timer.cancel();
            }
            arrangedList=new ArrayList<>();
            for(int x=0;x<sliderModelList.size();x++){
                arrangedList.add(x,sliderModelList.get(x));
            }
            arrangedList.add(0,sliderModelList.get(sliderModelList.size()-2));
            arrangedList.add(1,sliderModelList.get(sliderModelList.size()-1));
            arrangedList.add(sliderModelList.get(0));
            arrangedList.add(sliderModelList.get(1));

            SliderAdapter sliderAdapter=new SliderAdapter(arrangedList);
            bannerSliderViewPager.setAdapter(sliderAdapter);

            bannerSliderViewPager.setClipToPadding(false);
            bannerSliderViewPager.setPageMargin(20);

            bannerSliderViewPager.setCurrentItem(currentPage);

            ViewPager.OnPageChangeListener onPageChangeListener=new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    currentPage=position;
                }

                @Override
                public void onPageScrollStateChanged(int state) {
                    if(state==ViewPager.SCROLL_STATE_IDLE){
                        pageLooper(arrangedList);
                    }
                }
            };
            bannerSliderViewPager.addOnPageChangeListener(onPageChangeListener);

            startBannerSlideShow(arrangedList);

            bannerSliderViewPager.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    pageLooper(arrangedList);
                    stopBannerSlideShow();

                    if(motionEvent.getAction()==MotionEvent.ACTION_UP){
                        startBannerSlideShow(arrangedList);
                    }
                    return false;
                }
            });

        }

        private void pageLooper(List<SliderModel> sliderModelList){
            if(currentPage==sliderModelList.size()-2){
                currentPage=2;
                bannerSliderViewPager.setCurrentItem(currentPage,false);
            }

            if(currentPage==1){
                currentPage=sliderModelList.size()-3;
                bannerSliderViewPager.setCurrentItem(currentPage,false);
            }
        }

        private void startBannerSlideShow(final List<SliderModel> sliderModelList){
            final Handler handler=new Handler();
            final Runnable update=new Runnable() {
                @Override
                public void run() {
                    if(currentPage>=sliderModelList.size()){
                        currentPage=1;
                    }
                    bannerSliderViewPager.setCurrentItem(currentPage++,true);
                }
            };

            timer=new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    handler.post(update);
                }
            },DELAY_TIME,PERIOD_TIME);
        }

        private void stopBannerSlideShow(){
            timer.cancel();
        }

    }

    public class StripAdBannerViewHolder extends RecyclerView.ViewHolder{

        private ImageView stripAdImage;
        private ConstraintLayout stripAdContainer;

        public StripAdBannerViewHolder(@NonNull View itemView) {
            super(itemView);

            stripAdImage=itemView.findViewById(R.id.strip_ad_image);
            stripAdContainer=itemView.findViewById(R.id.strip_ad_container);

        }

        public void StripAd(String resource,String color){

            Glide.with(itemView.getContext()).load(resource).apply(new RequestOptions().placeholder(R.mipmap.pic)).into(stripAdImage);

            stripAdContainer.setBackgroundColor(Color.parseColor(color));
        }
    }

    public class HorizontalProductViewHolder extends RecyclerView.ViewHolder{
        private ConstraintLayout container;
        private TextView horizontallayoutTitle;
        private Button horizontalviewAllBtn;
        private RecyclerView horizontalRecyclerView;

        public HorizontalProductViewHolder(@NonNull View itemView) {
            super(itemView);
            container=itemView.findViewById(R.id.container);
            horizontalRecyclerView=itemView.findViewById(R.id.horizontal_scroll_layout_recycler_view);
            horizontalviewAllBtn=itemView.findViewById(R.id.horizontal_scroll_layout_viewall_button);
            horizontallayoutTitle=itemView.findViewById(R.id.horizontal_scroll_layout_title);
            horizontalRecyclerView.setRecycledViewPool(recycledViewPool);
        }

        private void setHorizontalProductLayout(final List<HorizontalProductScrollModel> horizontalProductScrollModelList, final String title, String color, final List<WishlistModel> viewAllProductList){
            container.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(color)));
            horizontallayoutTitle.setText(title);
            for (final HorizontalProductScrollModel model:horizontalProductScrollModelList) {

                if (!model.getProductID().isEmpty() && model.getProductTitle().isEmpty()){

                    firebaseFirestore.collection("PRODUCTS").document(model.getProductID()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                        @Override
                        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                            if (task.isSuccessful()){
                                model.setProductTitle(task.getResult().getString("product_title"));
                                model.setProductPrice(task.getResult().getString("product_price"));
                                model.setProductImage(task.getResult().getString("product_image_1"));

                                WishlistModel wishlistModel = viewAllProductList.get(horizontalProductScrollModelList.indexOf(model));
                                wishlistModel.setTotalRatings(task.getResult().getLong("total_ratings"));
                                wishlistModel.setRating(task.getResult().getString("average_rating"));
                                wishlistModel.setProductTitle(task.getResult().getString("product_title"));
                                wishlistModel.setProductPrice(task.getResult().getString("product_price"));
                                wishlistModel.setProductImage(task.getResult().getString("product_image_1"));
                                wishlistModel.setFreeCoupans(task.getResult().getLong("free_coupans"));
                                wishlistModel.setCuttedPrice(task.getResult().getString("cutted_price"));
                                wishlistModel.setCOD(task.getResult().getBoolean("COD"));
                                wishlistModel.setInStock(task.getResult().getLong("stock_quantity") > 0);


                                if (horizontalProductScrollModelList.indexOf(model) == horizontalProductScrollModelList.size()-1){
                                    if (horizontalRecyclerView.getAdapter()!= null){
                                        horizontalRecyclerView.getAdapter().notifyDataSetChanged();
                                    }
                                }


                            }else{
                                //do nothing
                            }
                        }
                    });


                    if(horizontalProductScrollModelList.size() > 8){
                        horizontalviewAllBtn.setVisibility(View.VISIBLE);
                        horizontalviewAllBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ViewAllActivity.wishlistModelList=viewAllProductList;
                                itemView.getContext().startActivity(new Intent(itemView.getContext(),ViewAllActivity.class)
                                        .putExtra("layout",0)
                                        .putExtra("title",title)
                                );
                            }
                        });
                    }else {
                        horizontalviewAllBtn.setVisibility(View.INVISIBLE);
                    }


                }

            }


            HorizontalProductScrollAdapter horizontalProductScrollAdapter=new HorizontalProductScrollAdapter(horizontalProductScrollModelList);

            LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(itemView.getContext());
            linearLayoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
            horizontalRecyclerView.setLayoutManager(linearLayoutManager1);

            horizontalRecyclerView.setAdapter(horizontalProductScrollAdapter);
            horizontalProductScrollAdapter.notifyDataSetChanged();

        }
    }

    public class GridProductViewHolder extends RecyclerView.ViewHolder{
        private ConstraintLayout container;
        private TextView gridLayoutTitle;
        private Button gridLayoutButton;
        private GridLayout gridProductLayout;

        public GridProductViewHolder(@NonNull final View itemView) {
            super(itemView);
            container=itemView.findViewById(R.id.container);
            gridLayoutTitle=itemView.findViewById(R.id.grid_product_layout_title);
            gridLayoutButton=itemView.findViewById(R.id.grid_product_layout_viewall_button);
            gridProductLayout=itemView.findViewById(R.id.grid_layout);

        }
        private void setGridProductLayout(final List<HorizontalProductScrollModel> horizontalProductScrollModelList, final String title, String color) {
            container.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(color)));
            gridLayoutTitle.setText(title);

            for(int x=0;x<4;x++){
                ImageView productImage=gridProductLayout.getChildAt(x).findViewById(R.id.h_s_product_image);
                TextView productTitle=gridProductLayout.getChildAt(x).findViewById(R.id.h_s_product_title);
                TextView productDesc=gridProductLayout.getChildAt(x).findViewById(R.id.h_s_product_description);
                TextView productPrice=gridProductLayout.getChildAt(x).findViewById(R.id.h_s_product_price);

                Glide.with(itemView.getContext()).load(horizontalProductScrollModelList.get(x).getProductImage()).apply(new RequestOptions().placeholder(R.mipmap.pic)).into(productImage);
                productTitle.setText(horizontalProductScrollModelList.get(x).getProductTitle());
                productDesc.setText(horizontalProductScrollModelList.get(x).getProductDesc());
                productPrice.setText("Rs."+horizontalProductScrollModelList.get(x).getProductPrice()+"/-");

                gridProductLayout.getChildAt(x).setBackgroundColor(Color.WHITE);
                if(!title.equals("")){
                    final int finalX = x;
                    gridProductLayout.getChildAt(x).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            itemView.getContext().startActivity(new Intent(itemView.getContext(),ProductDetailsActivity.class).putExtra("PRODUCT_ID",horizontalProductScrollModelList.get(finalX).getProductID()));
                        }
                    });
                }
            }

            if(!title.equals("")) {
                gridLayoutButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ViewAllActivity.horizontalProductScrollModelList = horizontalProductScrollModelList;
                        itemView.getContext().startActivity(new Intent(itemView.getContext(), ViewAllActivity.class)
                                .putExtra("layout", 1)
                                .putExtra("title", title)
                        );
                    }
                });
            }
        }

    }



}