-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
437 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
## 0.0.4 | ||
|
||
- update sdk. | ||
- realized life indices query. | ||
- 升级 SDK | ||
- 实现 生活指数查询 | ||
|
||
## 0.0.3 | ||
|
||
- realized geo search. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
android/src/main/kotlin/com/fluttercandies/flutter_qweather/ApiIndices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.fluttercandies.flutter_qweather; | ||
|
||
import android.content.Context; | ||
|
||
import com.google.gson.Gson; | ||
import com.qweather.sdk.bean.IndicesBean; | ||
import com.qweather.sdk.bean.base.IndicesType; | ||
import com.qweather.sdk.bean.base.Lang; | ||
import com.qweather.sdk.view.QWeather; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
public class ApiIndices { | ||
/// 获取1天生活指数 | ||
protected static void getIndices1Day(Context context, Object arguments, final MethodChannel.Result result) { | ||
getIndices("getIndices1Day", context, arguments, result); | ||
} | ||
|
||
/// 获取3天生活指数 | ||
protected static void getIndices3Day(Context context, Object arguments, final MethodChannel.Result result) { | ||
getIndices("getIndices3Day", context, arguments, result); | ||
} | ||
|
||
private static void getIndices(final String name, Context context, Object arguments, final MethodChannel.Result result) { | ||
@SuppressWarnings("unchecked") | ||
HashMap<String, Object> param = (HashMap<String, Object>) arguments; | ||
String location = (String) param.get("location"); | ||
@SuppressWarnings("unchecked") | ||
List<String> indicesTypes = (List<String>) param.get("indicesTypes"); | ||
List<IndicesType> indicesTypesTmp = new ArrayList<>(); | ||
assert indicesTypes != null; | ||
for (String type : indicesTypes) { | ||
switch (type) { | ||
case "SPT": | ||
indicesTypesTmp.add(IndicesType.SPT); | ||
break; | ||
case "CW": | ||
indicesTypesTmp.add(IndicesType.CW); | ||
break; | ||
case "DRSG": | ||
indicesTypesTmp.add(IndicesType.DRSG); | ||
break; | ||
case "FIS": | ||
indicesTypesTmp.add(IndicesType.FIS); | ||
break; | ||
case "UV": | ||
indicesTypesTmp.add(IndicesType.UV); | ||
break; | ||
case "TRAV": | ||
indicesTypesTmp.add(IndicesType.TRAV); | ||
break; | ||
case "AG": | ||
indicesTypesTmp.add(IndicesType.AG); | ||
break; | ||
case "COMF": | ||
indicesTypesTmp.add(IndicesType.COMF); | ||
break; | ||
case "FLU": | ||
indicesTypesTmp.add(IndicesType.FLU); | ||
break; | ||
case "AP": | ||
indicesTypesTmp.add(IndicesType.AP); | ||
break; | ||
case "AC": | ||
indicesTypesTmp.add(IndicesType.AC); | ||
break; | ||
case "GL": | ||
indicesTypesTmp.add(IndicesType.GL); | ||
break; | ||
case "MU": | ||
indicesTypesTmp.add(IndicesType.MU); | ||
break; | ||
case "DC": | ||
indicesTypesTmp.add(IndicesType.DC); | ||
break; | ||
case "PTFC": | ||
indicesTypesTmp.add(IndicesType.PTFC); | ||
break; | ||
case "SPI": | ||
indicesTypesTmp.add(IndicesType.SPI); | ||
break; | ||
case "SKI": | ||
indicesTypesTmp.add(IndicesType.SK); | ||
break; | ||
default: | ||
indicesTypesTmp = Collections.singletonList(IndicesType.ALL); | ||
break; | ||
} | ||
if (indicesTypesTmp.contains(IndicesType.ALL)) break; | ||
} | ||
QWeather.OnResultIndicesListener onResultIndicesListener = new QWeather.OnResultIndicesListener() { | ||
@Override | ||
public void onError(Throwable throwable) { | ||
DebugPrint.print(name + " onError: " + throwable.getLocalizedMessage()); | ||
result.success(null); | ||
} | ||
|
||
@Override | ||
public void onSuccess(IndicesBean indicesBean) { | ||
Gson gson = new Gson(); | ||
String jsonStr = gson.toJson(indicesBean); | ||
DebugPrint.print(name + " onSuccess: " + jsonStr); | ||
result.success(gson.fromJson(jsonStr, Map.class)); | ||
} | ||
}; | ||
if (name.equals("getIndices1Day")) { | ||
QWeather.getIndices1D(context, location, Lang.ZH_HANS, indicesTypesTmp, onResultIndicesListener); | ||
} else { | ||
QWeather.getIndices3D(context, location, Lang.ZH_HANS, indicesTypesTmp, onResultIndicesListener); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// ApiIndices.h | ||
// flutter_qweather | ||
// | ||
// Created by CyJay on 2021/6/5. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <Flutter/Flutter.h> | ||
#import <QWeather/QWeather.h> | ||
|
||
|
||
@interface ApiIndices : NSObject | ||
/// 获取1天生活指数 | ||
+ (void) getIndices1Day:(id)param result:(FlutterResult)result; | ||
/// 获取3天生活指数 | ||
+ (void) getIndices3Day:(id)param result:(FlutterResult)result; | ||
/// 获取生活指数 | ||
//+ (void) getIndices:(NSString*)name param:(id)param result:(FlutterResult)result; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// ApiIndices.m | ||
// flutter_qweather | ||
// | ||
// Created by CyJay on 2021/6/5. | ||
// | ||
|
||
#import "ApiIndices.h" | ||
#import "../DebugPrint/DebugPrint.h" | ||
@implementation ApiIndices | ||
/// 获取1天生活指数 | ||
+ (void) getIndices1Day:(id)param result:(FlutterResult)result{ | ||
[ApiIndices getIndices:@"getIndices1Day" param:param result:result]; | ||
} | ||
/// 获取3天生活指数 | ||
+ (void) getIndices3Day:(id)param result:(FlutterResult)result{ | ||
[ApiIndices getIndices:@"getIndices3Day" param:param result:result]; | ||
} | ||
|
||
/// 获取生活指数 | ||
+ (void) getIndices:(NSString*)name param:(id)param result:(FlutterResult)result{ | ||
NSDictionary *paramDic = param; | ||
QWeatherConfigInstance.location = paramDic[@"location"]; | ||
NSArray<NSString*> *indicesTypes = paramDic[@"indicesTypes"]; | ||
NSMutableArray<NSString*> *indicesTypesTmp = [NSMutableArray new]; | ||
for (int i = 0; i < indicesTypes.count; i++){ | ||
NSString *str = [indicesTypes objectAtIndex:i]; | ||
if ([str isEqualToString:@"SPT"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_spt]]; | ||
} else if ([str isEqualToString:@"CW"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_cw]]; | ||
} else if ([str isEqualToString:@"DRSG"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_drsg]]; | ||
} else if ([str isEqualToString:@"FIS"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_fis]]; | ||
} else if ([str isEqualToString:@"UV"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_uv]]; | ||
} else if ([str isEqualToString:@"TRAV"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_trav]]; | ||
} else if ([str isEqualToString:@"AG"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ag]]; | ||
} else if ([str isEqualToString:@"COMF"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_comf]]; | ||
} else if ([str isEqualToString:@"FLU"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_flu]]; | ||
} else if ([str isEqualToString:@"AP"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ap]]; | ||
} else if ([str isEqualToString:@"AC"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ac]]; | ||
} else if ([str isEqualToString:@"GL"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_gl]]; | ||
} else if ([str isEqualToString:@"MU"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_mu]]; | ||
} else if ([str isEqualToString:@"DC"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_dc]]; | ||
} else if ([str isEqualToString:@"PTEC"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ptfc]]; | ||
} else if ([str isEqualToString:@"SPI"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_spi]]; | ||
} else if ([str isEqualToString:@"SKI"]){ | ||
[indicesTypesTmp addObject: INDICES_TYPESTRING[INDICES_TYPE_ski]]; | ||
} else { | ||
indicesTypesTmp = [NSMutableArray arrayWithObject:INDICES_TYPESTRING[INDICES_TYPE_all]]; | ||
break; | ||
} | ||
} | ||
QWeatherConfigInstance.indices = indicesTypesTmp; | ||
INQUIRE_TYPE inquireType = INQUIRE_TYPE_INDICES_1D; | ||
if ([name isEqualToString:@"getIndices3Day"]){ | ||
inquireType = INQUIRE_TYPE_INDICES_3D; | ||
} | ||
[QWeatherConfigInstance weatherWithInquireType:inquireType WithSuccess:^(IndicesBaseClass *rep) { | ||
[DebugPrint print:[name stringByAppendingString:[@" WithSuccess: " stringByAppendingString:rep.description]]]; | ||
if (![rep.code isEqualToString:@"200"]){ | ||
result(NULL); | ||
return; | ||
} | ||
NSMutableArray<NSDictionary*> *dailyList = [NSMutableArray new]; | ||
for (IndicesDaily *one in rep.daily) { | ||
NSDictionary *oneIndicesDaily = @{@"date": one.date, @"type": one.type, @"name":one.name, | ||
@"level":one.level, @"category": one.category, @"text": one.text}; | ||
[dailyList addObject:oneIndicesDaily]; | ||
} | ||
NSDictionary *refer = @{@"licenseList": rep.refer.license, @"sourcesList": rep.refer.sources}; | ||
NSDictionary *basic = @{@"fxLink": rep.fxLink, @"updateTime": rep.updateTime}; | ||
NSMutableDictionary *dic = [NSMutableDictionary new]; | ||
[dic setValue:rep.code forKey:@"code"]; | ||
[dic setValue:refer forKey:@"refer"]; | ||
[dic setValue:basic forKey:@"basic"]; | ||
[dic setValue:dailyList forKey:@"dailyList"]; | ||
result(dic); | ||
} faileureForError:^(NSError *error) { | ||
[DebugPrint print:[name stringByAppendingString:[@" faileureForError: " stringByAppendingString:error.localizedDescription]]]; | ||
result(NULL); | ||
}]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.