Skip to content

Commit

Permalink
3.002
Browse files Browse the repository at this point in the history
  • Loading branch information
WangDaYeeeeee committed Feb 21, 2021
1 parent 5464f84 commit 28b0405
Show file tree
Hide file tree
Showing 33 changed files with 160,662 additions and 160,580 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "wangdaye.com.geometricweather"
minSdkVersion 19
targetSdkVersion 30
versionCode 30001
versionName "3.001"
versionCode 30002
versionName "3.002"
multiDexEnabled true
ndk {
abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package wangdaye.com.geometricweather.common.rxjava;

import androidx.annotation.NonNull;

import io.reactivex.observers.DisposableObserver;

public abstract class BaseObserver<T> extends DisposableObserver<T> {
Expand All @@ -9,7 +11,7 @@ public abstract class BaseObserver<T> extends DisposableObserver<T> {
public abstract void onFailed();

@Override
public void onNext(T t) {
public void onNext(@NonNull T t) {
if (t == null) {
onFailed();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected void onStart() {
}

@Override
public void onNext(T t) {
public void onNext(@NonNull T t) {
if (observer != null) {
observer.onNext(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
import wangdaye.com.geometricweather.weather.json.accu.AccuHourlyResult;
import wangdaye.com.geometricweather.weather.json.accu.AccuLocationResult;
import wangdaye.com.geometricweather.weather.json.accu.AccuMinuteResult;
import wangdaye.com.geometricweather.weather.services.WeatherService;

public class AccuResultConverter {

@NonNull
public static Location convert(@Nullable Location location, AccuLocationResult result,
@Nullable String zipCode) {
if (location != null
Expand Down Expand Up @@ -101,16 +103,17 @@ public static Location convert(@Nullable Location location, AccuLocationResult r
}
}

public static Weather convert(Context context,
Location location,
AccuCurrentResult currentResult,
AccuDailyResult dailyResult,
List<AccuHourlyResult> hourlyResultList,
@Nullable AccuMinuteResult minuteResult,
@Nullable AccuAqiResult aqiResult,
List<AccuAlertResult> alertResultList) {
@NonNull
public static WeatherService.WeatherResultWrapper convert(Context context,
Location location,
AccuCurrentResult currentResult,
AccuDailyResult dailyResult,
List<AccuHourlyResult> hourlyResultList,
@Nullable AccuMinuteResult minuteResult,
@Nullable AccuAqiResult aqiResult,
List<AccuAlertResult> alertResultList) {
try {
return new Weather(
Weather weather = new Weather(
new Base(
location.getCityId(),
System.currentTimeMillis(),
Expand Down Expand Up @@ -189,8 +192,9 @@ public static Weather convert(Context context,
),
getAlertList(alertResultList)
);
return new WeatherService.WeatherResultWrapper(weather);
} catch (Exception ignored) {
return null;
return new WeatherService.WeatherResultWrapper(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
import wangdaye.com.geometricweather.common.basic.models.weather.Wind;
import wangdaye.com.geometricweather.common.basic.models.weather.WindDegree;
import wangdaye.com.geometricweather.weather.json.cn.CNWeatherResult;
import wangdaye.com.geometricweather.weather.services.WeatherService;

public class CNResultConverter {

public static Weather convert(Context context,
@NonNull Location location, @Nullable CNWeatherResult result) {
@NonNull
public static WeatherService.WeatherResultWrapper convert(Context context,
@NonNull Location location,
@Nullable CNWeatherResult result) {
if (result == null) {
return null;
return new WeatherService.WeatherResultWrapper(null);
}

try {
Expand All @@ -58,7 +61,7 @@ public static Weather convert(Context context,
);
result.weather.remove(0);

return new Weather(
Weather weather = new Weather(
new Base(
location.getCityId(),
System.currentTimeMillis(),
Expand Down Expand Up @@ -134,9 +137,10 @@ public static Weather convert(Context context,
new ArrayList<>(),
getAlertList(result.alert)
);
return new WeatherService.WeatherResultWrapper(weather);
} catch (Exception e) {
e.printStackTrace();
return null;
return new WeatherService.WeatherResultWrapper(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.text.TextUtils;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
Expand Down Expand Up @@ -36,15 +37,16 @@
import wangdaye.com.geometricweather.common.basic.models.weather.WindDegree;
import wangdaye.com.geometricweather.weather.json.caiyun.CaiYunForecastResult;
import wangdaye.com.geometricweather.weather.json.caiyun.CaiYunMainlyResult;
import wangdaye.com.geometricweather.weather.services.WeatherService;

public class CaiyunResultConverter {

@Nullable
public static Weather convert(Context context, Location location,
CaiYunMainlyResult mainlyResult,
CaiYunForecastResult forecastResult) {
@NonNull
public static WeatherService.WeatherResultWrapper convert(Context context, Location location,
CaiYunMainlyResult mainlyResult,
CaiYunForecastResult forecastResult) {
try {
return new Weather(
Weather weather = new Weather(
new Base(
location.getCityId(),
System.currentTimeMillis(),
Expand Down Expand Up @@ -129,15 +131,21 @@ public static Weather convert(Context context, Location location,
),
getAlertList(mainlyResult)
);
return new WeatherService.WeatherResultWrapper(weather);
} catch (Exception e) {
e.printStackTrace();
return null;
return new WeatherService.WeatherResultWrapper(null);
}
}

private static AirQuality getAirQuality(Context context, CaiYunMainlyResult result) {
String quality = CommonConverter.getAqiQuality(
context, Integer.parseInt(result.aqi.aqi));
String quality;
try {
quality = CommonConverter.getAqiQuality(
context, Integer.parseInt(result.aqi.aqi));
} catch (Exception e) {
quality = null;
}

Integer index;
try {
Expand Down Expand Up @@ -324,8 +332,12 @@ private static List<Daily> getDailyList(Context context,
new Astro(null, null),
new MoonPhase(null, null),
new AirQuality(
CommonConverter.getAqiQuality(context, forecast.aqi.value.get(i)),
forecast.aqi.value.get(i),
forecast.aqi != null && forecast.aqi.value != null && forecast.aqi.value.size() > i
? CommonConverter.getAqiQuality(context, forecast.aqi.value.get(i))
: null,
forecast.aqi != null && forecast.aqi.value != null && forecast.aqi.value.size() > i
? forecast.aqi.value.get(i)
: null,
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -44,10 +45,12 @@
import wangdaye.com.geometricweather.weather.json.mf.MfLocationResult;
import wangdaye.com.geometricweather.weather.json.mf.MfRainResult;
import wangdaye.com.geometricweather.weather.json.mf.MfWarningsResult;
import wangdaye.com.geometricweather.weather.services.WeatherService;

public class MfResultConverter {

// Result of a coordinates search
@NonNull
public static Location convert(@Nullable Location location, MfForecastV2Result result) {
if (location != null
&& !TextUtils.isEmpty(location.getProvince())
Expand Down Expand Up @@ -100,6 +103,7 @@ public static Location convert(@Nullable Location location, MfForecastV2Result r
}

// Result of a query string search
@NonNull
public static Location convert(@Nullable Location location, MfLocationResult result) {
if (location != null
&& !TextUtils.isEmpty(location.getProvince())
Expand Down Expand Up @@ -151,16 +155,17 @@ public static Location convert(@Nullable Location location, MfLocationResult res
}
}

public static Weather convert(Context context,
Location location,
MfCurrentResult currentResult,
MfForecastResult forecastResult,
MfEphemerisResult ephemerisResult,
MfRainResult rainResult,
MfWarningsResult warningsResult,
@Nullable AtmoAuraQAResult aqiAtmoAuraResult) {
@NonNull
public static WeatherService.WeatherResultWrapper convert(Context context,
Location location,
MfCurrentResult currentResult,
MfForecastResult forecastResult,
MfEphemerisResult ephemerisResult,
MfRainResult rainResult,
MfWarningsResult warningsResult,
@Nullable AtmoAuraQAResult aqiAtmoAuraResult) {
try {
return new Weather(
Weather weather = new Weather(
new Base(
location.getCityId(),
System.currentTimeMillis(),
Expand Down Expand Up @@ -223,12 +228,13 @@ public static Weather convert(Context context,
getMinutelyList(forecastResult.dailyForecasts.get(0).sun.rise, forecastResult.dailyForecasts.get(0).sun.set, rainResult),
getWarningsList(warningsResult)
);
return new WeatherService.WeatherResultWrapper(weather);
} catch (Exception ignored) {
Log.d("GEOM", ignored.getMessage());
for (StackTraceElement stackTraceElement : ignored.getStackTrace()) {
Log.d("GEOM", stackTraceElement.toString());
}
return null;
return new WeatherService.WeatherResultWrapper(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
import io.reactivex.disposables.CompositeDisposable;
import wangdaye.com.geometricweather.BuildConfig;
import wangdaye.com.geometricweather.common.basic.models.Location;
import wangdaye.com.geometricweather.common.basic.models.weather.Weather;
import wangdaye.com.geometricweather.settings.SettingsOptionManager;
import wangdaye.com.geometricweather.common.rxjava.BaseObserver;
import wangdaye.com.geometricweather.common.rxjava.ObserverContainer;
import wangdaye.com.geometricweather.common.rxjava.SchedulerTransformer;
import wangdaye.com.geometricweather.settings.SettingsOptionManager;
import wangdaye.com.geometricweather.weather.apis.AccuWeatherApi;
import wangdaye.com.geometricweather.weather.converters.AccuResultConverter;
import wangdaye.com.geometricweather.weather.json.accu.AccuAlertResult;
Expand All @@ -28,8 +29,6 @@
import wangdaye.com.geometricweather.weather.json.accu.AccuHourlyResult;
import wangdaye.com.geometricweather.weather.json.accu.AccuLocationResult;
import wangdaye.com.geometricweather.weather.json.accu.AccuMinuteResult;
import wangdaye.com.geometricweather.common.rxjava.BaseObserver;
import wangdaye.com.geometricweather.common.rxjava.ObserverContainer;

/**
* Accu weather service.
Expand Down Expand Up @@ -139,11 +138,11 @@ public void requestWeather(Context context, Location location, @NonNull RequestW
accuAlertResults
)
).compose(SchedulerTransformer.create())
.subscribe(new ObserverContainer<>(mCompositeDisposable, new BaseObserver<Weather>() {
.subscribe(new ObserverContainer<>(mCompositeDisposable, new BaseObserver<WeatherResultWrapper>() {
@Override
public void onSucceed(Weather weather) {
if (weather != null) {
location.setWeather(weather);
public void onSucceed(WeatherResultWrapper wrapper) {
if (wrapper.result != null) {
location.setWeather(wrapper.result);
callback.requestWeatherSuccess(location);
} else {
onFailed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import io.reactivex.disposables.CompositeDisposable;
import wangdaye.com.geometricweather.common.basic.models.ChineseCity;
import wangdaye.com.geometricweather.common.basic.models.Location;
import wangdaye.com.geometricweather.common.basic.models.weather.Weather;
import wangdaye.com.geometricweather.common.rxjava.BaseObserver;
import wangdaye.com.geometricweather.common.rxjava.ObserverContainer;
import wangdaye.com.geometricweather.common.rxjava.SchedulerTransformer;
import wangdaye.com.geometricweather.common.utils.LanguageUtils;
import wangdaye.com.geometricweather.db.DatabaseHelper;
import wangdaye.com.geometricweather.common.rxjava.SchedulerTransformer;
import wangdaye.com.geometricweather.weather.apis.CNWeatherApi;
import wangdaye.com.geometricweather.weather.converters.CNResultConverter;
import wangdaye.com.geometricweather.weather.json.cn.CNWeatherResult;
import wangdaye.com.geometricweather.common.rxjava.BaseObserver;
import wangdaye.com.geometricweather.common.rxjava.ObserverContainer;

/**
* CN weather service.
Expand All @@ -47,9 +46,9 @@ public void requestWeather(Context context,
.subscribe(new ObserverContainer<>(mCompositeDisposable, new BaseObserver<CNWeatherResult>() {
@Override
public void onSucceed(CNWeatherResult cnWeatherResult) {
Weather weather = CNResultConverter.convert(context, location, cnWeatherResult);
if (weather != null) {
location.setWeather(weather);
WeatherResultWrapper wrapper = CNResultConverter.convert(context, location, cnWeatherResult);
if (wrapper.result != null) {
location.setWeather(wrapper.result);
callback.requestWeatherSuccess(location);
} else {
onFailed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
import io.reactivex.disposables.CompositeDisposable;
import wangdaye.com.geometricweather.common.basic.models.ChineseCity;
import wangdaye.com.geometricweather.common.basic.models.Location;
import wangdaye.com.geometricweather.common.basic.models.weather.Weather;
import wangdaye.com.geometricweather.common.rxjava.BaseObserver;
import wangdaye.com.geometricweather.common.rxjava.ObserverContainer;
import wangdaye.com.geometricweather.common.rxjava.SchedulerTransformer;
import wangdaye.com.geometricweather.weather.apis.CNWeatherApi;
import wangdaye.com.geometricweather.weather.apis.CaiYunApi;
import wangdaye.com.geometricweather.weather.converters.CaiyunResultConverter;
import wangdaye.com.geometricweather.weather.json.caiyun.CaiYunForecastResult;
import wangdaye.com.geometricweather.weather.json.caiyun.CaiYunMainlyResult;
import wangdaye.com.geometricweather.common.rxjava.BaseObserver;
import wangdaye.com.geometricweather.common.rxjava.ObserverContainer;

/**
* CaiYun weather service.
Expand Down Expand Up @@ -68,11 +67,11 @@ public void requestWeather(Context context,
Observable.zip(mainly, forecast, (mainlyResult, forecastResult) ->
CaiyunResultConverter.convert(context, location, mainlyResult, forecastResult)
).compose(SchedulerTransformer.create())
.subscribe(new ObserverContainer<>(mCompositeDisposable, new BaseObserver<Weather>() {
.subscribe(new ObserverContainer<>(mCompositeDisposable, new BaseObserver<WeatherResultWrapper>() {
@Override
public void onSucceed(Weather weather) {
if (weather != null) {
location.setWeather(weather);
public void onSucceed(WeatherResultWrapper wrapper) {
if (wrapper.result != null) {
location.setWeather(wrapper.result);
callback.requestWeatherSuccess(location);
} else {
callback.requestWeatherFailed(location);
Expand Down
Loading

0 comments on commit 28b0405

Please sign in to comment.