mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
Fix mqtt delete issue + show config if no config + update device etc
This commit is contained in:
parent
5a6624531f
commit
f95b0832b8
@ -18,7 +18,8 @@ class MQTTHelper {
|
|||||||
void onConnected(dynamic appContext) {
|
void onConnected(dynamic appContext) {
|
||||||
print('Connected !!!!!!!!!!!! ----------------------------------');
|
print('Connected !!!!!!!!!!!! ----------------------------------');
|
||||||
TabletAppContext tabletAppContext = appContext.getContext();
|
TabletAppContext tabletAppContext = appContext.getContext();
|
||||||
tabletAppContext.clientMQTT.updates.listen((List<MqttReceivedMessage<MqttMessage>> c) {
|
|
||||||
|
tabletAppContext.clientMQTT.updates.listen((List<MqttReceivedMessage<MqttMessage>> c) async {
|
||||||
final MqttPublishMessage message = c[0].payload;
|
final MqttPublishMessage message = c[0].payload;
|
||||||
final payload = MqttPublishPayload.bytesToStringAsString(message.payload.message);
|
final payload = MqttPublishPayload.bytesToStringAsString(message.payload.message);
|
||||||
print('Received message:$payload from topic: ${c[0].topic}');
|
print('Received message:$payload from topic: ${c[0].topic}');
|
||||||
@ -31,20 +32,37 @@ class MQTTHelper {
|
|||||||
var configId = c[0].topic.split('/')[1];
|
var configId = c[0].topic.split('/')[1];
|
||||||
if (configId != null) {
|
if (configId != null) {
|
||||||
// Check if tablet config
|
// Check if tablet config
|
||||||
|
print("Check if tablet config");
|
||||||
|
print(tabletAppContext.configuration);
|
||||||
|
if (tabletAppContext.configuration != null) {
|
||||||
if (tabletAppContext.configuration.id == configId) {
|
if (tabletAppContext.configuration.id == configId) {
|
||||||
// refresh config
|
// refresh config
|
||||||
try {
|
try {
|
||||||
PlayerMessageDTO playerMessage = PlayerMessageDTO.fromJson(jsonDecode(payload));
|
PlayerMessageDTO playerMessage = PlayerMessageDTO.fromJson(jsonDecode(payload));
|
||||||
var isConfigChanged = playerMessage.configChanged != null ? playerMessage.configChanged : false;
|
var isConfigChanged = playerMessage.configChanged != null ? playerMessage.configChanged : false;
|
||||||
|
var isDeleted = playerMessage.isDeleted != null ? playerMessage.isDeleted : false;
|
||||||
|
print(isDeleted);
|
||||||
|
if (isDeleted) {
|
||||||
|
// Clear all
|
||||||
|
print("isDeleted");
|
||||||
|
tabletAppContext.configuration = null;
|
||||||
|
appContext.setContext(tabletAppContext);
|
||||||
|
// UPDATE IT LOCALLY (SQLite)
|
||||||
|
await DatabaseHelper.instance.update(tabletAppContext);
|
||||||
|
|
||||||
|
} else {
|
||||||
if (isConfigChanged) {
|
if (isConfigChanged) {
|
||||||
updateConfig(appContext);
|
updateConfig(appContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
print('Error = $e');
|
print('Error = $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "player":
|
case "player":
|
||||||
print('Get message in topic player = $payload');
|
print('Get message in topic player = $payload');
|
||||||
|
|||||||
@ -39,6 +39,6 @@ class TabletAppContext with ChangeNotifier{
|
|||||||
// Implement toString to make it easier to see information about
|
// Implement toString to make it easier to see information about
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TabletAppContext{id: $id, deviceId: $deviceId, selectedConfiguration: $configuration, language: $language, host: $host}';
|
return 'TabletAppContext{id: $id, deviceId: $deviceId, configuration: $configuration, language: $language, host: $host}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,6 +9,7 @@ import 'package:tablet_app/Components/Buttons/rounded_button.dart';
|
|||||||
import 'package:tablet_app/Components/loading.dart';
|
import 'package:tablet_app/Components/loading.dart';
|
||||||
import 'package:tablet_app/Components/rounded_input_field.dart';
|
import 'package:tablet_app/Components/rounded_input_field.dart';
|
||||||
import 'package:tablet_app/Helpers/DatabaseHelper.dart';
|
import 'package:tablet_app/Helpers/DatabaseHelper.dart';
|
||||||
|
import 'package:tablet_app/Helpers/MQTTHelper.dart';
|
||||||
import 'package:tablet_app/Models/tabletContext.dart';
|
import 'package:tablet_app/Models/tabletContext.dart';
|
||||||
import 'package:tablet_app/Screens/MainView/dropDown_configuration.dart';
|
import 'package:tablet_app/Screens/MainView/dropDown_configuration.dart';
|
||||||
import 'package:tablet_app/Screens/MainView/main_view.dart';
|
import 'package:tablet_app/Screens/MainView/main_view.dart';
|
||||||
@ -29,7 +30,7 @@ class ConfigViewWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _ConfigViewWidget extends State<ConfigViewWidget> {
|
class _ConfigViewWidget extends State<ConfigViewWidget> {
|
||||||
Size sizeScreen = new Size(1080.0, 1920.0); // Tablet resolution
|
Size sizeScreen = new Size(1080.0, 1920.0); // Tablet resolution
|
||||||
String url = "http://192.168.31.96"; //DEV "http://192.168.31.96"
|
String url; //DEV "http://192.168.31.96"
|
||||||
bool configOk = false;
|
bool configOk = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -37,6 +38,11 @@ class _ConfigViewWidget extends State<ConfigViewWidget> {
|
|||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
SystemChrome.setEnabledSystemUIOverlays([]);
|
SystemChrome.setEnabledSystemUIOverlays([]);
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
|
TabletAppContext tabletAppContext = appContext.getContext();
|
||||||
|
if (tabletAppContext != null) {
|
||||||
|
if (tabletAppContext.host != null)
|
||||||
|
url = tabletAppContext.host;
|
||||||
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Container(
|
body: Container(
|
||||||
height: size.height,
|
height: size.height,
|
||||||
@ -75,7 +81,7 @@ class _ConfigViewWidget extends State<ConfigViewWidget> {
|
|||||||
configurations: snapshot.data,
|
configurations: snapshot.data,
|
||||||
onChange: (ConfigurationDTO configurationOut) async {
|
onChange: (ConfigurationDTO configurationOut) async {
|
||||||
// CREATE DEVICE REQUEST
|
// CREATE DEVICE REQUEST
|
||||||
createDevice(configurationOut, appContext);
|
await createDevice(configurationOut, appContext);
|
||||||
|
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
@ -128,6 +134,7 @@ class _ConfigViewWidget extends State<ConfigViewWidget> {
|
|||||||
padding: const EdgeInsets.only(left: 50, right: 50),
|
padding: const EdgeInsets.only(left: 50, right: 50),
|
||||||
child: RoundedInputField(
|
child: RoundedInputField(
|
||||||
hintText: "URL",
|
hintText: "URL",
|
||||||
|
initialValue: url,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
url = value;
|
url = value;
|
||||||
@ -210,7 +217,13 @@ class _ConfigViewWidget extends State<ConfigViewWidget> {
|
|||||||
appContext.setContext(tabletAppContext);
|
appContext.setContext(tabletAppContext);
|
||||||
|
|
||||||
// STORE IT LOCALLY (SQLite)
|
// STORE IT LOCALLY (SQLite)
|
||||||
|
TabletAppContext localContext = await DatabaseHelper.instance.getData();
|
||||||
|
if (localContext != null) { // Check if sql DB exist
|
||||||
|
await DatabaseHelper.instance.update(tabletAppContext);
|
||||||
|
} else {
|
||||||
await DatabaseHelper.instance.insert(tabletAppContext);
|
await DatabaseHelper.instance.insert(tabletAppContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: "La tablette a bien été créée",
|
msg: "La tablette a bien été créée",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import 'package:managerapi/api.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:tablet_app/Components/loading.dart';
|
import 'package:tablet_app/Components/loading.dart';
|
||||||
import 'package:tablet_app/Helpers/MQTTHelper.dart';
|
import 'package:tablet_app/Helpers/MQTTHelper.dart';
|
||||||
|
import 'package:tablet_app/Screens/Configuration/config_view.dart';
|
||||||
import 'package:tablet_app/Screens/Map/map_context.dart';
|
import 'package:tablet_app/Screens/Map/map_context.dart';
|
||||||
import 'package:tablet_app/Screens/Map/map_view.dart';
|
import 'package:tablet_app/Screens/Map/map_view.dart';
|
||||||
import 'package:tablet_app/Models/map-marker.dart';
|
import 'package:tablet_app/Models/map-marker.dart';
|
||||||
@ -191,7 +192,8 @@ class _MainViewWidget extends State<MainViewWidget> {
|
|||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
if (snapshot.data == null) {
|
if (snapshot.data == null) {
|
||||||
return Text("ERROR");
|
// Show select config
|
||||||
|
return Text("");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return GridView.builder(
|
return GridView.builder(
|
||||||
@ -261,11 +263,23 @@ class _MainViewWidget extends State<MainViewWidget> {
|
|||||||
|
|
||||||
Future<List<SectionDTO>> getSections(dynamic appContext) async {
|
Future<List<SectionDTO>> getSections(dynamic appContext) async {
|
||||||
TabletAppContext tabletAppContext = await appContext.getContext();
|
TabletAppContext tabletAppContext = await appContext.getContext();
|
||||||
print("GET SECTIONS");
|
try {
|
||||||
print(tabletAppContext.toString());
|
|
||||||
List<SectionDTO> sections = await tabletAppContext.clientAPI.sectionApi.sectionGetFromConfiguration(tabletAppContext.configuration.id);
|
List<SectionDTO> sections = await tabletAppContext.clientAPI.sectionApi.sectionGetFromConfiguration(tabletAppContext.configuration.id);
|
||||||
sections.sort((a, b) => a.order.compareTo(b.order));
|
sections.sort((a, b) => a.order.compareTo(b.order));
|
||||||
return sections;
|
return sections;
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
print("IN CATCH");
|
||||||
|
Navigator.pushAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) {
|
||||||
|
return ConfigViewWidget();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(Route<dynamic> route) => false // For pushAndRemoveUntil
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,11 @@ void main() async {
|
|||||||
// Get config from manager
|
// Get config from manager
|
||||||
DeviceDetailDTO device = await localContext.clientAPI.deviceApi.deviceGetDetail(localContext.deviceId);
|
DeviceDetailDTO device = await localContext.clientAPI.deviceApi.deviceGetDetail(localContext.deviceId);
|
||||||
localContext.configuration.id = device.configurationId;
|
localContext.configuration.id = device.configurationId;
|
||||||
|
if (device.configurationId == null) {
|
||||||
|
print("device.configurationId == null");
|
||||||
|
localContext.configuration = null;
|
||||||
|
isConfig = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
print("NO LOCAL DB !");
|
print("NO LOCAL DB !");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user