Skip to content

Commit

Permalink
修改api地址
Browse files Browse the repository at this point in the history
  • Loading branch information
zj-wukewei committed May 8, 2017
1 parent a7a37e3 commit a0cd46b
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,5 @@
.DS_Store
/build
/captures
/node_modules
/node_modules
/projectFilesBackup1
6 changes: 3 additions & 3 deletions .vscode/typings/react-native/react-native.d.ts
Expand Up @@ -980,7 +980,7 @@ declare namespace __React {
}

/**
* //FIXME: No documentation extracted from code comment on WebView.ios.js
* //FIXME: No documentation extracted from showapi_res_code comment on WebView.ios.js
*/
export interface NavState {

Expand Down Expand Up @@ -2303,7 +2303,7 @@ declare namespace __React {
}

/**
* //FIXME: Could not find docs. Inferred from examples and js code: ListViewDataSource.js
* //FIXME: Could not find docs. Inferred from examples and js showapi_res_code: ListViewDataSource.js
*/
export interface ListViewDataSource {
new( onAsset: DataSourceAssetCallback ): ListViewDataSource;
Expand Down Expand Up @@ -2616,7 +2616,7 @@ declare namespace __React {

/**
* This controls how often the scroll event will be fired while scrolling (in events per seconds).
* A higher number yields better accuracy for code that is tracking the scroll position,
* A higher number yields better accuracy for showapi_res_code that is tracking the scroll position,
* but can lead to scroll performance problems due to the volume of information being send over the bridge.
* The default value is zero, which means the scroll event will be sent only once each time the view is scrolled.
*/
Expand Down
4 changes: 2 additions & 2 deletions .vscode/typings/react/react.d.ts
Expand Up @@ -1923,7 +1923,7 @@ declare namespace __React {
canvas: HTMLFactory;
caption: HTMLFactory;
cite: HTMLFactory;
code: HTMLFactory;
showapi_res_code: HTMLFactory;
col: HTMLFactory;
colgroup: HTMLFactory;
data: HTMLFactory;
Expand Down Expand Up @@ -2155,7 +2155,7 @@ declare namespace JSX {
canvas: React.HTMLProps<HTMLCanvasElement>;
caption: React.HTMLProps<HTMLElement>;
cite: React.HTMLProps<HTMLElement>;
code: React.HTMLProps<HTMLElement>;
showapi_res_code: React.HTMLProps<HTMLElement>;
col: React.HTMLProps<HTMLTableColElement>;
colgroup: React.HTMLProps<HTMLTableColElement>;
data: React.HTMLProps<HTMLElement>;
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/wkw/hot/common/Constants.java
Expand Up @@ -4,8 +4,9 @@
* Created by wukewei on 16/5/26.
*/
public class Constants {
public static final String Base_Url = "http://apis.baidu.com/";
public static final String Api_Key = "ff27ef67506b2c0738a3252b01f8d564";
public static final String Base_Url = "http://route.showapi.com/";
public static final String Api_Key = "c12cf1979a384b119ebe7583f5dea18c";
public static final String Showapi_appid = "37613";
public static final String NEW_LIST = "new_list";
public static final int HTTP_CONNECT_TIMEOUT = 16000;
public static final int PAGE_SIZE = 20;
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/wkw/hot/data/DataManager.java
Expand Up @@ -5,6 +5,7 @@
import com.wkw.hot.common.Constants;
import com.wkw.hot.data.api.HotApi;
import com.wkw.hot.entity.ListPopularEntity;
import com.wkw.hot.entity.PagePopularEntity;
import com.wkw.hot.entity.PopularEntity;
import com.wkw.common_lib.rx.RxResultHelper;
import com.wkw.common_lib.rx.SchedulersCompat;
Expand All @@ -16,6 +17,7 @@

import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;

/**
* Created by wukewei on 16/7/12.
Expand Down Expand Up @@ -57,15 +59,20 @@ public List<String> getTabs() {
* @return
*/
public Observable<List<PopularEntity>> getPopular(int pn, String type) {
return mHotApi.getPopular(pn, Constants.PAGE_SIZE, type)
return mHotApi.getPopular(pn, type, Constants.Showapi_appid, Constants.Api_Key)
.compose(SchedulersCompat.applyIoSchedulers())
.compose(RxResultHelper.handleResult())
.doOnNext(populars -> {
if (pn == 1) {
ListPopularEntity popular = new ListPopularEntity(populars);
ListPopularEntity popular = new ListPopularEntity(populars.getPagebean().getContentlist());
cacheLoader.upNewData(type, popular);
}
});
})
.flatMap(new Func1<PagePopularEntity, Observable<List<PopularEntity>>>() {
@Override public Observable<List<PopularEntity>> call(PagePopularEntity pagePopularEntity) {
return Observable.just(pagePopularEntity.getPagebean().getContentlist());
}
});
}

/***
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/wkw/hot/data/api/HotApi.java
@@ -1,19 +1,19 @@
package com.wkw.hot.data.api;

import com.wkw.common_lib.rx.ApiResponse;
import com.wkw.hot.entity.PopularEntity;

import java.util.List;

import com.wkw.hot.entity.PagePopularEntity;
import retrofit2.http.GET;
import retrofit2.http.Query;
import rx.Observable;

/**
* Created by wukewei on 16/5/26.
*/
public interface HotApi {

@GET("txapi/weixin/wxhot")
rx.Observable<ApiResponse<List<PopularEntity>>> getPopular(@Query("page") int page, @Query("num") int num, @Query("word") String word);
@GET("582-2")
Observable<ApiResponse<PagePopularEntity>> getPopular(@Query("page") int page, @Query("key") String word,
@Query("showapi_appid") String showapi_appid,
@Query("showapi_sign") String showapi_sign);

}
101 changes: 101 additions & 0 deletions app/src/main/java/com/wkw/hot/entity/PagePopularEntity.java
@@ -0,0 +1,101 @@
package com.wkw.hot.entity;

import com.google.gson.annotations.SerializedName;
import java.util.List;

/**
* Created by wukewei on 17/5/8.
* Email zjwkw1992@163.com
* GitHub https://github.com/zj-wukewei
*/

public class PagePopularEntity {
@SerializedName("ret_code")
private int retCode;
@SerializedName("pagebean")
private Pagebean pagebean;


public int getRetCode() {
return retCode;
}


public void setRetCode(int retCode) {
this.retCode = retCode;
}


public Pagebean getPagebean() {
return pagebean;
}


public void setPagebean(Pagebean pagebean) {
this.pagebean = pagebean;
}


public static class Pagebean {
@SerializedName("allPages")
private int allPages;
@SerializedName("contentlist")
private List<PopularEntity> contentlist;
@SerializedName("currentPage")
private int currentPage;
@SerializedName("allNum")
private int allNum;
@SerializedName("maxResult")
private int maxResult;


public int getMaxResult() {
return maxResult;
}


public void setMaxResult(int maxResult) {
this.maxResult = maxResult;
}


public int getAllPages() {
return allPages;
}


public void setAllPages(int allPages) {
this.allPages = allPages;
}


public List<PopularEntity> getContentlist() {
return contentlist;
}


public void setContentlist(List<PopularEntity> contentlist) {
this.contentlist = contentlist;
}


public int getCurrentPage() {
return currentPage;
}


public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}


public int getAllNum() {
return allNum;
}


public void setAllNum(int allNum) {
this.allNum = allNum;
}
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/wkw/hot/entity/PopularEntity.java
Expand Up @@ -28,13 +28,13 @@ public String toString() {
* url : http://mp.weixin.qq.com/s?__biz=MjM5MTE1ODI2MA==&idx=2&mid=2651787931&sn=009a0d9df1accebef2adba14cc61ac9d
*/

@SerializedName("ctime")
@SerializedName("date")
private String ctime;
@SerializedName("title")
private String title;
@SerializedName("description")
@SerializedName("userName")
private String description;
@SerializedName("picUrl")
@SerializedName("contentImg")
private String picUrl;
@SerializedName("url")
private String url;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Expand Up @@ -26,7 +26,7 @@
"io.reactivex:rxandroid:1.2.0"\n
"com.squareup.retrofit2:converter-gson:2.0.2"\n
"com.squareup.retrofit2:adapter-rxjava:2.0.2"\n
"com.google.code.gson:gson:2.6.2"\n
"com.google.showapi_res_code.gson:gson:2.6.2"\n
"com.github.bumptech.glide:glide:3.7.0"\n
"com.jakewharton:butterknife:7.0.1"\n
"com.google.dagger:dagger:2.0"\n
Expand Down
30 changes: 15 additions & 15 deletions common_lib/src/main/java/com/wkw/common_lib/rx/ApiResponse.java
Expand Up @@ -5,38 +5,38 @@
*/
public class ApiResponse<T> {

public static final int SUCCESS_CODE = 200;
public static final int SUCCESS_CODE = 0;

private int code;
private String msg;
private T newslist;
private int showapi_res_code;
private String showapi_res_error;
private T showapi_res_body;

public int getCode() {
return code;
public int getShowapi_res_code() {
return showapi_res_code;
}

public void setCode(int code) {
this.code = code;
public void setShowapi_res_code(int showapi_res_code) {
this.showapi_res_code = showapi_res_code;
}

public String getMsg() {
return msg;
public String getShowapi_res_error() {
return showapi_res_error;
}

public void setMsg(String msg) {
this.msg = msg;
public void setShowapi_res_error(String showapi_res_error) {
this.showapi_res_error = showapi_res_error;
}

public T getNewsList() {
return newslist;
return showapi_res_body;
}

public void setNewsList(T newsList) {
this.newslist = newsList;
this.showapi_res_body = newsList;
}

public boolean isSuccess() {
if (this.code == SUCCESS_CODE) {
if (this.showapi_res_code == SUCCESS_CODE) {
return true;
} else {
return false;
Expand Down
Expand Up @@ -25,7 +25,7 @@ public Observable<T> call(ApiResponse<T> tApiResponse) {
} else if (tApiResponse.isSuccess()) {
return createData(tApiResponse.getNewsList());
} else {
return Observable.error(new ServerException(tApiResponse.getCode(),tApiResponse.getMsg()));
return Observable.error(new ServerException(tApiResponse.getShowapi_res_code(),tApiResponse.getShowapi_res_error()));
}
}
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ public static String handleError(ErrorBundle e) {
} else if (exception instanceof NetworkConnectionException) {
message = "网络中断,请检查您的网络状态";
} else if (exception instanceof ServerException) {
int code = ((ServerException) e).getCode();
int code = ((ServerException) exception).getCode();
//在这里你可以获取code来判断是什么类型 好比有些token失效了你就可以实现跳转到登录页面
message = e.getErrorMessage();
} else {
Expand Down
12 changes: 6 additions & 6 deletions version.gradle
@@ -1,7 +1,7 @@
ext {
android = [
compileSdkVersion : 23,
buildToolsVersion : "23.0.2",
compileSdkVersion : 25,
buildToolsVersion : "25.0.1",
applicationId : "com.wkw.hot",
minSdkVersion : 16,
targetSdkVersion : 22,
Expand All @@ -11,10 +11,10 @@ ext {
]

dependencies = [
"appcompat-v7" : "com.android.support:appcompat-v7:23.4.0",
"design" : "com.android.support:design:23.4.0",
"cardview" : "com.android.support:cardview-v7:23.4.0",
"recyclerview-v7" : "com.android.support:recyclerview-v7:23.4.0",
"appcompat-v7" : "com.android.support:appcompat-v7:25.0.1",
"design" : "com.android.support:design:25.0.1",
"cardview" : "com.android.support:cardview-v7:25.0.1",
"recyclerview-v7" : "com.android.support:recyclerview-v7:25.0.1",
"retrofit" : "com.squareup.retrofit2:retrofit:2.0.2",
"logging-interceptor" : "com.squareup.okhttp3:logging-interceptor:3.4.1",
"rxandroid" : "io.reactivex:rxandroid:1.2.0",
Expand Down

0 comments on commit a0cd46b

Please sign in to comment.