package com.yidian.shenghuoquan.newscontent.ui

import android.content.Intent
import android.os.Bundle
import com.umeng.socialize.UMShareAPI
import com.yidian.common.XRouterPathConstants
import com.yidian.common.XRouterPathConstants.Companion.NEWS_CONTENT
import com.yidian.common.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.databinding.ActivityNewsContentBinding


class NewsContentActivity : BaseActivity<ActivityNewsContentBinding>() {
    override fun createViewBinding(): ActivityNewsContentBinding {
        return ActivityNewsContentBinding.inflate(layoutInflater)
    }

    override fun getXPageName(): String {
        return NEWS_CONTENT
    }

    companion object {
        const val ContentType = "content_type"
        const val TextType = "text_detail"
        const val VideoType = "video_detail"
        const val DocId = "doc_id"
        const val JumpFrom = "jump_from"
    }

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        if(intent.getSerializableExtra(XRouterPathConstants.ParamsKey) !=null){
            val paramsMap = intent.getSerializableExtra(XRouterPathConstants.ParamsKey) as HashMap<*, *>
            val newContentType = paramsMap[ContentType] as String
            initFragment(newContentType,paramsMap)
        }
    }

    private fun initFragment(contentType: String, paramsMap: Map<*, *>) {
        when (contentType) {
            TextType -> {
                val commentFragment = CommentWebFragment.newInstance(paramsMap)
                supportFragmentManager.beginTransaction().replace(R.id.fly_webContainer, commentFragment).commit()
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        UMShareAPI.get(this).release()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data)
    }
}