package com.gh.gamecenter.message.view.message

import android.os.Bundle
import com.gh.gamecenter.common.baselist.ListFragment
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.viewModelProvider
import com.gh.gamecenter.message.entity.MessageItemData

/**
 * 消息中心-二级消息列表
 */
class MessageListFragment : ListFragment<MessageItemData, MessageListViewModel>() {
    private lateinit var mViewModel: MessageListViewModel
    private var mAdapter: MessageListAdapter? = null
    private var mType = ""
    private var mGameId = ""
    private var mGameName = ""
    private var mGameType = ""

    override fun provideListAdapter(): MessageListAdapter {
        if (mAdapter == null) {
            mAdapter = MessageListAdapter(requireContext(), mGameId, mGameName, mGameType, mType, mViewModel, mEntrance)
        }
        return mAdapter as MessageListAdapter
    }

    override fun provideListViewModel(): MessageListViewModel {
        mViewModel = viewModelProvider(MessageListViewModel.Factory(mType, mGameId))
        return mViewModel
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        mType = requireArguments().getString(EntranceConsts.KEY_TYPE, "")
        mGameId = requireArguments().getString(EntranceConsts.KEY_GAMEID, "")
        mGameName = requireArguments().getString(EntranceConsts.KEY_GAMENAME, "")
        mGameType = requireArguments().getString(EntranceConsts.KEY_GAME_TYPE, "")
        super.onCreate(savedInstanceState)
        setNavigationTitle(requireArguments().getString(EntranceConsts.KEY_NAME, ""))
    }

}