feat: 增加壁纸显示,增加天气事件分发,增加HotSeat

This commit is contained in:
2026-05-09 11:27:56 +08:00
parent 59539d048d
commit da83e852e0
55 changed files with 1776 additions and 419 deletions

View File

@@ -11,6 +11,7 @@ import com.qweather.sdk.QWeather;
import com.qweather.sdk.basic.Lang;
import com.qweather.sdk.basic.Unit;
import com.qweather.sdk.parameter.weather.WeatherParameter;
import com.qweather.sdk.response.error.ErrorResponse;
import com.qweather.sdk.response.weather.WeatherDailyResponse;
import com.qweather.sdk.response.weather.WeatherHourlyResponse;
import com.qweather.sdk.response.weather.WeatherNowResponse;
@@ -33,6 +34,10 @@ import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.GlobalScope;
public class WeatherManager {
private static final String TAG = "WeatherManager";
@@ -44,10 +49,11 @@ public class WeatherManager {
private Map<String, String> LocationIDMap = new HashMap<>();
private boolean loadCsvFinish = false;
private String mAdCode;
private WeatherUpdateManager weatherUpdateManager;
private WeatherManager(Context context) {
this.mContext = context.getApplicationContext();
weatherUpdateManager = WeatherUpdateManager.Companion.getInstance();
initCsv();
try {
// 通过SDK提供的JWTGenerator设置令牌生成器其实现自TokenGenerator接口
@@ -155,7 +161,30 @@ public class WeatherManager {
WeatherParameter parameter = new WeatherParameter(locationID)
.lang(Lang.ZH_HANS)
.unit(Unit.METRIC);
mQWeather.weatherNow(parameter, callback);
mQWeather.weatherNow(parameter, new Callback<WeatherNowResponse>() {
@Override
public void onSuccess(WeatherNowResponse weatherNowResponse) {
Logger.e(TAG, "getWeatherNow", "onSuccess: " + weatherNowResponse);
weatherUpdateManager.publishWeatherNowUpdate(weatherNowResponse);
if (callback != null) {
callback.onSuccess(weatherNowResponse);
}
}
@Override
public void onFailure(ErrorResponse errorResponse) {
if (callback != null) {
callback.onFailure(errorResponse);
}
}
@Override
public void onException(Throwable throwable) {
if (callback != null) {
callback.onException(throwable);
}
}
});
}
public void getWeather24h(String adCode, Callback<WeatherHourlyResponse> callback) {
@@ -164,7 +193,30 @@ public class WeatherManager {
WeatherParameter parameter = new WeatherParameter(locationID)
.lang(Lang.ZH_HANS)
.unit(Unit.METRIC);
mQWeather.weather24h(parameter, callback);
mQWeather.weather24h(parameter, new Callback<WeatherHourlyResponse>() {
@Override
public void onSuccess(WeatherHourlyResponse weatherHourlyResponse) {
Logger.e(TAG, "getWeather24h", "onSuccess: " + weatherHourlyResponse);
weatherUpdateManager.publishWeatherHourlyUpdate(weatherHourlyResponse);
if (callback != null) {
callback.onSuccess(weatherHourlyResponse);
}
}
@Override
public void onFailure(ErrorResponse errorResponse) {
if (callback != null) {
callback.onFailure(errorResponse);
}
}
@Override
public void onException(Throwable throwable) {
if (callback != null) {
callback.onException(throwable);
}
}
});
}
public void getWeather10D(String adCode, Callback<WeatherDailyResponse> callback) {
@@ -173,7 +225,30 @@ public class WeatherManager {
WeatherParameter parameter = new WeatherParameter(locationID)
.lang(Lang.ZH_HANS)
.unit(Unit.METRIC);
mQWeather.weather10d(parameter, callback);
mQWeather.weather10d(parameter, new Callback<WeatherDailyResponse>() {
@Override
public void onSuccess(WeatherDailyResponse weatherDailyResponse) {
Logger.e(TAG, "getWeather10D", "onSuccess: " + weatherDailyResponse);
weatherUpdateManager.publishWeatherDailyUpdate(weatherDailyResponse);
if (callback != null) {
callback.onSuccess(weatherDailyResponse);
}
}
@Override
public void onFailure(ErrorResponse errorResponse) {
if (callback != null) {
callback.onFailure(errorResponse);
}
}
@Override
public void onException(Throwable throwable) {
if (callback != null) {
callback.onException(throwable);
}
}
});
}