ViewDetailsDialog.java 3.67 KB

package com.wd.common.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.wd.common.viewclick.BaseClickListener;
import com.wd.fastcoding.base.R;
import com.wd.foundation.bean.utils.TimeUtil;


/**
 * 详情对话框
 *
 * @author lvjinhui
 */
public class ViewDetailsDialog extends Dialog {

    // 作者
    private final String authorName;

    // 标题
    private final String newsTitle;

    // 描述
    private final String newIntroduction;

    /**
     * 时间
     */
    private String time;

    public ViewDetailsDialog(@NonNull Context context, String authorName, String newsTitle,
                             String newIntroduction, String time) {
        super(context, R.style.DialogBackgroundNull);
        this.authorName = authorName;
        this.newsTitle = newsTitle;
        this.newIntroduction = newIntroduction;
        this.time = time;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_short_video_describe);
        initOption();
        initView();
    }

    private void initOption() {
        Window window = getWindow();
        if (window != null) {
            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            window.setDimAmount(0);
            window.setBackgroundDrawableResource(android.R.color.transparent);
        }
    }

    private void initView() {

        TextView tv_author = findViewById(R.id.tv_author);
        TextView tv_title = findViewById(R.id.tv_title);
        TextView tv_description = findViewById(R.id.tv_description);
        TextView timeTv = findViewById(R.id.tv_time);
        ImageView iv_close = findViewById(R.id.iv_close);
        ConstraintLayout clEmptyArea = findViewById(R.id.clEmptyArea);
        if (!TextUtils.isEmpty(authorName)) {
            if (tv_author != null) {
                tv_author.setText(authorName);
            }
        }
        if (!TextUtils.isEmpty(newsTitle)) {
            if (tv_title != null) {
                tv_title.setText(newsTitle);
            }
        }
        if (!TextUtils.isEmpty(newIntroduction)) {
            if (tv_description != null) {
                tv_description.setVisibility(View.VISIBLE);
                tv_description.setText(newIntroduction);
            }
        }else {
            if (tv_description != null) {
                tv_description.setVisibility(View.GONE);
            }
        }

        //设置时间
        if (TextUtils.isEmpty(time)) {
            timeTv.setVisibility(View.GONE);
        }else {
            timeTv.setVisibility(View.VISIBLE);
            //不需要走统一规则,目前接口返回的就是具体时间格式
            //yyyy-MM-dd HH:mm:ss ----> yyyy-MM-dd HH:mm
            time = TimeUtil.transFormTime3(time);
            timeTv.setText(time);
        }
        if (iv_close != null) {
            iv_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
        }
        if (clEmptyArea != null){
            clEmptyArea.setOnClickListener(new BaseClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    dismiss();
                }
            });
        }
    }

}