Skip to content

Commit

Permalink
修复程序崩溃问题,修复多次请求网络的问题,更改网络访问框架,采用OkHttp+Retrofit+RxJava。
Browse files Browse the repository at this point in the history
  • Loading branch information
lilongweidev committed Jul 23, 2021
1 parent db216a1 commit 90842db
Show file tree
Hide file tree
Showing 52 changed files with 2,079 additions and 601 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "2.6"
versionName "2.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
171 changes: 86 additions & 85 deletions app/src/main/java/com/llw/goodweather/MainActivity.java

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions app/src/main/java/com/llw/goodweather/NetworkRequiredInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.llw.goodweather;

import android.app.Application;

import com.llw.mvplibrary.BuildConfig;
import com.llw.mvplibrary.newnet.INetworkRequiredInfo;


/**
* 网络访问信息
* @author llw
*/
public class NetworkRequiredInfo implements INetworkRequiredInfo {

private Application application;

public NetworkRequiredInfo(Application application){
this.application = application;
}

/**
* 版本名
*/
@Override
public String getAppVersionName() {
return BuildConfig.VERSION_NAME;
}
/**
* 版本号
*/
@Override
public String getAppVersionCode() {
return String.valueOf(BuildConfig.VERSION_CODE);
}

/**
* 是否为debug
*/
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}

/**
* 应用全局上下文
*/
@Override
public Application getApplicationContext() {
return application;
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/llw/goodweather/WeatherApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.iflytek.cloud.SpeechUtility;
import com.llw.goodweather.utils.GlideUtil;
import com.llw.mvplibrary.BaseApplication;
import com.llw.mvplibrary.newnet.NetworkApi;
import com.llw.mvplibrary.utils.ActivityManager;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
Expand Down Expand Up @@ -102,6 +103,9 @@ public void onActivityDestroyed(Activity activity) {
}
});

//初始化网络框架
NetworkApi.init(new NetworkRequiredInfo(this));

//初始化数据库
LitePal.initialize(this);

Expand Down
48 changes: 34 additions & 14 deletions app/src/main/java/com/llw/goodweather/api/ApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.llw.mvplibrary.bean.AppVersion;
import com.llw.mvplibrary.bean.WallPaper;

