package com.android.chmo.ui.activity.activities;

import android.content.Intent;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.chmo.R;
import com.android.chmo.base.BaseActivity;
import com.android.chmo.http.HttpApi;
import com.android.chmo.model.ActivitiesInfo;
import com.android.chmo.utils.PixelUtils;
import com.android.chmo.utils.XUtilsImage;

import butterknife.BindView;
import butterknife.OnClick;


public class ActivitiesDetailActivity extends BaseActivity {
    @BindView(R.id.image)
    ImageView imageView;
    @BindView(R.id.atitle)
    TextView titleView;
    @BindView(R.id.startTime)
    TextView startTimeView;
    @BindView(R.id.endTime)
    TextView endTimeView;
    @BindView(R.id.desc)
    TextView descView;


    @BindView(R.id.signBtn)
    Button signBtn;

    private ActivitiesInfo info;

    @Override
    protected int getContentResId() {
        return R.layout.activity_activities_detail;
    }

    @Override
    public void initView() {
        info = (ActivitiesInfo) getIntent().getSerializableExtra("data");

        int width = PixelUtils.getWindowWidth();
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)imageView.getLayoutParams();
        lp.width = width;
        lp.height = width;
        imageView.setLayoutParams(lp);
        XUtilsImage.display(imageView, HttpApi.getImgUrl(info.pic), R.mipmap.def_img2);

        titleView.setText(info.caption);
        startTimeView.setText(info.beg);
        endTimeView.setText(info.sendt);
        descView.setText(info.intro);

        if(info.issigndate == 1) {
            signBtn.setBackgroundResource(R.drawable.pink_btn);
            signBtn.setText("立即报名");
        }else {
            signBtn.setBackgroundResource(R.drawable.gray_btn);
            signBtn.setText("已结束");
        }
    }

    @OnClick(R.id.signBtn)
    public void sign(){
        if(info.issigndate != 1) {
            return;
        }

        Intent intent = new Intent(this,SignInActivity.class);
        intent.putExtra("data", info);
        openPage(intent);
    }
}
