package com.wisewoods.eduandroid.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.wisewoods.base.base.BaseActivity;
import com.wisewoods.base.bean.ScheduleData;
import com.wisewoods.base.net.JDCallback;
import com.wisewoods.base.utils.ImgUtils;
import com.wisewoods.eduandroid.app.App;
import com.wisewoods.eduandroid.databinding.ActivityCourseBinding;

import retrofit2.Response;

public class CourseActivity extends BaseActivity<ActivityCourseBinding> {

    private String id;

    public static void start(String id) {
        Intent intent = new Intent(ActivityUtils.getTopActivity(), CourseActivity.class);
        intent.putExtra("id", id);
        ActivityUtils.startActivity(intent);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        id = getIntent().getStringExtra("id");
        showBarBack(binding.bar.tvTitle, "课程详情", binding.bar.ivBack);

        App.api.getScheduleInfo(id)
                .enqueue(new JDCallback<ScheduleData>() {
                    @Override
                    public void onS(Response<ScheduleData> response, ScheduleData scheduleData) {
                        ImgUtils.load(activity, scheduleData.data.courseThumbnailUrl, binding.ivCover);
                        binding.tvName.setText(scheduleData.data.courseCeremoneyName);
                        binding.tvTime.setText(scheduleData.data.courseStartTime + "开始");
                        if (TextUtils.isEmpty(scheduleData.data.classroomBaseName)) {
                            binding.llRoom.setVisibility(View.GONE);
                        } else {
                            binding.tvClassroom.setText(scheduleData.data.classroomBaseName);
                        }
                        binding.tvDes.setText(scheduleData.data.courseSynopsis);
                        if (TextUtils.isEmpty(scheduleData.data.teacherName)) {
                            binding.llTeacher.setVisibility(View.GONE);
                        } else {
                            binding.tvTeacher.setText(scheduleData.data.teacherName);
                        }
                    }
                });
    }
}
