// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java
// public abstract class BasePresenter<T extends IBaseView> {
//     protected CompositeSubscription mCompositeSubscription;
//     protected Context mContext;
//     protected T iView;
// 
//     public BasePresenter(Context context, T iView) {
//         this.mContext = context;
//         this.iView = iView;
//     }
// 
//     public void init() {
//         iView.init();
//     }
// 
//     public void release() {
//         if (this.mCompositeSubscription != null) {
//             this.mCompositeSubscription.unsubscribe();
//         }
//     }
// 
//     public void addSubscription(Subscription s) {
//         if (this.mCompositeSubscription == null) {
//             this.mCompositeSubscription = new CompositeSubscription();
//         }
//         this.mCompositeSubscription.add(s);
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/RankData.java
// public class RankData {
//     @Json(name = "comic_id") public int comicId;
//     public String title;
//     public String authors;
//     public String status;
//     public String cover;
//     public String types;
//     @Json(name = "last_updatetime") public Long lastUpdatetime;
// }


import android.content.Context;
import java.util.List;
import moe.yukinoneko.gcomic.R;
import moe.yukinoneko.gcomic.base.BasePresenter;
import moe.yukinoneko.gcomic.data.RankData;
import moe.yukinoneko.gcomic.network.GComicApi;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
/*
 * Copyright (C) 2016  SamuelGjk <samuel.alva@outlook.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.gcomic.module.main.rank;




/**
 * Created by SamuelGjk on 2016/4/7.
 */
public class RankPresenter extends BasePresenter<IRankView> {

    public RankPresenter(Context context, IRankView iView) {
        super(context, iView);
    }

    void fetchRankData(int page) {
        Subscription subscription = GComicApi.getInstance()
                                             .fetchRankData(page)
                                             .observeOn(AndroidSchedulers.mainThread())
                                             .subscribe(new Action1<List<RankData>>() {
                                                 @Override
                                                 public void call(List<RankData> rankDatas) {
                                                     iView.updateRankList(rankDatas);
                                                     iView.setRefreshing(false);
                                                 }
                                             }, new Action1<Throwable>() {
                                                 @Override
                                                 public void call(Throwable throwable) {
                                                     iView.showMessageSnackbar(R.string.message_load_error);
                                                     iView.setRefreshing(false);
                                                 }
                                             });
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java
// public abstract class BasePresenter<T extends IBaseView> {
//     protected CompositeSubscription mCompositeSubscription;
//     protected Context mContext;
//     protected T iView;
// 
//     public BasePresenter(Context context, T iView) {
//         this.mContext = context;
//         this.iView = iView;
//     }
// 
//     public void init() {
//         iView.init();
//     }
// 
//     public void release() {
//         if (this.mCompositeSubscription != null) {
//             this.mCompositeSubscription.unsubscribe();
//         }
//     }
// 
//     public void addSubscription(Subscription s) {
//         if (this.mCompositeSubscription == null) {
//             this.mCompositeSubscription = new CompositeSubscription();
//         }
//         this.mCompositeSubscription.add(s);
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/RankData.java
// public class RankData {
//     @Json(name = "comic_id") public int comicId;
//     public String title;
//     public String authors;
//     public String status;
//     public String cover;
//     public String types;
//     @Json(name = "last_updatetime") public Long lastUpdatetime;
// }


// Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/rank/RankPresenter.java
import android.content.Context;
import java.util.List;
import moe.yukinoneko.gcomic.R;
import moe.yukinoneko.gcomic.base.BasePresenter;
import moe.yukinoneko.gcomic.data.RankData;
import moe.yukinoneko.gcomic.network.GComicApi;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

/*
 * Copyright (C) 2016  SamuelGjk <samuel.alva@outlook.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.gcomic.module.main.rank;




/**
 * Created by SamuelGjk on 2016/4/7.
 */
public class RankPresenter extends BasePresenter<IRankView> {

    public RankPresenter(Context context, IRankView iView) {
        super(context, iView);
    }

    void fetchRankData(int page) {
        Subscription subscription = GComicApi.getInstance()
                                             .fetchRankData(page)
                                             .observeOn(AndroidSchedulers.mainThread())
                                             .subscribe(new Action1<List<RankData>>() {
                                                 @Override
                                                 public void call(List<RankData> rankDatas) {
                                                     iView.updateRankList(rankDatas);
                                                     iView.setRefreshing(false);
                                                 }
                                             }, new Action1<Throwable>() {
                                                 @Override
                                                 public void call(Throwable throwable) {
                                                     iView.showMessageSnackbar(R.string.message_load_error);
                                                     iView.setRefreshing(false);
                                                 }
                                             });
        addSubscription(subscription);