import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
Expand All @@ -42,13 +43,16 @@ public interface ApiService {
* getTodayWeather是这个接口的方法名。这样说应该很清楚了吧
*/



/**
* 必应每日一图
*
* @return BiYingImgResponse 必应壁纸返回
*/
@GET("/HPImageArchive.aspx?format=js&idx=0&n=1")
Call<BiYingImgResponse> biying();
Observable<BiYingImgResponse> biying();
// Call<BiYingImgResponse> biying();

/********** 以下为 V7版本API使用 **************/

Expand All @@ -59,7 +63,8 @@ public interface ApiService {
* @return 返回实况天气数据 NowResponse
*/
@GET("/v7/weather/now?key=" + API_KEY + "&gzip=n")
Call<NowResponse> nowWeather(@Query("location") String location);
Observable<NowResponse> nowWeather(@Query("location") String location);
//Call<NowResponse> nowWeather(@Query("location") String location);

/**
* 天气预报 因为是开发者所以最多可以获得15天的数据,但是如果你是普通用户,那么最多只能获得三天的数据
Expand All @@ -70,7 +75,8 @@ public interface ApiService {
* @return 返回天气预报数据 DailyResponse
*/
@GET("/v7/weather/{type}?key=" + API_KEY)
Call<DailyResponse> dailyWeather(@Path("type") String type, @Query("location") String location);
Observable<DailyResponse> dailyWeather(@Path("type") String type, @Query("location") String location);
//Call<DailyResponse> dailyWeather(@Path("type") String type, @Query("location") String location);

/**
* 逐小时预报(未来24小时)之前是逐三小时预报
Expand All @@ -79,7 +85,8 @@ public interface ApiService {
* @return 返回逐小时数据 MoreAirFiveResponse
*/
@GET("/v7/weather/24h?key=" + API_KEY)
Call<HourlyResponse> hourlyWeather(@Query("location") String location);
Observable<HourlyResponse> hourlyWeather(@Query("location") String location);
//Call<HourlyResponse> hourlyWeather(@Query("location") String location);

/**
* 当天空气质量
Expand All @@ -88,7 +95,8 @@ public interface ApiService {
* @return 返回当天空气质量数据 MoreAirFiveResponse
*/
@GET("/v7/air/now?key=" + API_KEY)
Call<AirNowResponse> airNowWeather(@Query("location") String location);
Observable<AirNowResponse> airNowWeather(@Query("location") String location);
// Call<AirNowResponse> airNowWeather(@Query("location") String location);

/**
* 空气质量5天预报
Expand All @@ -97,7 +105,8 @@ public interface ApiService {
* @return 返回空气质量5天预报数据 MoreAirFiveResponse
*/
@GET("/v7/air/5d?key=" + API_KEY)
Call<MoreAirFiveResponse> airFiveWeather(@Query("location") String location);
Observable<MoreAirFiveResponse> airFiveWeather(@Query("location") String location);
// Call<MoreAirFiveResponse> airFiveWeather(@Query("location") String location);

/**
* 生活指数
Expand All @@ -110,8 +119,10 @@ public interface ApiService {
* @return LifestyleResponse 生活指数数据返回
*/
@GET("/v7/indices/1d?key=" + API_KEY)
Call<LifestyleResponse> lifestyle(@Query("type") String type,
Observable<LifestyleResponse> lifestyle(@Query("type") String type,
@Query("location") String location);
// Call<LifestyleResponse> lifestyle(@Query("type") String type,
// @Query("location") String location);

/**
* 搜索城市 V7版本 模糊搜索,国内范围 返回10条数据
Expand All @@ -121,8 +132,10 @@ Call<LifestyleResponse> lifestyle(@Query("type") String type,
* @return NewSearchCityResponse 搜索城市数据返回
*/
@GET("/v2/city/lookup?key=" + API_KEY + "&range=cn")
Call<NewSearchCityResponse> newSearchCity(@Query("location") String location,
Observable<NewSearchCityResponse> newSearchCity(@Query("location") String location,
@Query("mode") String mode);
// Call<NewSearchCityResponse> newSearchCity(@Query("location") String location,
// @Query("mode") String mode);

/**
* 世界城市
Expand All @@ -131,7 +144,8 @@ Call<NewSearchCityResponse> newSearchCity(@Query("location") String location,
* @return WorldCityResponse 世界城市数据返回
*/
@GET("/v2/city/top?key=" + API_KEY + "&number=20")
Call<WorldCityResponse> worldCity(@Query("range") String range);
Observable<WorldCityResponse> worldCity(@Query("range") String range);
//Call<WorldCityResponse> worldCity(@Query("range") String range);

/**
* 当前城市灾害预警
Expand All @@ -140,15 +154,18 @@ Call<NewSearchCityResponse> newSearchCity(@Query("location") String location,
* @return WarningResponse 灾害预警返回
*/
@GET("/v7/warning/now?key=" + API_KEY)
Call<WarningResponse> nowWarn(@Query("location") String location);
Observable<WarningResponse> nowWarn(@Query("location") String location);
//Call<WarningResponse> nowWarn(@Query("location") String location);

/**
* APP版本更新
*
* @return AppVersion 版本信息返回
*/
@GET("/apps/latest/" + UPDATE_USER_ID + "?api_token=" + UPDATE_API_TOKEN)
Call<AppVersion> getAppInfo();
Observable<AppVersion> getAppInfo();
// @GET("/apps/latest/" + UPDATE_USER_ID + "?api_token=" + UPDATE_API_TOKEN)
// Call<AppVersion> getAppInfo();

/**
* 太阳和月亮 日出日落、月升月落
Expand All @@ -158,15 +175,17 @@ Call<NewSearchCityResponse> newSearchCity(@Query("location") String location,
* @return SunMoonResponse 太阳和月亮数据返回
*/
@GET("/v7/astronomy/sunmoon?key=" + API_KEY)
Call<SunMoonResponse> getSunMoon(@Query("location") String location, @Query("date") String date);
Observable<SunMoonResponse> getSunMoon(@Query("location") String location, @Query("date") String date);
//Call<SunMoonResponse> getSunMoon(@Query("location") String location, @Query("date") String date);

/**
* 手机壁纸API
*
* @return WallPaperResponse 网络壁纸数据返回
*/
@GET("/v1/vertical/vertical?limit=30&skip=180&adult=false&first=0&order=hot")
Call<WallPaperResponse> getWallPaper();
Observable<WallPaperResponse> getWallPaper();
//Call<WallPaperResponse> getWallPaper();


/**
Expand All @@ -176,6 +195,7 @@ Call<NewSearchCityResponse> newSearchCity(@Query("location") String location,
* @return
*/
@GET("/v7/minutely/5m?key=" + API_KEY)
Call<MinutePrecResponse> getMinutePrec(@Query("location") String location);
Observable<MinutePrecResponse> getMinutePrec(@Query("location") String location);
//Call<MinutePrecResponse> getMinutePrec(@Query("location") String location);

}
Loading

0 comments on commit 90842db

Please sign in to comment.