package com.gh.gamecenter.cloudarchive

import android.os.Bundle
import android.view.View
import com.gh.gamecenter.common.baselist.LoadType
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.core.AppExecutor
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class MyShareArchiveFragment : MyArchiveFragment() {
    override fun onCreate(savedInstanceState: Bundle?) {
        mType = Type.MY_SHARE_ARCHIVE
        super.onCreate(savedInstanceState)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mBinding.tipsTv.visibility = View.GONE
        mBinding.reuseNoneData.reuseNoneDataTv.text = "您还没有分享存档噢~"
        mBinding.reuseNoneData.reuseNoneDataDescTv.text = "快快把您的有趣存档分享给大家吧！"
    }

    override fun onLoadDone() {
        super.onLoadDone()
        mBinding.tipsTv.visibility = View.GONE
        if (requireActivity() is CloudArchiveManagerActivity) {
            (requireActivity() as CloudArchiveManagerActivity).controlUploadGameArchive()
        }
    }

    override fun onLoadEmpty() {
        super.onLoadEmpty()
        if (requireActivity() is CloudArchiveManagerActivity) {
            (requireActivity() as CloudArchiveManagerActivity).controlUploadGameArchive()
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    override fun onEventMainThread(reuse: EBReuse) {
        super.onEventMainThread(reuse)
        if ("RefreshShareArchive" == reuse.type) {
            AppExecutor.uiExecutor.executeWithDelay({
                mListViewModel.load(LoadType.REFRESH)
            }, 200)
        }
    }
}