package com.ycgis.macall.personalcenter.v.activity;

import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.rs.macall.androidx.basemodel.base.BaseViewBindActivity;
import com.rs.macall.androidx.basemodel.utils.StringUtil;
import com.rs.macall.androidx.basemodel.utils.ToastUtil;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.ActivityMsgDetailsBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.MessageBean;
import com.ycgis.macall.personalcenter.p.app.AppCache;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


public class MsgDetailsActivity extends BaseViewBindActivity<ActivityMsgDetailsBinding> {
    private MessageBean msgData;

    @Override
    protected boolean isImmersiveStatusBar() {
        return true;
    }

    @Override
    protected ActivityMsgDetailsBinding getViewBinding() {
        return ActivityMsgDetailsBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void init() {

    }

    @Override
    protected void readInstanceState(Bundle savedInstanceState) {
        msgData = (MessageBean) getIntent().getSerializableExtra("msgData");
    }

    @Override
    protected void start() {
        viewBinding.baseTitle.leftImage.setImageDrawable(getDrawables(R.drawable.ic_back));
        viewBinding.baseTitle.contentTitle.setText("消息详情");
        viewBinding.baseTitle.titleleft.setOnClickListener(v -> finish());
        if (msgData == null) {
            ToastUtil.centered(getContext(), "接收参数错误！");
            ys();
            return;
        }
        viewBinding.msgTitle.setText(msgData.getTitle());
        viewBinding.msgContent.setText(msgData.getContent());
        viewBinding.msgDept.setText(msgData.getAppName());
        viewBinding.msgTime.setText(msgData.getTime());
        if (StringUtil.hasContent(msgData.getAppIcon())) {
            String imgUrl = AppCache.BASE_IMAGE_URL + msgData.getAppIcon();
            //图片加载自己实现
            Glide.with(viewBinding.imageView10)
                    .load(imgUrl)
                    .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                    .into(viewBinding.imageView10);
        }
    }

    private void ys() {
        Observable.timer(1000, TimeUnit.MILLISECONDS)
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NotNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NotNull Long aLong) {

                    }

                    @Override
                    public void onError(@NotNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {
                        finish();
                        ;
                    }
                });
    }


}