Integration setting improvement
This commit is contained in:
parent
283ae6cfd4
commit
44165993b4
@ -143,6 +143,7 @@ void updateDeviceLocationIsolate() {
|
|||||||
//print("[Background $backgroundTask] Getting device location...");
|
//print("[Background $backgroundTask] Getting device location...");
|
||||||
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
|
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
|
||||||
//print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}");
|
//print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}");
|
||||||
|
if (location != null) {
|
||||||
data["data"]["gps"] = [location.latitude, location.longitude];
|
data["data"]["gps"] = [location.latitude, location.longitude];
|
||||||
data["data"]["gps_accuracy"] = location.accuracy;
|
data["data"]["gps_accuracy"] = location.accuracy;
|
||||||
//print("[Background $backgroundTask] Sending data home...");
|
//print("[Background $backgroundTask] Sending data home...");
|
||||||
@ -151,10 +152,12 @@ void updateDeviceLocationIsolate() {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
body: json.encode(data)
|
body: json.encode(data)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
//print("[Background $backgroundTask] Error getting current location: ${e.toString()}. Trying last known...");
|
//print("[Background $backgroundTask] Error getting current location: ${e.toString()}. Trying last known...");
|
||||||
Geolocator().getLastKnownPosition(desiredAccuracy: LocationAccuracy.medium).then((location){
|
Geolocator().getLastKnownPosition(desiredAccuracy: LocationAccuracy.medium).then((location){
|
||||||
//print("[Background $backgroundTask] Got last known location: ${location.latitude} ${location.longitude}");
|
//print("[Background $backgroundTask] Got last known location: ${location.latitude} ${location.longitude}");
|
||||||
|
if (location != null) {
|
||||||
data["data"]["gps"] = [location.latitude, location.longitude];
|
data["data"]["gps"] = [location.latitude, location.longitude];
|
||||||
data["data"]["gps_accuracy"] = location.accuracy;
|
data["data"]["gps_accuracy"] = location.accuracy;
|
||||||
//print("[Background $backgroundTask] Sending data home...");
|
//print("[Background $backgroundTask] Sending data home...");
|
||||||
@ -163,6 +166,7 @@ void updateDeviceLocationIsolate() {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
body: json.encode(data)
|
body: json.encode(data)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -89,6 +89,16 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_switchLocationTrackingState(bool state) async {
|
||||||
|
if (state) {
|
||||||
|
await LocationManager().updateDeviceLocation();
|
||||||
|
}
|
||||||
|
await LocationManager().setSettings(_locationTrackingEnabled, _locationInterval);
|
||||||
|
setState(() {
|
||||||
|
_wait = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
@ -114,11 +124,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
_locationTrackingEnabled = value;
|
_locationTrackingEnabled = value;
|
||||||
_wait = true;
|
_wait = true;
|
||||||
});
|
});
|
||||||
LocationManager().setSettings(_locationTrackingEnabled, _locationInterval).then((_){
|
_switchLocationTrackingState(value);
|
||||||
setState(() {
|
|
||||||
_wait = false;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -132,19 +138,19 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
//Expanded(child: Container(),),
|
//Expanded(child: Container(),),
|
||||||
FlatButton(
|
FlatButton(
|
||||||
padding: EdgeInsets.all(0.0),
|
padding: EdgeInsets.all(0.0),
|
||||||
child: Text("+", style: TextStyle(fontSize: Sizes.largeFontSize)),
|
child: Text("-", style: TextStyle(fontSize: Sizes.largeFontSize)),
|
||||||
onPressed: () => incLocationInterval(),
|
onPressed: () => decLocationInterval(),
|
||||||
),
|
),
|
||||||
Text("$_locationInterval", style: TextStyle(fontSize: Sizes.largeFontSize)),
|
Text("$_locationInterval", style: TextStyle(fontSize: Sizes.largeFontSize)),
|
||||||
FlatButton(
|
FlatButton(
|
||||||
padding: EdgeInsets.all(0.0),
|
padding: EdgeInsets.all(0.0),
|
||||||
child: Text("-", style: TextStyle(fontSize: Sizes.largeFontSize)),
|
child: Text("+", style: TextStyle(fontSize: Sizes.largeFontSize)),
|
||||||
onPressed: () => decLocationInterval(),
|
onPressed: () => incLocationInterval(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
Text("Registration", style: TextStyle(fontSize: Sizes.largeFontSize-2)),
|
Text("Integration status", style: TextStyle(fontSize: Sizes.largeFontSize-2)),
|
||||||
Container(height: Sizes.rowPadding,),
|
Container(height: Sizes.rowPadding,),
|
||||||
Text("${HomeAssistant().userName}'s ${DeviceInfoManager().model}, ${DeviceInfoManager().osName} ${DeviceInfoManager().osVersion}"),
|
Text("${HomeAssistant().userName}'s ${DeviceInfoManager().model}, ${DeviceInfoManager().osName} ${DeviceInfoManager().osVersion}"),
|
||||||
Container(height: 6.0,),
|
Container(height: 6.0,),
|
||||||
@ -156,13 +162,13 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
RaisedButton(
|
RaisedButton(
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
onPressed: () => updateRegistration(),
|
onPressed: () => updateRegistration(),
|
||||||
child: Text("Check registration", style: TextStyle(color: Colors.white))
|
child: Text("Check integration", style: TextStyle(color: Colors.white))
|
||||||
),
|
),
|
||||||
Container(width: 10.0,),
|
Container(width: 10.0,),
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
color: Colors.redAccent,
|
color: Colors.redAccent,
|
||||||
onPressed: () => resetRegistration(),
|
onPressed: () => resetRegistration(),
|
||||||
child: Text("Reset registration", style: TextStyle(color: Colors.white))
|
child: Text("Reset integration", style: TextStyle(color: Colors.white))
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user