Start to update stuff

This commit is contained in:
zontreck 2024-05-22 16:09:36 -07:00
parent 110b2d150c
commit 399d884681
18 changed files with 217 additions and 240 deletions

View file

@ -1,25 +1,13 @@
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:hive/hive.dart';
import 'package:libac_flutter/nbt/NbtUtils.dart';
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
import 'package:libac_flutter/nbt/impl/IntTag.dart';
import 'package:servermanager/settings.dart';
part 'autorestart.g.dart';
@HiveType(typeId: 3)
class AutomaticRestartInfo {
@HiveField(0, defaultValue: 0)
final int hours;
@HiveField(1, defaultValue: 0)
final int minutes;
@HiveField(2, defaultValue: 0)
final int seconds;
@HiveField(3, defaultValue: false)
final bool enabled;
const AutomaticRestartInfo(
@ -27,6 +15,30 @@ class AutomaticRestartInfo {
this.minutes = 0,
this.seconds = 0,
this.enabled = false});
static AutomaticRestartInfo deserialize(CompoundTag tag) {
return AutomaticRestartInfo(
hours: tag.get(TAG_HOURS)?.asInt() ?? 12,
minutes: tag.get(TAG_MINUTES)?.asInt() ?? 0,
seconds: tag.get(TAG_SECONDS)?.asInt() ?? 0,
enabled: NbtUtils.readBoolean(tag, TAG_ENABLED));
}
CompoundTag serialize() {
CompoundTag tag = CompoundTag();
tag.put(TAG_HOURS, IntTag.valueOf(hours));
tag.put(TAG_MINUTES, IntTag.valueOf(minutes));
tag.put(TAG_SECONDS, IntTag.valueOf(seconds));
NbtUtils.writeBoolean(tag, TAG_ENABLED, enabled);
return tag;
}
static const TAG_NAME = "ari";
static const TAG_HOURS = "hours";
static const TAG_MINUTES = "minutes";
static const TAG_SECONDS = "seconds";
static const TAG_ENABLED = "enabled";
}
class AutoRestartPage extends StatefulWidget {
@ -62,8 +74,8 @@ class AutoRestartState extends State<AutoRestartPage> {
title: Text("Automatic Restart"),
backgroundColor: Color.fromARGB(255, 100, 0, 0),
),
body: WillPopScope(
onWillPop: () async {
body: PopScope(
onPopInvoked: (v) async {
Navigator.pop(
context,
AutomaticRestartInfo(
@ -71,8 +83,6 @@ class AutoRestartState extends State<AutoRestartPage> {
hours: hours,
minutes: minutes,
seconds: seconds));
return true;
},
child: SingleChildScrollView(
child: Padding(