Skip to content

Commit df42179

Browse files
author
CyJaySong
committed
realized life indices query.
1 parent 660c33b commit df42179

File tree

19 files changed

+437
-28
lines changed

19 files changed

+437
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.0.4
2+
3+
- update sdk.
4+
- realized life indices query.
5+
- 升级 SDK
6+
- 实现 生活指数查询
7+
18
## 0.0.3
29

310
- realized geo search.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- [x] 逐天天气查询
1919
- [x] 逐时天气查询
2020
- [x] 中国地区未来2小时内每5分钟降水查询
21+
- [x] 当天生活指数查询
22+
- [x] 三天生活指数查询
2123
- [ ] 其他功能...
2224

2325
## 运行
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.fluttercandies.flutter_qweather;
2+
3+
import android.content.Context;
4+
5+
import com.google.gson.Gson;
6+
import com.qweather.sdk.bean.IndicesBean;
7+
import com.qweather.sdk.bean.base.IndicesType;
8+
import com.qweather.sdk.bean.base.Lang;
9+
import com.qweather.sdk.view.QWeather;
10+
11+
import java.util.ArrayList;
12+
import java.util.Collections;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
import io.flutter.plugin.common.MethodChannel;
18+
19+
public class ApiIndices {
20+
/// 获取1天生活指数
21+
protected static void getIndices1Day(Context context, Object arguments, final MethodChannel.Result result) {
22+
getIndices("getIndices1Day", context, arguments, result);
23+
}
24+
25+
/// 获取3天生活指数
26+
protected static void getIndices3Day(Context context, Object arguments, final MethodChannel.Result result) {
27+
getIndices("getIndices3Day", context, arguments, result);
28+
}
29+
30+
private static void getIndices(final String name, Context context, Object arguments, final MethodChannel.Result result) {
31+
@SuppressWarnings("unchecked")
32+
HashMap<String, Object> param = (HashMap<String, Object>) arguments;
33+
String location = (String) param.get("location");
34+
@SuppressWarnings("unchecked")
35+
List<String> indicesTypes = (List<String>) param.get("indicesTypes");
36+
List<IndicesType> indicesTypesTmp = new ArrayList<>();
37+
assert indicesTypes != null;
38+
for (String type : indicesTypes) {
39+
switch (type) {
40+
case "SPT":
41+
indicesTypesTmp.add(IndicesType.SPT);
42+
break;
43+
case "CW":
44+
indicesTypesTmp.add(IndicesType.CW);
45+
break;
46+
case "DRSG":
47+
indicesTypesTmp.add(IndicesType.DRSG);
48+
break;
49+
case "FIS":
50+
indicesTypesTmp.add(IndicesType.FIS);
51+
break;
52+
case "UV":
53+
indicesTypesTmp.add(IndicesType.UV);
54+
break;
55+
case "TRAV":
56+
indicesTypesTmp.add(IndicesType.TRAV);
57+
break;
58+
case "AG":
59+
indicesTypesTmp.add(IndicesType.AG);
60+
break;
61+
case "COMF":
62+
indicesTypesTmp.add(IndicesType.COMF);
63+
break;
64+
case "FLU":
65+
indicesTypesTmp.add(IndicesType.FLU);
66+
break;
67+
case "AP":
68+
indicesTypesTmp.add(IndicesType.AP);
69+
break;
70+
case "AC":
71+
indicesTypesTmp.add(IndicesType.AC);
72+
break;
73+
case "GL":
74+
indicesTypesTmp.add(IndicesType.GL);
75+
break;
76+
case "MU":
77+
indicesTypesTmp.add(IndicesType.MU);
78+
break;
79+
case "DC":
80+
indicesTypesTmp.add(IndicesType.DC);
81+
break;
82+
case "PTFC":
83+
indicesTypesTmp.add(IndicesType.PTFC);
84+
break;
85+
case "SPI":
86+
indicesTypesTmp.add(IndicesType.SPI);
87+
break;
88+
case "SKI":
89+
indicesTypesTmp.add(IndicesType.SK);
90+
break;
91+
default:
92+
indicesTypesTmp = Collections.singletonList(IndicesType.ALL);
93+
break;
94+
}
95+
if (indicesTypesTmp.contains(IndicesType.ALL)) break;
96+
}
97+
QWeather.OnResultIndicesListener onResultIndicesListener = new QWeather.OnResultIndicesListener() {
98+
@Override
99+
public void onError(Throwable throwable) {
100+
DebugPrint.print(name + " onError: " + throwable.getLocalizedMessage());
101+
result.success(null);
102+
}
103+
104+
@Override
105+
public void onSuccess(IndicesBean indicesBean) {
106+
Gson gson = new Gson();
107+
String jsonStr = gson.toJson(indicesBean);
108+
DebugPrint.print(name + " onSuccess: " + jsonStr);
109+
result.success(gson.fromJson(jsonStr, Map.class));
110+
}
111+
};
112+
if (name.equals("getIndices1Day")) {
113+
QWeather.getIndices1D(context, location, Lang.ZH_HANS, indicesTypesTmp, onResultIndicesListener);
114+
} else {
115+
QWeather.getIndices3D(context, location, Lang.ZH_HANS, indicesTypesTmp, onResultIndicesListener);
116+
}
117+
}
118+
}

