Skip to content

Commit

Permalink
网络请求抽取
Browse files Browse the repository at this point in the history
  • Loading branch information
080901 committed May 6, 2016
1 parent b0139b5 commit fafc53c
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 119 deletions.
13 changes: 0 additions & 13 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 3,12 @@

import com.example.y.mvp.mvp.Bean.ImageDetailBean;
import com.example.y.mvp.mvp.Bean.ImageDetailInfo;
import com.example.y.mvp.network.Network;
import com.example.y.mvp.network.NetWorkRequest;
import com.example.y.mvp.utils.LogUtils;

import java.util.List;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.Subscriber;

/**
* by y on 2016/4/29.
Expand All @@ -21,26 19,22 @@ public class ImageDetailModelImpl implements ImageDetailModel {
@Override
public void netWorkDetail(int id, final ImageDetailData imageDetailData) {

Network.getImageDetailApi().getImageDetail(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ImageDetailBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("ImageDetailModelImpl:-->", e.getMessage());
imageDetailData.error();
}

@Override
public void onNext(ImageDetailBean imageDetailBean) {
imageDetailData.addData(imageDetailBean.getList());
}
});
NetWorkRequest.imageDetail(id, new Subscriber<ImageDetailBean>() {
@Override
public void onCompleted() {
}

@Override
public void onError(Throwable e) {
LogUtils.i("ImageDetailModelImpl:-->", e.getMessage());
imageDetailData.error();
}

@Override
public void onNext(ImageDetailBean imageDetailBean) {
imageDetailData.addData(imageDetailBean.getList());
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 3,12 @@

import com.example.y.mvp.mvp.Bean.ImageListBean;
import com.example.y.mvp.mvp.Bean.ImageListInfo;
import com.example.y.mvp.network.Network;
import com.example.y.mvp.network.NetWorkRequest;
import com.example.y.mvp.utils.LogUtils;

import java.util.List;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.Subscriber;

/**
* by y on 2016/4/28.
Expand All @@ -19,26 17,25 @@ public class ImageListModelImpl implements ImageListModel {

@Override
public void netWorkList(int id, final int page, final ImageListData imageListData) {
Network.getImageListApi().getImageList(id, page)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ImageListBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("ImageListModelImpl:-->", e.getMessage());
imageListData.error();
}

@Override
public void onNext(ImageListBean imageListBean) {
imageListData.addData(imageListBean.getTngou());
}
});

NetWorkRequest.imageList(id, page, new Subscriber<ImageListBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("ImageListModelImpl:-->", e.getMessage());
imageListData.error();
}

@Override
public void onNext(ImageListBean imageListBean) {
imageListData.addData(imageListBean.getTngou());

}
});
}

public interface ImageListData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 3,12 @@

import com.example.y.mvp.mvp.Bean.ImageNewBean;
import com.example.y.mvp.mvp.Bean.ImageNewInfo;
import com.example.y.mvp.network.Network;
import com.example.y.mvp.network.NetWorkRequest;
import com.example.y.mvp.utils.LogUtils;

import java.util.List;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.Subscriber;

/**
* by 12406 on 2016/4/29.
Expand All @@ -20,27 18,25 @@ public class ImageNewModelImpl implements ImageNewModel {

@Override
public void netWorkNew(int id, int rows, final ImageNewData imageNewData) {
Network.getImageNewApi().getImageNews(id, rows)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ImageNewBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("ImageNewModelImpl", e.getMessage());
imageNewData.error();
}

@Override
public void onNext(ImageNewBean imageNewBean) {
imageNewData.addData(imageNewBean.getTngou());
LogUtils.i("imagenewBean_size", imageNewBean.getTngou().size() "");
}
});

NetWorkRequest.imageNew(id, rows, new Subscriber<ImageNewBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("ImageNewModelImpl", e.getMessage());
imageNewData.error();
}

@Override
public void onNext(ImageNewBean imageNewBean) {
imageNewData.addData(imageNewBean.getTngou());
LogUtils.i("imagenewBean_size", imageNewBean.getTngou().size() "");
}
});
}

public interface ImageNewData {
Expand Down
41 changes: 18 additions & 23 deletions app/src/main/java/com/example/y/mvp/mvp/model/TabNameModelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 3,12 @@

import com.example.y.mvp.mvp.Bean.TabNameBean;
import com.example.y.mvp.mvp.Bean.TabNameInfo;
import com.example.y.mvp.network.Network;
import com.example.y.mvp.network.NetWorkRequest;
import com.example.y.mvp.utils.LogUtils;

import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
* by y on 2016/4/28.
Expand All @@ -20,26 18,23 @@ public class TabNameModelImpl implements TabNameModel {

@Override
public void netWorkName(final TabNameData tabNameData) {
Network.getTabNameApi().getTabName()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<TabNameBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("TabNameModelImpl:-->", e.getMessage());
tabNameData.error();
}

@Override
public void onNext(TabNameBean tabNameBean) {
tabNameData.addData(tabNameBean.getTngou());
}
});
NetWorkRequest.tabName(new Subscriber<TabNameBean>() {
@Override
public void onCompleted() {

}

@Override
public void onError(Throwable e) {
LogUtils.i("TabNameModelImpl:-->", e.getMessage());
tabNameData.error();
}

@Override
public void onNext(TabNameBean tabNameBean) {
tabNameData.addData(tabNameBean.getTngou());
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 13,6 @@
*/
public interface ImageDetailApi {

@GET(Api.IMAGE_SHOW "?id" "id" "id")
@GET(Api.IMAGE_SHOW)
Observable<ImageDetailBean> getImageDetail(@Query("id") int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@
public interface ImageListApi {


@GET(Api.IMAGE_LIST "?id" "id" "id" "&" "page" "page")
@GET(Api.IMAGE_LIST)
Observable<ImageListBean> getImageList(@Query("id") int id, @Query("page") int page);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@
*/
public interface ImageNewApi {

@GET(Api.IMAGE_NEW "?id" "id" "id" "&" "rows" "rows")
@GET(Api.IMAGE_NEW)
Observable<ImageNewBean> getImageNews(@Query("id") int id, @Query("rows") int rows);

}
46 changes: 46 additions & 0 deletions app/src/main/java/com/example/y/mvp/network/NetWorkRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 1,46 @@
package com.example.y.mvp.network;

import com.example.y.mvp.mvp.Bean.ImageDetailBean;
import com.example.y.mvp.mvp.Bean.ImageListBean;
import com.example.y.mvp.mvp.Bean.ImageNewBean;
import com.example.y.mvp.mvp.Bean.TabNameBean;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
* by y on 2016/5/6.
*/
public class NetWorkRequest {


public static void imageDetail(int id, Subscriber<ImageDetailBean> subscriber) {
Network.getImageDetailApi().getImageDetail(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
}

public static void imageList(int id, int page, Subscriber<ImageListBean> subscriber) {
Network.getImageListApi().getImageList(id, page)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
}

public static void imageNew(int id, int rows, Subscriber<ImageNewBean> subscriber) {
Network.getImageNewApi().getImageNews(id, rows)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
}

public static void tabName(Subscriber<TabNameBean> subscriber) {
Network.getTabNameApi().getTabName()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
}

}

0 comments on commit fafc53c

Please sign in to comment.