package com.example.prettywallpapers.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.example.prettywallpapers.R;
import com.example.prettywallpapers.activity.PrettyPaperActivity;
import com.example.prettywallpapers.base.PrettyWallPaper;
import com.example.prettywallpapers.list.PrettyPaper;
import com.example.prettywallpapers.listener.SwitchType;
import com.example.prettywallpapers.myvalue.MyValues;
import com.example.prettywallpapers.prettyadapter.WallpaperAdapter;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment {
    private RecyclerView recyclerView_prettywall;
    private Banner banner;
    private List<PrettyPaper> prettyPapers;
    private SwitchType switchintent;
    List<String> stringList = new ArrayList<>();

    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        banner = view.findViewById(R.id.banner);
        stringList.add("https://resource-sg-public.lux-ad.com/wallpaper/148499404d85516a86eeb5c2c30fafbd.jpeg");
        stringList.add("https://resource-sg-public.lux-ad.com/wallpaper/989ccbceb5d165cc4b44ced23af4d5fb.jpeg");
        stringList.add("https://resource-sg-public.lux-ad.com/wallpaper/b655bc8400774e2dc940b5a8291e2ca5.jpeg");
        banner.setAdapter(new BannerImageAdapter<String>(stringList) {
            @Override
            public void onBindView(BannerImageHolder holder, String data, int position, int size) {
                Glide.with(holder.itemView).load(data).apply(RequestOptions.bitmapTransform(new RoundedCorners(30))).into(holder.imageView);
            }
        });
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(Object data, int position) {
                //Log.d("-----data","------data"+data);
                Intent intent = new Intent(getActivity(), PrettyPaperActivity.class);
                //intent.putExtra(MyValues.TYPE,"1");
                //Log.d("-----MyValues.TYPE","------MyValues.TYPE"+MyValues.TYPE);
                intent.putExtra(MyValues.PAPER_IMAGE,String.valueOf(data));
                Log.d("-----data","------data"+String.valueOf(data));
                startActivity(intent);
            }
        });
        banner.setIndicator(new CircleIndicator(getActivity()));
        recyclerView_prettywall = view.findViewById(R.id.recyclerview_pretty);
        setPrettyWallpaper();
        return view;
    }
    private void setPrettyWallpaper() {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),1);
        recyclerView_prettywall.setLayoutManager(gridLayoutManager);
        WallpaperAdapter wallpaperAdapter = new WallpaperAdapter(PrettyWallPaper.getCategorylist(),getActivity());
        recyclerView_prettywall.setAdapter(wallpaperAdapter);
    }
}