feat: 增加联系人增删改查

This commit is contained in:
2026-05-19 11:40:50 +08:00
parent da83e852e0
commit c878c307b3
1129 changed files with 10342 additions and 2682 deletions

View File

@@ -15,9 +15,11 @@ 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;
import com.tencent.mmkv.MMKV;
import com.ttstd.dialer.BuildConfig;
import com.ttstd.dialer.bean.CityInfo;
import com.ttstd.dialer.config.CommonConfig;
import com.ttstd.dialer.gson.GsonUtils;
import com.ttstd.dialer.utils.Logger;
import com.ttstd.dialer.utils.NativeUtils;
@@ -34,26 +36,30 @@ 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";
private static final String WEATHER_NOW_CACHE = "weather_now_cache_key";
private static final String WEATHER_24_HOUR_CACHE = "weather_24_hour_cache";
private static final String WEATHER_10_DAY_CACHE = "weather_10_day_cache";
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
@SuppressLint("StaticFieldLeak")
private static WeatherManager INSTANCE;
private static volatile WeatherManager INSTANCE;
private Context mContext;
private QWeather mQWeather;
private Map<String, String> LocationIDMap = new HashMap<>();
private boolean loadCsvFinish = false;
private String mAdCode;
private WeatherUpdateManager weatherUpdateManager;
private String mLocationId;
private WeatherUpdateManager mWeatherUpdateManager;
private WeatherManager(Context context) {
this.mContext = context.getApplicationContext();
weatherUpdateManager = WeatherUpdateManager.Companion.getInstance();
mWeatherUpdateManager = WeatherUpdateManager.Companion.getInstance();
mAdCode = mMMKV.decodeString(CommonConfig.CURRENT_LOCATION_AD_CODE_KEY, "");
initCsv();
try {
// 通过SDK提供的JWTGenerator设置令牌生成器其实现自TokenGenerator接口
@@ -67,11 +73,29 @@ public class WeatherManager {
Logger.e(TAG, "QWeatherUtils: " + e.getMessage());
e.printStackTrace();
}
WeatherNowResponse weatherNowResponse = getWeatherNowCache();
if (weatherNowResponse != null) {
mWeatherUpdateManager.publishWeatherNowUpdate(weatherNowResponse);
}
WeatherHourlyResponse weatherHourlyResponse = getWeather24hCache();
if (weatherHourlyResponse != null) {
mWeatherUpdateManager.publishWeatherHourlyUpdate(weatherHourlyResponse);
}
WeatherDailyResponse weatherDailyResponse = getWeather10DCache();
if (weatherDailyResponse != null) {
mWeatherUpdateManager.publishWeatherDailyUpdate(weatherDailyResponse);
}
}
public static void init(Context context) {
if (INSTANCE == null) {
INSTANCE = new WeatherManager(context);
synchronized (WeatherManager.class) {
if (INSTANCE == null) {
INSTANCE = new WeatherManager(context);
}
}
}
}
@@ -98,16 +122,20 @@ public class WeatherManager {
}
}
public String getAdCode() {
return mAdCode;
}
private void initCsv() {
Observable.create(new ObservableOnSubscribe<List<CityInfo>>() {
@Override
public void subscribe(@NonNull ObservableEmitter<List<CityInfo>> emitter) throws Throwable {
long time = System.currentTimeMillis();
List<CityInfo> cityInfos = CsvDeserializer.deserializeFromAssets(mContext, "China-City-List-latest.csv");
Logger.e(TAG, "subscribe: deserializeFromAssets time = " + (System.currentTimeMillis() - time) + "ms");
emitter.onNext(cityInfos);
}
})
@Override
public void subscribe(@NonNull ObservableEmitter<List<CityInfo>> emitter) throws Throwable {
long time = System.currentTimeMillis();
List<CityInfo> cityInfos = CsvDeserializer.deserializeFromAssets(mContext, "China-City-List-latest.csv");
Logger.e(TAG, "subscribe: deserializeFromAssets time = " + (System.currentTimeMillis() - time) + "ms");
emitter.onNext(cityInfos);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<List<CityInfo>>() {
@@ -155,9 +183,19 @@ public class WeatherManager {
return "";
}
public void getWeatherNow(String adCode, Callback<WeatherNowResponse> callback) {
public void refreshweather() {
if (!TextUtils.isEmpty(mAdCode)) {
}
}
public void getWeatherNowAdCode(String adCode, Callback<WeatherNowResponse> callback) {
String locationID = getLocationID(adCode);
Logger.e(TAG, "getWeatherNow: locationID = " + locationID);
Logger.e(TAG, "getWeatherNowAdCode: locationID = " + locationID);
getWeatherNow(locationID, callback);
}
public void getWeatherNow(String locationID, Callback<WeatherNowResponse> callback) {
WeatherParameter parameter = new WeatherParameter(locationID)
.lang(Lang.ZH_HANS)
.unit(Unit.METRIC);
@@ -165,7 +203,9 @@ public class WeatherManager {
@Override
public void onSuccess(WeatherNowResponse weatherNowResponse) {
Logger.e(TAG, "getWeatherNow", "onSuccess: " + weatherNowResponse);
weatherUpdateManager.publishWeatherNowUpdate(weatherNowResponse);
mWeatherUpdateManager.publishWeatherNowUpdate(weatherNowResponse);
mMMKV.encode(WEATHER_NOW_CACHE, GsonUtils.toJSONString(weatherNowResponse));
if (callback != null) {
callback.onSuccess(weatherNowResponse);
}
@@ -187,17 +227,23 @@ public class WeatherManager {
});
}
public void getWeather24h(String adCode, Callback<WeatherHourlyResponse> callback) {
public void getWeather24HourAdCode(String adCode, Callback<WeatherHourlyResponse> callback) {
String locationID = getLocationID(adCode);
Logger.e(TAG, "getWeatherNow: locationID = " + locationID);
Logger.e(TAG, "getWeather24HourAdCode: locationID = " + locationID);
getWeather24Hour(locationID, callback);
}
public void getWeather24Hour(String locationID, Callback<WeatherHourlyResponse> callback) {
WeatherParameter parameter = new WeatherParameter(locationID)
.lang(Lang.ZH_HANS)
.unit(Unit.METRIC);
mQWeather.weather24h(parameter, new Callback<WeatherHourlyResponse>() {
@Override
public void onSuccess(WeatherHourlyResponse weatherHourlyResponse) {
Logger.e(TAG, "getWeather24h", "onSuccess: " + weatherHourlyResponse);
weatherUpdateManager.publishWeatherHourlyUpdate(weatherHourlyResponse);
Logger.e(TAG, "getWeather24Hour", "onSuccess: " + weatherHourlyResponse);
mWeatherUpdateManager.publishWeatherHourlyUpdate(weatherHourlyResponse);
mMMKV.encode(WEATHER_24_HOUR_CACHE, GsonUtils.toJSONString(weatherHourlyResponse));
if (callback != null) {
callback.onSuccess(weatherHourlyResponse);
}
@@ -219,17 +265,23 @@ public class WeatherManager {
});
}
public void getWeather10D(String adCode, Callback<WeatherDailyResponse> callback) {
public void getWeather10DayAdCode(String adCode, Callback<WeatherDailyResponse> callback) {
String locationID = getLocationID(adCode);
Logger.e(TAG, "getWeather10D: locationID = " + locationID);
Logger.e(TAG, "getWeather10Day: locationID = " + locationID);
getWeather10Day(locationID, callback);
}
public void getWeather10Day(String locationID, Callback<WeatherDailyResponse> callback) {
WeatherParameter parameter = new WeatherParameter(locationID)
.lang(Lang.ZH_HANS)
.unit(Unit.METRIC);
mQWeather.weather10d(parameter, new Callback<WeatherDailyResponse>() {
@Override
public void onSuccess(WeatherDailyResponse weatherDailyResponse) {
Logger.e(TAG, "getWeather10D", "onSuccess: " + weatherDailyResponse);
weatherUpdateManager.publishWeatherDailyUpdate(weatherDailyResponse);
Logger.e(TAG, "getWeather10Day", "onSuccess: " + weatherDailyResponse);
mWeatherUpdateManager.publishWeatherDailyUpdate(weatherDailyResponse);
mMMKV.encode(WEATHER_10_DAY_CACHE, GsonUtils.toJSONString(weatherDailyResponse));
if (callback != null) {
callback.onSuccess(weatherDailyResponse);
}
@@ -251,5 +303,28 @@ public class WeatherManager {
});
}
public WeatherNowResponse getWeatherNowCache() {
String weatherNowCache = mMMKV.decodeString(WEATHER_NOW_CACHE);
if (!TextUtils.isEmpty(weatherNowCache)) {
return GsonUtils.toJavaObject(weatherNowCache, WeatherNowResponse.class);
}
return null;
}
public WeatherHourlyResponse getWeather24hCache() {
String weather24hCache = mMMKV.decodeString(WEATHER_24_HOUR_CACHE);
if (!TextUtils.isEmpty(weather24hCache)) {
return GsonUtils.toJavaObject(weather24hCache, WeatherHourlyResponse.class);
}
return null;
}
public WeatherDailyResponse getWeather10DCache() {
String weather10DCache = mMMKV.decodeString(WEATHER_10_DAY_CACHE);
if (!TextUtils.isEmpty(weather10DCache)) {
return GsonUtils.toJavaObject(weather10DCache, WeatherDailyResponse.class);
}
return null;
}
}