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 MyDownloadArchiveFragment : MyArchiveFragment() {
    var isEmpty = false

    override fun onCreate(savedInstanceState: Bundle?) {
        mType = Type.MY_DOWNLOAD_ARCHIVE
        super.onCreate(savedInstanceState)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mBinding.reuseNoneData.reuseNoneDataTv.text = "还没有存档噢~"
        mBinding.reuseNoneData.reuseNoneDataDescTv.text = "去看看大家上传的热门存档吧！"
    }

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

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

    @Subscribe(threadMode = ThreadMode.MAIN)
    override fun onEventMainThread(reuse: EBReuse) {
        super.onEventMainThread(reuse)
        if ("RefreshArchive" == reuse.type) {
            AppExecutor.uiExecutor.executeWithDelay({
                mListViewModel.load(LoadType.REFRESH)
                if (requireActivity() is CloudArchiveManagerActivity) {
                    (requireActivity() as CloudArchiveManagerActivity).updateMyArchive()
                    (requireActivity() as CloudArchiveManagerActivity).updateMyShareArchive()
                }
            }, 200)
        }
    }
}