package com.bokecc.livemodule.view.timer;

import android.view.View;
import android.widget.TextView;

/**
 * Copyright (C), 20105-2021, 创盛视联数码科技（北京）有限公司
 * FileName:
 * Author:
 * Date: 2023/1/6
 * Description:
 */
public class TextViewUpdater implements DigitalTimerView.ViewUpdater {
    private int mTimeTextViewId;
    private int mSuffixTextViewId;

    public TextViewUpdater(int mTimeTextViewId, int mSuffixTextViewId) {
        this.mTimeTextViewId = mTimeTextViewId;
        this.mSuffixTextViewId = mSuffixTextViewId;
    }

    @Override
    public void initSuffix(View suffixView, int pos) {
        View v = suffixView.findViewById(mSuffixTextViewId);
//        if (v != null && v instanceof TextView) {
//            ((TextView) v).setText(":");
//        }
    }
    @Override
    public void updateShow(View subTimeView, int subTime, String formattedSubTime) {
        View v = subTimeView.findViewById(mTimeTextViewId);
        if (v != null && v instanceof TextView) {
            ((TextView) v).setText(formattedSubTime);
        }
    }
    @Override
    public void updateDayShow(View subTimeView, int subTime, String formattedSubTime) {
//        if (subTime==0){
//            subTimeView.setVisibility(View.GONE);
//        }else {
//            subTimeView.setVisibility(View.VISIBLE);
//            View v = subTimeView.findViewById(mTimeTextViewId);
//            if (v != null && v instanceof TextView) {
//                ((TextView) v).setText(formattedSubTime);
//            }
//        }
        subTimeView.setVisibility(View.VISIBLE);
        View v = subTimeView.findViewById(mTimeTextViewId);
        if (v != null && v instanceof TextView) {
            ((TextView) v).setText(formattedSubTime);
        }
    }

    @Override
    public void updateHourShow(View subTimeView, int subTime, String formattedSubTime) {
        subTimeView.setVisibility(View.VISIBLE);
        View v = subTimeView.findViewById(mTimeTextViewId);
        if (v != null && v instanceof TextView) {
            ((TextView) v).setText(formattedSubTime);
        }
    }

    @Override
    public void updateMinShow(View subTimeView, int subTime, String formattedSubTime) {
        subTimeView.setVisibility(View.VISIBLE);
        View v = subTimeView.findViewById(mTimeTextViewId);
        if (v != null && v instanceof TextView) {
            ((TextView) v).setText(formattedSubTime);
        }
    }

    @Override
    public void updateSecShow(View subTimeView, int subTime, String formattedSubTime) {
        subTimeView.setVisibility(View.VISIBLE);
        View v = subTimeView.findViewById(mTimeTextViewId);
        if (v != null && v instanceof TextView) {
            ((TextView) v).setText(formattedSubTime);
        }
    }
}
