package com.liuguangqiang.recyclerview.sample;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.liuguangqiang.asyncokhttp.AsyncOkHttp;
import com.liuguangqiang.asyncokhttp.JsonResponseHandler;
import com.liuguangqiang.recyclerview.listener.OnPageListener;
import com.liuguangqiang.recyclerview.widget.SuperRecyclerView;

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

public class MainActivity extends AppCompatActivity implements OnPageListener {

    private SuperRecyclerView recyclerView;
    private List<Story> data = new ArrayList<>();
    private StoryAdapter adapter;

    private int lastDatetime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
        getDaily(lastDatetime);
    }

    private void initViews() {
        recyclerView = (SuperRecyclerView) findViewById(R.id.recycler_view);
        adapter = new StoryAdapter(getApplicationContext(), data);
        recyclerView.setAdapter(adapter);
        recyclerView.setOnPageListener(this);
    }

    @Override
    public void onPage() {
        getDaily(lastDatetime);
    }

    public void getDaily(int datetime) {
        String url = datetime > 0 ? ApiUtils.getNewsBefore(datetime) : ApiUtils.getLatest();
        AsyncOkHttp.getInstance().get(url, new JsonResponseHandler<Daily>(Daily.class) {
            @Override
            public void onSuccess(Daily daily) {
                if (daily != null) {
                    lastDatetime = daily.getDate();
                    data.addAll(daily.getStories());

                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            recyclerView.notifyDataSetChanged();
                            recyclerView.onLoadFinish();
                        }
                    }, 1000);
                }
            }

            @Override
            public void onStart() {
                super.onStart();
                recyclerView.onLoadStart();
            }
        });
    }

}

@@ -1,8 +1,610 @@
+/*%0A * Copyright 2015 Eric Liu%0A *%0A *  Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *  you may not use this file except in compliance with the License.%0A *  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A */%0A%0A
 package 
@@ -744,16 +744,63 @@
 .Bundle;
+%0Aimport android.support.v7.widget.RecyclerView;
 %0A%0Aimport
@@ -960,24 +960,157 @@
 geListener;%0A
+import com.liuguangqiang.recyclerview.widget.DividerItemDecoration;%0Aimport com.liuguangqiang.recyclerview.widget.LinearRecyclerView;%0A
 import com.l
@@ -1899,16 +1899,16 @@
 apter);%0A
-
         
@@ -1945,16 +1945,448 @@
 (this);%0A
+        recyclerView.addItemDecoration(new DividerItemDecoration(getApplicationContext()));%0A        recyclerView.setOnScrollListener(new LinearRecyclerView.OnScrollListener() %7B%0A            @Override%0A            public void onScrollStateChanged(RecyclerView recyclerView, int newState) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void onScrolled(RecyclerView recyclerView, int dx, int dy) %7B%0A%0A            %7D%0A        %7D);%0A
     %7D%0A%0A 

update sample.