package com.daya.live_teaching.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.cooleshow.base.widgets.ColorTextView;
import com.daya.live_teaching.R;
import com.daya.live_teaching.model.ClassMember;
import com.daya.live_teaching.ui.adapter.AccompanimentDownloadListAdapter;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Author by pq, Date on 2022/5/6.
 */
public class AccompanimentDialog extends Dialog {

    private AccompanimentDownloadListAdapter mAccompanimentDownloadAdapter;
    private TextView mTvTitle;

    public AccompanimentDialog(@NonNull Context context) {
        super(context, com.cooleshow.base.R.style.DialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_accompaniment_download_dialog);
        mTvTitle = findViewById(R.id.tv_title);
        ImageView ivClose = findViewById(R.id.iv_close);
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        ColorTextView ctv_layout_accompaniment_download_dialog_cancel = findViewById(R.id.ctv_layout_accompaniment_download_dialog_cancel);
        ColorTextView ctv_layout_accompaniment_download_dialog_comfirm = findViewById(R.id.ctv_layout_accompaniment_download_dialog_comfirm);

        ivClose.setOnClickListener(view -> {
            dismiss();
        });
        ctv_layout_accompaniment_download_dialog_cancel.setOnClickListener(view -> ivClose.callOnClick());
        ctv_layout_accompaniment_download_dialog_comfirm.setOnClickListener(view -> ivClose.callOnClick());
        mAccompanimentDownloadAdapter = new AccompanimentDownloadListAdapter(getContext());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(mAccompanimentDownloadAdapter);
    }

    public void setTitle(String title){
        if (mTvTitle != null) {
            mTvTitle.setText("《" + title + "》");
        }
    }

    public void setData(List<ClassMember> accompanimentDosnloadMembers, String musicScoreAccompanimentId){
        if(mAccompanimentDownloadAdapter!=null){
            mAccompanimentDownloadAdapter.setData(accompanimentDosnloadMembers, musicScoreAccompanimentId);
        }
    }
}
