package com.performance.liferecord;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
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.ImageView;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Gracker on 2016/3/22.
 */
public class ActivityFragment extends BaseFragment {
    private RecyclerView mRecyclerView ;
    private List<String> mDates;
    private List<String> mContents;

    public  ActivityFragment(){
        initData();
    }

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

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_fragment,null);
        mRecyclerView = (RecyclerView) rootView.findViewById(R.id.activity_recycke_view);
        //设置布局管理器
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        //设置adapter
        initData();
        mRecyclerView.setAdapter(new ActivityAdapter());
        //设置Item增加、移除动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        return rootView;
    }

    public static ActivityFragment newInstance() {
        
        Bundle args = new Bundle();
        
        ActivityFragment fragment = new ActivityFragment();
        fragment.setArguments(args);
        return fragment;
    }

    protected void initData()
    {
        mDates = new ArrayList<>();
        for (int i = 0; i < 30 ;  i++)
        {
            mDates.add("2016 年 3 月 " + i + " 号");
        }
        mContents = new ArrayList<>();
        for (int i = 0; i < 30 ;  i++)
        {
            mContents.add("看完了电视剧<看了又看>的第 " + i + " 集");
        }
    }

    class ActivityAdapter extends RecyclerView.Adapter<MyViewHolder>{

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    getContext()).inflate(R.layout.activity_recycleview_item_with_date, parent,
                    false));
            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            holder.date.setText(mDates.get(position));
            holder.content.setText(mContents.get(position));
            holder.content.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(new MessageEvent((String) ((TextView)v).getText()));
                }
            });
        }

        @Override
        public int getItemCount() {
            return mContents.size();
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        TextView date;
        ImageView type;
        TextView content;
        public MyViewHolder(View itemView) {
            super(itemView);
            date = (TextView) itemView.findViewById(R.id.activity_recycke_item_date);
            type = (ImageView) itemView.findViewById(R.id.activity_recycke_item_type);
            content = (TextView) itemView.findViewById(R.id.activity_recycke_item_content);
        }
    }
}

@@ -665,17 +665,16 @@
 clerView
- 
 ;%0D%0A    p
@@ -752,17 +752,16 @@
  public 
- 
 Activity
@@ -770,16 +770,17 @@
 agment()
+ 
 %7B%0D%0A     
@@ -1141,16 +1141,17 @@
 ragment,
+ 
 null);%0D%0A
@@ -1619,24 +1619,16 @@
 ce() %7B%0D%0A
-        
 %0D%0A      
@@ -1658,24 +1658,16 @@
 dle();%0D%0A
-        
 %0D%0A      
@@ -1823,21 +1823,16 @@
 itData()
-%0D%0A   
  %7B%0D%0A    
@@ -1894,33 +1894,22 @@
 ; i %3C 30
- ; 
+;
  i++)
-%0D%0A       
  %7B%0D%0A    
@@ -2040,25 +2040,14 @@
 %3C 30
- ; 
+;
  i++)
-%0D%0A       
  %7B%0D%0A
@@ -2192,16 +2192,17 @@
 wHolder%3E
+ 
 %7B%0D%0A%0D%0A   
@@ -2986,16 +2986,17 @@
 extView)
+ 
 v).getTe
@@ -3221,16 +3221,17 @@
 ewHolder
+ 
 %7B%0D%0A%0D%0A   
@@ -3299,24 +3299,26 @@
 w content;%0D%0A
+%0D%0A
         publ

format code