package cn.org.bjca.trust.pushdemo

import android.os.Bundle
import android.provider.MediaStore
import androidx.activity.result.contract.ActivityResultContracts
import cn.org.bjca.trust.push.PushSdk
import cn.org.bjca.trust.push.common.GraphicHelper
import cn.org.bjca.trust.push.common.LogHelper
import cn.org.bjca.trust.push.common.MessageHelper
import cn.org.bjca.trust.push.common.SendMessageHelper
import cn.org.bjca.trust.push.enums.MsgType
import cn.org.bjca.trust.push.message.bean.PictureMessage
import cn.org.bjca.trust.pushdemo.databinding.ActivityMainBinding
import com.xuqm.base.extensions.loge
import com.xuqm.base.ui.BaseActivity

class MainActivity : BaseActivity<ActivityMainBinding>() {

    override fun showStatus(): Int = R.color.black
    override fun getLayoutId(): Int = R.layout.activity_main

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        PushSdk.instance.register("xuqinmin")


        val r = registerForActivityResult(ActivityResultContracts.GetContent()) {
            it.loge()
            SendMessageHelper.sendImageMessage(
                "xuqinmin", MediaStore.Images.Media.getBitmap(
                    contentResolver, it
                )
            )
        }

        binding.register.setOnClickListener {
            val m = MessageHelper.getMessageForPage(1, 10)
            LogHelper.e(m[0])
            if (m[0].msgType == MsgType.Image) {
                binding.iv.setImageBitmap(GraphicHelper.base64ToBitmap((m[0] as PictureMessage).thumbnail))
            }
        }
        binding.send.setOnClickListener {
            SendMessageHelper.sendTextMessage("xuqm", "hello${System.currentTimeMillis()}")
//            r.launch("image/*")
        }

    }

}