android/src/main/kotlin/com/fluttercandies/flutter_qweather/FlutterQweatherPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class FlutterQweatherPlugin : FlutterPlugin, MethodCallHandler {
3232
MethodConstants.GetWeatherDaily -> ApiWeather.getWeatherDaily(context, call.arguments, result)
3333
MethodConstants.GetWeatherHourly -> ApiWeather.getWeatherHourly(context, call.arguments, result)
3434
MethodConstants.GetWeatherMinuteLy -> ApiWeather.getWeatherMinuteLy(context, call.arguments, result)
35+
MethodConstants.GetIndices1Day -> ApiIndices.getIndices1Day(context, call.arguments, result)
36+
MethodConstants.GetIndices3Day -> ApiIndices.getIndices3Day(context, call.arguments, result)
3537
else -> result.notImplemented()
3638
}
3739
}

android/src/main/kotlin/com/fluttercandies/flutter_qweather/MethodConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ public class MethodConstants {
3232

3333
// 获取中国地区未来2小时内每5分钟降水
3434
public static final String GetWeatherMinuteLy = "GetWeatherMinuteLy";
35+
36+
// 获取1天生活指数
37+
public static final String GetIndices1Day = "GetIndices1Day";
38+
39+
// 获取3天生活指数
40+
public static final String GetIndices3Day = "GetIndices3Day";
3541
}

example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class _MyAppState extends State<MyApp> {
4343
// await Qweather.instance.setDebug();
4444
await queryWeatherNow();
4545
// FlutterQweather.instance.getWeatherMinuteLy(_location);
46-
FlutterQweather.instance.geoPoiRangeLookup('116.40000,39.88999', PoiType.scenic);
46+
// FlutterQweather.instance.geoPoiRangeLookup('116.40000,39.88999', PoiType.scenic);
47+
// FlutterQweather.instance.getIndices1Day('116.40000,39.88999',indicesTypes: {IndicesType.TRAV});
4748
}
4849

4950
// 查询实时天气

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ packages:
6868
path: ".."
6969
relative: true
7070
source: path
71-
version: "0.0.2"
71+
version: "0.0.4"
7272
flutter_test:
7373
dependency: "direct dev"
7474
description: flutter
@@ -158,4 +158,4 @@ packages:
158158
version: "2.1.0"
159159
sdks:
160160
dart: ">=2.12.0 <3.0.0"
161-
flutter: ">=2.0.0"
161+
flutter: ">=1.20.0"

