package com.tjzhxx.union;

import android.content.Intent;
import android.os.Bundle;
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.engine.DiskCacheStrategy;
import com.tjzhxx.union.activity.AddressMapActivity;
import com.tjzhxx.union.entity.BannerEntity;
import com.tjzhxx.union.system.BaseFragment;

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

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bingoogolapple.bgabanner.BGABanner;
import io.reactivex.annotations.Nullable;

/**
 * 描述:
 *
 * @author yanghuaxiong
 * @create 2021/9/1 11:44 AM
 */

public class GroupFragment extends BaseFragment {


    @BindView(R.id.bga_banner)
    BGABanner bgaBanner;
    private List<BannerEntity> bannerEntities = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        View view = inflater.inflate(R.layout.fragment_group, container, false);
        ButterKnife.bind(this, view);
        bgaBanner.setAdapter(new BGABanner.Adapter<ImageView, String>() {
            @Override
            public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
                Glide.with(getActivity())
                        .load(model)
                        .placeholder(R.mipmap.bg_placeholder)
                        .error(R.mipmap.bg_placeholder)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .centerCrop()
                        .dontAnimate()
                        .into(itemView);
            }
        });
        String[] url = new String[]{
                "https://app.tjzhxx.cn:1443/Uploads/sysimage/p1.jpg",
                "https://app.tjzhxx.cn:1443/Uploads/sysimage/p2.jpg",
                "https://app.tjzhxx.cn:1443/Uploads/sysimage/p3.jpg",
                "https://app.tjzhxx.cn:1443/Uploads/sysimage/p4.jpg",
                "https://app.tjzhxx.cn:1443/Uploads/sysimage/p5.jpg",
                "https://app.tjzhxx.cn:1443/Uploads/sysimage/p6.jpg"};
        List<String> urls = new ArrayList<>();
        List<String> titles = new ArrayList<>();
        for (String entity : url) {
            urls.add(entity);
            titles.add("");
        }
        bgaBanner.setData(urls, titles);
        return view;
    }

    @OnClick(R.id.address)
    public void onClick() {
        Intent intent = new Intent(getActivity(), AddressMapActivity.class);
        startActivity(intent);
    }
}
