Adds logic for making folders
This commit is contained in:
parent
e71f55cbc4
commit
c1dd5e1957
6 changed files with 210 additions and 5 deletions
|
@ -1,3 +1,11 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:libac_flutter/utils/uuid/UUID.dart';
|
||||
import 'package:zontreck/Constants.dart';
|
||||
import 'package:zontreck/Packets.dart';
|
||||
import 'package:zontreck/Settings.dart';
|
||||
|
||||
enum InventoryFolder {
|
||||
Texture(id: 0, name: "Textures"),
|
||||
Sound(id: 1, name: "Sounds"),
|
||||
|
@ -32,3 +40,105 @@ enum InventoryFolder {
|
|||
final String name;
|
||||
const InventoryFolder({required this.id, required this.name});
|
||||
}
|
||||
|
||||
class CreateInventoryPopup extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => CreateInventoryState();
|
||||
}
|
||||
|
||||
class CreateInventoryState extends State<CreateInventoryPopup> {
|
||||
double getProgress() {
|
||||
double percent = (value * 100 / total);
|
||||
return percent / 100;
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
int total = 100;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
startProcessing();
|
||||
}
|
||||
|
||||
Future<void> startProcessing() async {
|
||||
total = InventoryFolder.values.length;
|
||||
await Future.delayed(Duration(seconds: 5));
|
||||
|
||||
UUID rootFolder = UUID.generate(4);
|
||||
|
||||
Settings settings = Settings();
|
||||
Future<void> createFolder(Timer timer) async {
|
||||
if (getProgress() >= 1) {
|
||||
timer.cancel();
|
||||
Navigator.pop(context);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
"Inventory successfully created. Your account is now active")));
|
||||
return;
|
||||
}
|
||||
|
||||
UUID parent = rootFolder;
|
||||
UUID id = UUID.generate(4);
|
||||
UUID owner = settings.currentUser!.ID;
|
||||
int type = InventoryFolder.values[value].id;
|
||||
String name = InventoryFolder.values[value].name;
|
||||
|
||||
if (type == InventoryFolder.ROOT.id) {
|
||||
parent = UUID.ZERO;
|
||||
id = rootFolder;
|
||||
}
|
||||
|
||||
C2SCreateFolderPacket makeFolder = C2SCreateFolderPacket(
|
||||
ParentFolder: parent,
|
||||
ID: id,
|
||||
Name: name,
|
||||
Type: type,
|
||||
Owner: owner,
|
||||
client: Constants.CLIENTPSK);
|
||||
|
||||
var reply = await settings.sendPacketToEndpoint(
|
||||
APIEndpoint.MakeFolder, makeFolder) as S2CSimpleReplyPacket;
|
||||
if (!reply.done) {
|
||||
timer.cancel();
|
||||
Navigator.pop(context);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (V) {
|
||||
return AlertDialog(
|
||||
title: Text("FATAL ERROR"),
|
||||
content: Text(
|
||||
"For an unknown reason, we failed to create the inventory folders. Some may have been created, but there was an error while processing: ${makeFolder.encodeSafe()}"),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
value++;
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Timer.periodic(Duration(milliseconds: 500), createFolder);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: Icon(Icons.folder_copy),
|
||||
title: Text("Please Wait... Activating Account"),
|
||||
content: SizedBox(
|
||||
height: 75,
|
||||
child: Column(
|
||||
children: [
|
||||
Text("Creating necessary Inventory Folders"),
|
||||
Divider(),
|
||||
LinearProgressIndicator(
|
||||
value: getProgress(),
|
||||
color: Constants.PORTFOLIO_CARD_COLOR,
|
||||
minHeight: 10,
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue