package com.cooleshow.teacher.ui.homepage;

import android.text.TextUtils;
import android.view.View;

import com.cooleshow.base.ui.fragment.BaseMVPFragment;
import com.cooleshow.base.utils.SizeUtils;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.adapter.MineStyleFansGroupListAdapter;
import com.cooleshow.teacher.adapter.MineStyleVideoListAdapter;
import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;
import com.cooleshow.teacher.contract.MineStyleContract;
import com.cooleshow.teacher.databinding.FragmentMineStyleLayoutBinding;
import com.cooleshow.teacher.presenter.homePage.MineStylePresenter;
import com.cooleshow.teacher.widgets.MineStyleVideoListItemDecoration;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

/**
 * Author by pq, Date on 2022/5/9.
 */
public class MineStyleFragment extends BaseMVPFragment<FragmentMineStyleLayoutBinding, MineStylePresenter> implements MineStyleContract.MineStylePageView {

    private MineStyleFansGroupListAdapter mFansGroupListAdapter;
    private MineStyleVideoListAdapter mStyleVideoListAdapter;

    @Override
    protected void initView(View rootView) {
        mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mStyleVideoListAdapter = new MineStyleVideoListAdapter(R.layout.item_mine_style_video_layout);
        MineStyleVideoListItemDecoration itemDecoration = new MineStyleVideoListItemDecoration(SizeUtils.dp2px(11), 0, 0, 0, SizeUtils.dp2px(5));
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
        mViewBinding.recyclerView.setLayoutManager(gridLayoutManager);
        mViewBinding.recyclerView.addItemDecoration(itemDecoration);
        mViewBinding.recyclerView.setAdapter(mStyleVideoListAdapter);
        mFansGroupListAdapter = new MineStyleFansGroupListAdapter(R.layout.item_mine_style_fans_group_layout);
        mViewBinding.recyclerViewFans.setLayoutManager(new LinearLayoutManager(getContext()));
        mViewBinding.recyclerViewFans.setAdapter(mFansGroupListAdapter);
        mViewBinding.recyclerView.setNestedScrollingEnabled(false);
        mViewBinding.recyclerViewFans.setNestedScrollingEnabled(false);
    }

    @Override
    protected void initData() {
        presenter.getTeacherSelfStyle();
    }

    @Override
    protected FragmentMineStyleLayoutBinding getLayoutView() {
        return FragmentMineStyleLayoutBinding.inflate(getLayoutInflater());
    }

    @Override
    protected MineStylePresenter createPresenter() {
        return new MineStylePresenter();
    }

    @Override
    public void getSelfStyleSuccess(TeacherSelfStyleInfoBean styleInfoBean) {
        if (isDetached()) {
            return;
        }
        if (styleInfoBean == null) {
            return;
        }
        //个人介绍
        if (TextUtils.isEmpty(styleInfoBean.introduction)) {

        } else {
            mViewBinding.tvSelfIntroduction.setText(styleInfoBean.introduction);
        }
        //视频信息
        if (mStyleVideoListAdapter != null) {
            mStyleVideoListAdapter.setNewInstance(styleInfoBean.styleVideo);
        }

    }
}
