// Path: app/src/main/java/me/zsj/interessant/api/DailyApi.java
// public interface DailyApi {
// 
//     @GET("v2/feed?num=2")
//     Flowable<Daily> getDaily(@Query("date") long date);
// 
//     @GET("v2/feed?num=2")
//     Flowable<Daily> getDaily();
// 
// }
// 
// Path: app/src/main/java/me/zsj/interessant/base/ToolbarActivity.java
// public abstract class ToolbarActivity extends RxAppCompatActivity {
// 
//     public Toolbar toolbar;
//     public ActionBar ab;
// 
//     public abstract int providerLayoutId();
// 
//     @Override
//     protected void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(providerLayoutId());
// 
//         toolbar = (Toolbar) findViewById(R.id.toolbar);
//         setSupportActionBar(toolbar);
// 
//         ab = getSupportActionBar();
//         if (ab != null)
//             ab.setDisplayHomeAsUpEnabled(true);
// 
//     }
// 
//     public void toSearch(Activity context) {
//         Intent intent = new Intent(context, SearchActivity.class);
//         startActivity(intent);
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/model/Category.java
// public class Category {
// 
//     public String categoryTitle;
// 
//     public Category(@NonNull String categoryTitle) {
//         this.categoryTitle = categoryTitle;
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/model/Daily.java
// public class Daily {
// 
//     public String nextPageUrl;
//     public List<IssueList> issueList;
// 
//     public static class IssueList {
//         public long releaseTime;
//         public String type;
//         public long date;
//         public long publishTime;
//         public int count;
//         public List<ItemList> itemList;
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/rx/ErrorAction.java
// public class ErrorAction {
// 
//     private ErrorAction() {
//         throw new AssertionError("No instances.");
//     }
// 
//     public static Consumer<Throwable> error(Context context) {
//         return throwable -> {
//             throwable.printStackTrace();
//             Toasty.error(context, throwable.getMessage()).show();
//         };
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/rx/RxScroller.java
// public class RxScroller {
// 
//     private RxScroller() {
//         throw new AssertionError("No instances.");
//     }
// 
//     public static <T> ObservableTransformer<Integer, Integer> scrollTransformer(
//             final LinearLayoutManager layoutManager, final RecyclerView.Adapter adapter,
//             final List<T> data) {
//         return integerObservable -> integerObservable
//                 .filter(integer -> layoutManager.findFirstCompletelyVisibleItemPosition() >=
//                             adapter.getItemCount() - 4)
//                 .filter(integer -> data.size() != 0)
//                 .filter(integer -> layoutManager.findFirstVisibleItemPosition() != 0);
//     }
// 
// }


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import com.jakewharton.rxbinding2.support.v4.widget.RxSwipeRefreshLayout;
import com.jakewharton.rxbinding2.support.v7.widget.RxRecyclerView;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import me.drakeet.multitype.Items;
import me.drakeet.multitype.MultiTypeAdapter;
import me.zsj.interessant.api.DailyApi;
import me.zsj.interessant.base.ToolbarActivity;
import me.zsj.interessant.model.Category;
import me.zsj.interessant.model.Daily;
import me.zsj.interessant.rx.ErrorAction;
import me.zsj.interessant.rx.RxScroller;

            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0) {
                    getWindow().setStatusBarColor(ContextCompat.getColor(
                            MainActivity.this, android.R.color.transparent));
                } else {
                    getWindow().setStatusBarColor(ContextCompat.getColor(
                            MainActivity.this, R.color.colorPrimaryDark));
                }
            }
        });
    }

    private void loadData() {
        loadData(false /*Load more data. */);
    }

    private void loadData(final boolean clear) {
        Flowable<Daily> result;
        if (clear) result = dailyApi.getDaily();
        else result = dailyApi.getDaily(Long.decode(dateTime));

        result.compose(bindToLifecycle())
                .filter(daily -> daily != null)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(daily -> {
                    if (clear) items.clear();
                })
                .doAfterTerminate(() -> {

// Path: app/src/main/java/me/zsj/interessant/api/DailyApi.java
// public interface DailyApi {
// 
//     @GET("v2/feed?num=2")
//     Flowable<Daily> getDaily(@Query("date") long date);
// 
//     @GET("v2/feed?num=2")
//     Flowable<Daily> getDaily();
// 
// }
// 
// Path: app/src/main/java/me/zsj/interessant/base/ToolbarActivity.java
// public abstract class ToolbarActivity extends RxAppCompatActivity {
// 
//     public Toolbar toolbar;
//     public ActionBar ab;
// 
//     public abstract int providerLayoutId();
// 
//     @Override
//     protected void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(providerLayoutId());
// 
//         toolbar = (Toolbar) findViewById(R.id.toolbar);
//         setSupportActionBar(toolbar);
// 
//         ab = getSupportActionBar();
//         if (ab != null)
//             ab.setDisplayHomeAsUpEnabled(true);
// 
//     }
// 
//     public void toSearch(Activity context) {
//         Intent intent = new Intent(context, SearchActivity.class);
//         startActivity(intent);
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/model/Category.java
// public class Category {
// 
//     public String categoryTitle;
// 
//     public Category(@NonNull String categoryTitle) {
//         this.categoryTitle = categoryTitle;
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/model/Daily.java
// public class Daily {
// 
//     public String nextPageUrl;
//     public List<IssueList> issueList;
// 
//     public static class IssueList {
//         public long releaseTime;
//         public String type;
//         public long date;
//         public long publishTime;
//         public int count;
//         public List<ItemList> itemList;
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/rx/ErrorAction.java
// public class ErrorAction {
// 
//     private ErrorAction() {
//         throw new AssertionError("No instances.");
//     }
// 
//     public static Consumer<Throwable> error(Context context) {
//         return throwable -> {
//             throwable.printStackTrace();
//             Toasty.error(context, throwable.getMessage()).show();
//         };
//     }
// }
// 
// Path: app/src/main/java/me/zsj/interessant/rx/RxScroller.java
// public class RxScroller {
// 
//     private RxScroller() {
//         throw new AssertionError("No instances.");
//     }
// 
//     public static <T> ObservableTransformer<Integer, Integer> scrollTransformer(
//             final LinearLayoutManager layoutManager, final RecyclerView.Adapter adapter,
//             final List<T> data) {
//         return integerObservable -> integerObservable
//                 .filter(integer -> layoutManager.findFirstCompletelyVisibleItemPosition() >=
//                             adapter.getItemCount() - 4)
//                 .filter(integer -> data.size() != 0)
//                 .filter(integer -> layoutManager.findFirstVisibleItemPosition() != 0);
//     }
// 
// }


// Path: app/src/main/java/me/zsj/interessant/MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import com.jakewharton.rxbinding2.support.v4.widget.RxSwipeRefreshLayout;
import com.jakewharton.rxbinding2.support.v7.widget.RxRecyclerView;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import me.drakeet.multitype.Items;
import me.drakeet.multitype.MultiTypeAdapter;
import me.zsj.interessant.api.DailyApi;
import me.zsj.interessant.base.ToolbarActivity;
import me.zsj.interessant.model.Category;
import me.zsj.interessant.model.Daily;
import me.zsj.interessant.rx.ErrorAction;
import me.zsj.interessant.rx.RxScroller;

            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0) {
                    getWindow().setStatusBarColor(ContextCompat.getColor(
                            MainActivity.this, android.R.color.transparent));
                } else {
                    getWindow().setStatusBarColor(ContextCompat.getColor(
                            MainActivity.this, R.color.colorPrimaryDark));
                }
            }
        });
    }

    private void loadData() {
        loadData(false /*Load more data. */);
    }

    private void loadData(final boolean clear) {
        Flowable<Daily> result;
        if (clear) result = dailyApi.getDaily();
        else result = dailyApi.getDaily(Long.decode(dateTime));

        result.compose(bindToLifecycle())
                .filter(daily -> daily != null)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(daily -> {
                    if (clear) items.clear();
                })
                .doAfterTerminate(() -> {

                    refreshLayout.setRefreshing(false);