ios/Classes/Api/ApiGeo.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ + (void) geoCityLookup:(id)param result:(FlutterResult)result{
1515
QWeatherConfigInstance.location = paramDic[@"location"];
1616
QWeatherConfigInstance.number = paramDic[@"number"];
1717
QWeatherConfigInstance.range = paramDic[@"range"];
18-
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_CITY_LOOKUP
19-
WithSuccess:^(GeoBaseClass *rep) {
18+
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_CITY_LOOKUP WithSuccess:^(GeoBaseClass *rep) {
2019
[DebugPrint print:[@"geoCityLookup WithSuccess: " stringByAppendingString:rep.description]];
2120
if (![rep.code isEqualToString:@"200"]){
2221
result(NULL);
@@ -46,8 +45,7 @@ + (void) getGeoTopCity:(id)param result:(FlutterResult)result{
4645
NSDictionary *paramDic = param;
4746
QWeatherConfigInstance.number = paramDic[@"number"];
4847
QWeatherConfigInstance.range = paramDic[@"range"];
49-
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_TOPCITY
50-
WithSuccess:^(GeoBaseClass *rep) {
48+
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_TOPCITY WithSuccess:^(GeoBaseClass *rep) {
5149
[DebugPrint print:[@"geoCityLookup WithSuccess: " stringByAppendingString:rep.description]];
5250
if (![rep.code isEqualToString:@"200"]){
5351
result(NULL);
@@ -78,8 +76,7 @@ + (void) geoPoiLookup:(id)param result:(FlutterResult)result{
7876
QWeatherConfigInstance.number = paramDic[@"number"];
7977
QWeatherConfigInstance.type = paramDic[@"type"];
8078
QWeatherConfigInstance.city = paramDic[@"city"];
81-
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_POI_LOOKUP
82-
WithSuccess:^(GeoBaseClass *rep) {
79+
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_POI_LOOKUP WithSuccess:^(GeoBaseClass *rep) {
8380
[DebugPrint print:[@"geoCityLookup WithSuccess: " stringByAppendingString:rep.description]];
8481
if (![rep.code isEqualToString:@"200"]){
8582
result(NULL);
@@ -110,8 +107,7 @@ + (void) geoPoiRangeLookup:(id)param result:(FlutterResult)result{
110107
QWeatherConfigInstance.radius = paramDic[@"radius"];
111108
QWeatherConfigInstance.number = paramDic[@"number"];
112109
QWeatherConfigInstance.type = paramDic[@"type"];
113-
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_POI_RANGE
114-
WithSuccess:^(GeoBaseClass *rep) {
110+
[QWeatherConfigInstance weatherWithInquireType:INQUIRE_TYPE_GEO_POI_RANGE WithSuccess:^(GeoBaseClass *rep) {
115111
[DebugPrint print:[@"geoCityLookup WithSuccess: " stringByAppendingString:rep.description]];
116112
if (![rep.code isEqualToString:@"200"]){
117113
result(NULL);

ios/Classes/Api/ApiIndices.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// ApiIndices.h
3+
// flutter_qweather
4+
//
5+
// Created by CyJay on 2021/6/5.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
#import <Flutter/Flutter.h>
10+
#import <QWeather/QWeather.h>
11+
12+
13+
@interface ApiIndices : NSObject
14+
/// 获取1天生活指数
15+
+ (void) getIndices1Day:(id)param result:(FlutterResult)result;
16+
/// 获取3天生活指数
17+
+ (void) getIndices3Day:(id)param result:(FlutterResult)result;
18+
/// 获取生活指数
19+
//+ (void) getIndices:(NSString*)name param:(id)param result:(FlutterResult)result;
20+
@end

ios/Classes/Api/ApiIndices.m

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// ApiIndices.m
3+
// flutter_qweather
4+
//
5+
// Created by CyJay on 2021/6/5.
6+
//
7+
8+
#import "ApiIndices.h"
9+
#import "../DebugPrint/DebugPrint.h"
10+
@implementation ApiIndices
11+
/// 获取1天生活指数
12+
+ (void) getIndices1Day:(id)param result:(FlutterResult)result{
13+
[ApiIndices getIndices:@"getIndices1Day" param:param result:result];
14+
}
15+
/// 获取3天生活指数
16+
+ (void) getIndices3Day:(id)param result:(FlutterResult)result{
17+
[ApiIndices getIndices:@"getIndices3Day" param:param result:result];
18+
}
19+
20+
/// 获取生活指数
21+
+ (void) getIndices:(NSString*)name param:(id)param result:(FlutterResult)result{
22+
NSDictionary *paramDic = param;
23+
QWeatherConfigInstance.location = paramDic[@"location"];
24+
NSArray<NSString*> *indicesTypes = paramDic[@"indicesTypes"];
25+
NSMutableArray<NSString*> *indicesTypesTmp = [NSMutableArray new];
26+
for (int i = 0; i < indicesTypes.count; i++){
27+
NSString *str = [indicesTypes objectAtIndex:i];
28+
if ([str isEqualToString:@"SPT"]){
29+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_spt]];
30+
} else if ([str isEqualToString:@"CW"]){
31+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_cw]];
32+
} else if ([str isEqualToString:@"DRSG"]){
33+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_drsg]];
34+
} else if ([str isEqualToString:@"FIS"]){
35+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_fis]];
36+
} else if ([str isEqualToString:@"UV"]){
37+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_uv]];
38+
} else if ([str isEqualToString:@"TRAV"]){
39+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_trav]];
40+
} else if ([str isEqualToString:@"AG"]){
41+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ag]];
42+
} else if ([str isEqualToString:@"COMF"]){
43+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_comf]];
44+
} else if ([str isEqualToString:@"FLU"]){
45+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_flu]];
46+
} else if ([str isEqualToString:@"AP"]){
47+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ap]];
48+
} else if ([str isEqualToString:@"AC"]){
49+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ac]];
50+
} else if ([str isEqualToString:@"GL"]){
51+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_gl]];
52+
} else if ([str isEqualToString:@"MU"]){
53+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_mu]];
54+
} else if ([str isEqualToString:@"DC"]){
55+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_dc]];
56+
} else if ([str isEqualToString:@"PTEC"]){
57+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ptfc]];
58+
} else if ([str isEqualToString:@"SPI"]){
59+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_spi]];
60+
} else if ([str isEqualToString:@"SKI"]){
61+
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ski]];
62+
} else {
63+
indicesTypesTmp = [NSMutableArray arrayWithObject:INDICES_TYPESTRING[INDICES_TYPE_all]];
64+
break;
65+
}
66+
}
67+
QWeatherConfigInstance.indices = indicesTypesTmp;
68+
INQUIRE_TYPE inquireType = INQUIRE_TYPE_INDICES_1D;
69+
if ([name isEqualToString:@"getIndices3Day"]){
70+
inquireType = INQUIRE_TYPE_INDICES_3D;
71+
}
72+
[QWeatherConfigInstance weatherWithInquireType:inquireType WithSuccess:^(IndicesBaseClass *rep) {
73+
[DebugPrint print:[name stringByAppendingString:[@" WithSuccess: " stringByAppendingString:rep.description]]];
74+
if (![rep.code isEqualToString:@"200"]){
75+
result(NULL);
76+
return;
77+
}
78+
NSMutableArray<NSDictionary*> *dailyList = [NSMutableArray new];
79+
for (IndicesDaily *one in rep.daily) {
80+
NSDictionary *oneIndicesDaily = @{@"date": one.date, @"type": one.type, @"name":one.name,
81+
@"level":one.level, @"category": one.category, @"text": one.text};
82+
[dailyList addObject:oneIndicesDaily];
83+
}
84+
NSDictionary *refer = @{@"licenseList": rep.refer.license, @"sourcesList": rep.refer.sources};
85+
NSDictionary *basic = @{@"fxLink": rep.fxLink, @"updateTime": rep.updateTime};
86+
NSMutableDictionary *dic = [NSMutableDictionary new];
87+
[dic setValue:rep.code forKey:@"code"];
88+
[dic setValue:refer forKey:@"refer"];
89+
[dic setValue:basic forKey:@"basic"];
90+
[dic setValue:dailyList forKey:@"dailyList"];
91+
result(dic);
92+
} faileureForError:^(NSError *error) {
93+
[DebugPrint print:[name stringByAppendingString:[@" faileureForError: " stringByAppendingString:error.localizedDescription]]];
94+
result(NULL);
95+
}];
96+
}
97+
@end

0 commit comments

Comments
 (0)