Skip to content

Commit

Permalink
feat: Custom KML generation and KMl rendering done.
Browse files Browse the repository at this point in the history
  • Loading branch information
AritraBiswas9788 committed Jun 24, 2024
1 parent 5bc4b28 commit 6855d7b
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 61 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<queries>
<!-- If your application checks for inAppBrowserView launch mode support -->
<intent>
Expand Down
61 changes: 60 additions & 1 deletion lib/components/apimanager_block.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:super_liquid_galaxy_controller/utils/api_manager.dart';
import '../generated/assets.dart';
import 'custom_dialog.dart';
import 'galaxytextfield.dart';
import 'package:lottie/lottie.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ApiManagerBlock extends StatefulWidget {
Expand Down Expand Up @@ -31,7 +35,16 @@ class ApiManagerBlock extends StatefulWidget {
State<ApiManagerBlock> createState() => _ApiManagerBlockState();
}



class _ApiManagerBlockState extends State<ApiManagerBlock> {

@override
void initState() {
loadSetValues();
super.initState();
}

@override
Widget build(BuildContext context) {
return Padding(
Expand Down Expand Up @@ -179,10 +192,56 @@ class _ApiManagerBlockState extends State<ApiManagerBlock> {
)))
]))));
}
void loadSetValues() async {

try {
SharedPreferences preferences = await SharedPreferences.getInstance();
var key = preferences.getString("places_apikey") ?? "";
key = key.trim();
widget.keyController.text = key;
}
catch(e)
{
print(e);
}

}


void saveApiKey(String prefKey) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.setString(prefKey, widget.keyController.text);
ApiManager.instance;
ApiManager apiClient = Get.find();
await apiClient.testApiKey();
var dialog = apiClient.isConnected.value
? CustomDialog(
content: Text("All Api Services now available!"),
title: Text("API KEY VALIDATED",style: TextStyle(color: Colors.green.shade500,fontSize: 25.0,fontWeight: FontWeight.bold),),
firstColor: Colors.green,
secondColor: Colors.white,
headerIcon: Lottie.asset(Assets.lottieConnected,
decoder: customDecoder, repeat: false,width: 200.0,height: 200.0))
: CustomDialog(
content: Text("Api services unavailable"),
title: Text("API KEY INVALID",style: TextStyle(color: Colors.red.shade500,fontSize: 25.0,fontWeight: FontWeight.bold),),
firstColor: Colors.red.shade400,
secondColor: Colors.white,
headerIcon: Lottie.asset(Assets.lottieConnectionfailed,
decoder: customDecoder, repeat: false,width: 200.0,height: 200.0));
showDialog(
context: context,
builder: (BuildContext context) {
return dialog;
},
);

}

