package com.quyunshuo.module.home.dialog

import android.content.Context
import android.os.Environment
import android.util.Log
import android.widget.ImageView
import coil.request.ImageRequest
import com.hboxs.serialport.plc.DialogClickListener
import com.quyunshuo.androidbaseframemvvm.base.mvvm.v.BaseFrameDialog
import com.quyunshuo.androidbaseframemvvm.base.utils.CoilGIFImageLoader
import com.quyunshuo.module.home.databinding.HomeDialogAgainBuyBinding

/**
 * 连接服务器的对话框
 */
class AgainBuyDialog(mContext: Context) : BaseFrameDialog<HomeDialogAgainBuyBinding>(mContext) {
    private val TAG = "ConnectionServerDialog"
    private var againBuyDialoglistener: DialogClickListener? = null

    var type1: Int = 1
    var type2: Int = 2
    override fun HomeDialogAgainBuyBinding.initView() {
        readDataFromAssets("assets/dingdian_qutang.gif", ivIcon)
        tvAgainBuy.setOnClickListener {
            againBuyDialoglistener?.onClickListener(type1,null)
        }
    }


    override fun createVB() = HomeDialogAgainBuyBinding.inflate(layoutInflater)


    override fun initObserve() {
    }

    override fun initRequestData() {
    }

    fun setListener(listener: DialogClickListener) {
        this.againBuyDialoglistener = listener
    }

    /* Checks if external storage is available for read and write */
    fun isExternalStorageWritable(): Boolean {
        val state = Environment.getExternalStorageState()
        if (Environment.MEDIA_MOUNTED == state) {
            return true
        }
        Log.e(TAG, "isExternalStorageWritable: $state")
        return false
    }

    private fun readDataFromAssets(assetsPath: String, ivAssets: ImageView): Boolean {
        val request = ImageRequest.Builder(mContext)
            .data(assetsPath) // 替换为你的G图像路径
            .target(ivAssets)
            .build()

        CoilGIFImageLoader.imageLoader.enqueue(request)
        return true
    }

}