王學崗csdn網路訪問框架的搭建
阿新 • • 發佈:2019-02-04
public abstract class BaseActivity extends FragmentActivity { private CompositeDisposable disposables = new CompositeDisposable(); public void addDispose(Disposable disposable){ disposables.add(disposable); } @Override protected void onDestroy() { super.onDestroy(); disposables.clear(); } }
訪問網路,使用Retroft
@GET(RunningGroupURL.GET_RUNGROUP_GETRANKFORGROUPUSER)
Observable<PublicResponseEntity<List<RankForGroupUserEntity>>> getRankForGroupUser(@QueryMap HashMap<String, Integer> params);
程式碼中引用
public class OtherTeamActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_other_team); addDispose(mServiceApi.getRankForGroupUser(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(Comsumer,Consumer)); } }
示例
addDispose(runningGroupViewMoudle.getRankForGroupUser(groupId, 1, userId, 1, pagesizeOfAve) // .doOnSubscribe(new Consumer<Disposable>() { // @Override // public void accept(Disposable disposable) throws Exception { // AlertDialog.Builder builder=new AlertDialog.Builder(OtherTeamActivity.this); // builder.setMessage("正在載入資料……"); // dialog = builder.create(); // dialog.show(); // } // }).doFinally(new Action() { // @Override // public void run() throws Exception { // dialog.dismiss(); // } // }) .subscribe(new Consumer<PublicResponseEntity<List<RankForGroupUserEntity>>>() { @Override public void accept(PublicResponseEntity<List<RankForGroupUserEntity>> listPublicResponseEntity) throws Exception { int memberCount = listPublicResponseEntity.getData().get(0).getStepsGroupUserRankResponseList().get(0).getMemberCount(); tv_other_team_numbers.setText("團隊成員(" + memberCount + ")"); List<RankForGroupUserEntity.StepsGroupUserRankResponseListBean> allData = listPublicResponseEntity.getData().get(1).getStepsGroupUserRankResponseList(); OtherTeamAverAdapter adapter = new OtherTeamAverAdapter(R.layout.personitemlayout, allData); recyclerView1.setAdapter(adapter); refreshLayout.finishLoadMore(); if (pagesizeOfAve >= memberCount) { refreshLayout.setEnableLoadMore(false); } } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { } })); } });
// 跑團個人排名
public Observable<PublicResponseEntity<List<RankForGroupUserEntity>>> getRankForGroupUser(int groupId, int type, int userId, int page, int pageSize){
HashMap<String, Integer> params = new HashMap<>();
params.put("groupId",groupId);
params.put("type",type);
params.put("userId",userId);
params.put("page",page);
params.put("pageSize",pageSize);
return mServiceApi.getRankForGroupUser(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
// 跑團個人排名
@GET(RunningGroupURL.GET_RUNGROUP_GETRANKFORGROUPUSER)
Observable<PublicResponseEntity<List<RankForGroupUserEntity>>> getRankForGroupUser(@QueryMap HashMap<String, Integer> params);