Future<LottieComposition?> customDecoder(List<int> bytes) {
return LottieComposition.decodeZip(bytes, filePicker: (files) {
return files.firstWhere(
(f) => f.name.startsWith('animations/') && f.name.endsWith('.json'),
);
});
}
}
4 changes: 2 additions & 2 deletions lib/components/navisland.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ class NavIsland extends StatelessWidget {
color: Colors.transparent,
child: InkWell(
onTap: () async {
var manager = ApiManager.instance;
/*var manager = ApiManager.instance;
var response = await manager.getAutoCompleteResponse("How");
print(response.data);
print(response.data);*/
},
borderRadius: BorderRadius.circular(15),
child: Container(
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:super_liquid_galaxy_controller/screens/splashscreen.dart';
import 'package:super_liquid_galaxy_controller/utils/api_manager.dart';
import 'package:super_liquid_galaxy_controller/utils/lg_connection.dart';

AndroidMapRenderer mapRenderer = AndroidMapRenderer.platformDefault;
Expand All @@ -17,7 +18,8 @@ void main() {
mapRenderer = await mapsImplementation
.initializeWithRenderer(AndroidMapRenderer.latest);
}*/
Get.put(LGConnection());
Get.lazyPut(() => LGConnection(),fenix: true);
Get.lazyPut(() => ApiManager(),fenix: true);
LGConnection client = Get.find();
client.connectToLG();
SystemChrome.setPreferredOrientations([
Expand Down
19 changes: 12 additions & 7 deletions lib/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:super_liquid_galaxy_controller/components/navisland.dart';
import 'package:super_liquid_galaxy_controller/components/planet_selector.dart';
import 'package:super_liquid_galaxy_controller/generated/assets.dart';
import 'package:super_liquid_galaxy_controller/screens/settings.dart';
import 'package:super_liquid_galaxy_controller/utils/api_manager.dart';
import 'package:super_liquid_galaxy_controller/utils/lg_connection.dart';
import 'package:lottie/lottie.dart';

Expand All @@ -27,12 +28,14 @@ class _DashBoardState extends State<DashBoard> {
late double screenHeight;
late double screenWidth;
late LGConnection connectionClient;
late ApiManager apiClient;

@override
void initState() {
super.initState();
log("ui", "dashboard-built");
initializeLGClient();
initializeApiClient();

}

Expand Down Expand Up @@ -107,7 +110,6 @@ class _DashBoardState extends State<DashBoard> {
onTap: () async {
log("gesture", "settings tapped");
await Get.to(() => Settings());
_reload();
},
),
)
Expand Down Expand Up @@ -145,7 +147,7 @@ class _DashBoardState extends State<DashBoard> {
children: [
Obx(() {
return ConnectionFlag(
status: connectionClient.isConnected.value,
status: apiClient.isConnected.value,
backgroundColor: Colors.white.withOpacity(
0.0),
selectedText: 'API CONNECTED',
Expand Down Expand Up @@ -195,9 +197,10 @@ class _DashBoardState extends State<DashBoard> {
void initializeLGClient() async {
connectionClient = Get.find();
await connectionClient.connectToLG();
setState(() {

});
}
void initializeApiClient() async {
apiClient = Get.find();
await apiClient.testApiKey();
}

void _reload() {
Expand All @@ -207,7 +210,7 @@ class _DashBoardState extends State<DashBoard> {

//test

Future<void> testDialog() async {
/*Future<void> testDialog() async {
var customDialog = CustomDialog(
content: Text("SSH operations are now possible."),
title: Text("Connection established",style: TextStyle(color: Colors.green.shade500,fontSize: 25.0,fontWeight: FontWeight.bold),),
Expand All @@ -229,7 +232,7 @@ class _DashBoardState extends State<DashBoard> {
return customDialog1;
},
);
}
}*/

Future<LottieComposition?> customDecoder(List<int> bytes) {
return LottieComposition.decodeZip(bytes, filePicker: (files) {
Expand All @@ -239,4 +242,6 @@ class _DashBoardState extends State<DashBoard> {
});
}



}
26 changes: 24 additions & 2 deletions lib/screens/kml_builder.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import 'dart:io';
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:get/get.dart';
import 'package:super_liquid_galaxy_controller/components/galaxy_button.dart';
import 'package:super_liquid_galaxy_controller/components/glassbox.dart';
import 'package:super_liquid_galaxy_controller/components/kml_elements/linestring.dart';
import 'package:super_liquid_galaxy_controller/components/kml_elements/placemark.dart';
import 'package:super_liquid_galaxy_controller/components/kml_elements/polygon.dart';
import 'package:super_liquid_galaxy_controller/screens/test.dart';
import 'package:super_liquid_galaxy_controller/utils/galaxy_colors.dart';
import 'package:super_liquid_galaxy_controller/utils/kmlgenerator.dart';
import 'package:super_liquid_galaxy_controller/utils/lg_connection.dart';

import '../data_class/kml_element.dart';
import '../generated/assets.dart';
Expand All @@ -25,6 +30,7 @@ class _KmlUploaderState extends State<KmlUploader> {
late double screenHeight;
late double screenWidth;
late DataRetrieverHandler dataController;
late LGConnection sshClient;

int elementIndex = 0;
List<String> labels = ['Placemark', 'Polyline', 'Polygon'];
Expand All @@ -35,6 +41,12 @@ class _KmlUploaderState extends State<KmlUploader> {
];
List<KmlElement> kmlList = [];

@override
void initState() {
sshClient = Get.find();
super.initState();
}

@override
Widget build(BuildContext context) {
screenHeight = MediaQuery.of(context).size.height;
Expand Down Expand Up @@ -219,7 +231,16 @@ class _KmlUploaderState extends State<KmlUploader> {
actionText: "VISUALIZE IN LG",
icon: Icons.smart_screen,
isLeading: true,
onTap: () {},
onTap: () async {
print("tapped");
await sshClient.connectToLG();
await sshClient.clearKml();
File? file = await sshClient.makeFile('custom_kml', KMLGenerator.generateKml('slave_1', kmlList));
print("made successfully");
await sshClient.kmlFileUpload(context, file!, 'custom_kml');
print("uploaded successfully");
await sshClient.runKml('custom_kml');
},
backgroundColor: GalaxyColors.blue.withOpacity(0.4),
),
GalaxyButton(
Expand All @@ -228,7 +249,8 @@ class _KmlUploaderState extends State<KmlUploader> {
actionText: "VISUALIZE IN MAP",
icon: Icons.map,
isLeading: true,
onTap: () {},
onTap: () {
},
backgroundColor: GalaxyColors.blue.withOpacity(0.4),
)
],
Expand Down
11 changes: 7 additions & 4 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:super_liquid_galaxy_controller/generated/assets.dart';
import 'package:super_liquid_galaxy_controller/tabs/apikey_tab.dart';
import 'package:super_liquid_galaxy_controller/tabs/connection_tab.dart';
import 'package:super_liquid_galaxy_controller/tabs/sshcommands_tab.dart';
import 'package:super_liquid_galaxy_controller/utils/api_manager.dart';
import 'package:super_liquid_galaxy_controller/utils/lg_connection.dart';

//ignore_for_file: prefer_const_constructors
Expand All @@ -22,11 +23,13 @@ class Settings extends StatefulWidget {
class _SettingsState extends State<Settings> {
late double screenHeight;
late double screenWidth;
late LGConnection client;
late LGConnection connectionClient;
late ApiManager apiClient;

@override
void initState() {
client = Get.find();
connectionClient = Get.find();
apiClient = Get.find();
super.initState();
}

Expand Down Expand Up @@ -89,7 +92,7 @@ class _SettingsState extends State<Settings> {
]),
child: ImageIcon(
AssetImage(Assets.iconsSshIndicator),
color: client.isConnected.value ? Colors.green : Colors.red,
color: connectionClient.isConnected.value ? Colors.green : Colors.red,
size: screenHeight *0.06,
)),
);}
Expand All @@ -107,7 +110,7 @@ class _SettingsState extends State<Settings> {
]),
child: ImageIcon(
AssetImage(Assets.iconsApiIndicator),
color: client.isConnected.value ? Colors.green : Colors.red,
color: apiClient.isConnected.value ? Colors.green : Colors.red,
size: screenHeight *0.07,
)),
);}
Expand Down
31 changes: 31 additions & 0 deletions lib/screens/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';

class TestScreen extends StatefulWidget {
const TestScreen({super.key, required this.kml});

final String kml;

@override
State<TestScreen> createState() => _TestScreenState();
}

class _TestScreenState extends State<TestScreen> {
TextEditingController controller = TextEditingController();

@override
void initState() {
controller.text = widget.kml;
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextField(
controller: controller,
),
),
);
}
}
5 changes: 4 additions & 1 deletion lib/tabs/sshcommands_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ class _SSHCommandsTabState extends State<SSHCommandsTab> with AutomaticKeepAlive
),
TextButton(
child: const Text("CONTINUE", style: TextStyle(color: Colors.red),),
onPressed: () => action(),
onPressed: () async {
await action();
Get.back();
},
),
],
),
Expand Down
Loading

0 comments on commit 6855d7b

Please sign in to comment.