package com.sheep.gamegroup.view.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sheep.gamegroup.view.activity.MessageReplyDetailActivity;
import com.sheep.gamegroup.view.adapter.MessageLeftAdapter;
import com.sheep.jiuyan.samllsheep.R;

import java.util.List;

/**
 * created on：2018/8/28 on 12:32
 * created by: YSL
 * 描述:
 */

@SuppressLint("ValidFragment")
public class MessageCenterFragment extends Fragment implements MessageLeftAdapter.ItemOnClickListener {
    private Context mContext;
    private RecyclerView recyclerView;
    private MessageLeftAdapter adapter;
    private List<?> mList;


    public MessageCenterFragment() {
    }

    public MessageCenterFragment(Context mContext) {
        this.mContext = mContext;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = null;
        if (mList == null || mList.isEmpty()) {
            view=inflater.inflate(R.layout.layout_empty_no_data,null);
        } else {
            view = inflater.inflate(R.layout.fragment_messagecenter, null);
            recyclerView = view.findViewById(R.id.recycle_fragment_message_center);
        }
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (mList==null||mList.isEmpty()){
            return;
        }
        adapter = new MessageLeftAdapter(mContext, mList, this);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(OrientationHelper.VERTICAL);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void itemClick(int position) {
        if (getActivity() != null) {
            startActivity(new Intent(getActivity(), MessageReplyDetailActivity.class));
        }
    }
}
