Skip to content

Commit

Permalink
Resetting of accessory. Improvements on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
danny committed Feb 23, 2025
1 parent 3f66939 commit a1d608b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
26 changes: 23 additions & 3 deletions macless_haystack/lib/accessory/accessory_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class AccessoryDetail extends StatefulWidget {
return _AccessoryDetailState();
}

// @override
// _AccessoryDetailState createState() => _AccessoryDetailState();
// @override
// _AccessoryDetailState createState() => _AccessoryDetailState();
}

class _AccessoryDetailState extends State<AccessoryDetail> {
Expand Down Expand Up @@ -84,7 +84,7 @@ class _AccessoryDetailState extends State<AccessoryDetail> {
setState(() {
newAccessory.setIcon(selectedIcon);
});
if (mounted) {
if (context.mounted) {
// Show color selection only when icon is selected
Color? selectedColor =
await AccessoryColorSelector
Expand Down Expand Up @@ -147,6 +147,26 @@ class _AccessoryDetailState extends State<AccessoryDetail> {
child: const Text('Save'),
),
),
ListTile(
title: OutlinedButton(
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
),
onPressed: () {
// Update accessory with changed values
var accessoryRegistry =
Provider.of<AccessoryRegistry>(context, listen: false);
accessoryRegistry.deleteData(widget.accessory);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('All current and historical data deleted'),
),
);
},
child: const Text('Reset Accessory'),
),
),
ListTile(
title: ElevatedButton(
style: ButtonStyle(
Expand Down
2 changes: 1 addition & 1 deletion macless_haystack/lib/accessory/accessory_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AccessoryListItem extends StatelessWidget {
// Format published date in a human readable way
String? dateString = accessory.datePublished != null &&
accessory.datePublished != DateTime(1970)
? ' · ${DateFormat.yMMMd(Platform.localeName).format(accessory.datePublished!)} ${DateFormat.jm(Platform.localeName).format(accessory.datePublished!)}'
? '\n${DateFormat.yMMMd(Platform.localeName).format(accessory.datePublished!)} ${DateFormat.jm(Platform.localeName).format(accessory.datePublished!)}'
: '';
return ListTile(
onTap: onTap,
Expand Down
12 changes: 12 additions & 0 deletions macless_haystack/lib/accessory/accessory_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,16 @@ class AccessoryRegistry extends ChangeNotifier {
loadedAccessories.removeAt(index);
}
}

void deleteData(Accessory accessory) {
accessory.lastBatteryStatus = null;
accessory.lastLocation = null;
accessory.hashesWithTS.clear();
accessory.isActive = true;
accessory.datePublished = DateTime(1970);
accessory.place = Future.value(null);
accessory.locationHistory.clear();
notifyListeners();
}

}
4 changes: 2 additions & 2 deletions macless_haystack/lib/findMy/find_my_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class FindMyController {
ECKeyGeneratorParameters(ecCurve), secureRandom));

final newKeyPair = keyGen.generateKeyPair();
final ECPublicKey publicKey = newKeyPair.publicKey as ECPublicKey;
final ECPrivateKey privateKey = newKeyPair.privateKey as ECPrivateKey;
final ECPublicKey publicKey = newKeyPair.publicKey;
final ECPrivateKey privateKey = newKeyPair.privateKey;
final hashedKey = getHashedPublicKey(publicKey: publicKey);
final keyPair =
FindMyKeyPair(publicKey, hashedKey, privateKey, DateTime.now(), -1);
Expand Down
5 changes: 4 additions & 1 deletion macless_haystack/lib/history/accessory_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:macless_haystack/history/location_popup.dart';

import 'dart:math';


class AccessoryHistory extends StatefulWidget {
final Accessory accessory;

Expand Down Expand Up @@ -167,7 +168,9 @@ class _AccessoryHistoryState extends State<AccessoryHistory> {
},
child: Icon(
Icons.circle,
size: isPointLayerVisible ? calculateSize(entry) : 0,
size: isPointLayerVisible
? calculateSize(entry)
: 0,
color: entry == popupEntry
? Colors.red
: Theme.of(context).indicatorColor,
Expand Down
5 changes: 3 additions & 2 deletions macless_haystack/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ dependencies:
# UI
flutter_colorpicker: ^1.1.0
flutter_slidable: ^4.0.0
marquee: ^2.3.0

# Networking
http: ^1.3.0
universal_html: ^2.2.4

# Cryptography
# latest version of pointy castle for crypto functions
pointycastle: ^3.9.1
pointycastle: ^4.0.0

# State Management
provider: ^6.1.2
Expand All @@ -55,7 +56,7 @@ dependencies:
# Storage
shared_preferences: ^2.5.2
flutter_secure_storage: ^9.2.4
file_picker: ^8.3.7
file_picker: ^9.0.0

# Sharing
share_plus: ^10.1.4
Expand Down

0 comments on commit a1d608b

Please sign in to comment.