package com.gh.gamecenter.search;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gh.base.AppController;
import com.gh.gamecenter.R;

public class SearchGameListFragment extends Fragment {

	public static final String TAG = SearchGameListFragment.class.getSimpleName();

	private View view;

	private String key;

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		view = View.inflate(getActivity(), R.layout.fm_search, null);

		TextView reuse_tv_none_data = (TextView) view.findViewById(R.id.reuse_tv_none_data);
		reuse_tv_none_data.setText("搜索为空");

		LinearLayout search_loading = (LinearLayout) view.findViewById(R.id.search_gamedetail_ll_loading);
		LinearLayout search_nogame = (LinearLayout) view.findViewById(R.id.reuse_none_data);
		LinearLayout search_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);

		RecyclerView search_detail = (RecyclerView) view.findViewById(R.id.search_detail);
		search_detail.setHasFixedSize(true);
		search_detail.setLayoutManager(new LinearLayoutManager(getActivity()));
		search_detail.setAdapter(new SearchGameListFragmentAdapter(getActivity(), search_detail,
				search_loading, search_nogame, search_connection, key));
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
							 @Nullable Bundle savedInstanceState) {
		if (container != null) {
			container.removeView(view);
		}
		return view;
	}

	public void setKey(String key) {
		this.key = key;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		AppController.canclePendingRequests(TAG);
		view = null;
		key = null;
	}
}
