package com.gh.gamecenter.message;

import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.Nullable;

import android.view.View;

import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.R;
import com.gh.gamecenter.common.baselist.ListAdapter;
import com.gh.gamecenter.common.baselist.ListFragment;
import com.gh.gamecenter.entity.MessageKeFuEntity;
import com.halo.assistant.HaloApp;

/**
 * Created by khy on 2017/4/5.
 * 消息-客服
 */
public class KeFuFragment extends ListFragment<MessageKeFuEntity, KeFuViewModel> {

    private KeFuFragmentAdapter mAdapter;
    private MessageUnreadViewModel mUnreadViewModel;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setNavigationTitle("系统");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUnreadViewModel = ViewModelProviders.of(this, new MessageUnreadViewModel.Factory(HaloApp.getInstance().getApplication()))
                .get(MessageUnreadViewModel.class);
    }

    @Override
    public void onLoadDone() {
        super.onLoadDone();
        mUnreadViewModel.markRead(MessageUnreadViewModel.ReadType.SERVICE);
    }

    @Override
    protected ListAdapter provideListAdapter() {
        return mAdapter == null ? mAdapter = new KeFuFragmentAdapter(getContext(),
                this,
                mListViewModel,
                mEntrance) : mAdapter;
    }

    @Override
    public void onListClick(View view, int position, Object data) {
        if (view.getId() == R.id.message_kaifu_item) {
            MtaHelper.onEvent("消息中心", "系统_二级列表", "点击卡片");
            MessageKeFuEntity keFuEntity = (MessageKeFuEntity) data;
            if (!keFuEntity.isRead()) {
                mListViewModel.postMessageRead(keFuEntity.getId());
                mAdapter.notifyDataSetChanged();
            }
        }
    }
}
