Skip to content

Commit

Permalink
Merge pull request #128 from Myzel394/fix-migration
Browse files Browse the repository at this point in the history
Fix migration
  • Loading branch information
Myzel394 committed Oct 3, 2023
2 parents 92d19f9 + 2c99789 commit fb2500b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/constants/values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const LOCATION_INTERVAL = Duration(minutes: 1);
const TRANSFER_DATA_USERNAME = "locus_transfer";
final TRANSFER_SUCCESS_MESSAGE = Uint8List.fromList([1, 2, 3, 4]);

const CURRENT_APP_VERSION = "0.15.0";
const CURRENT_APP_VERSION = "0.15.1";

const LOG_TAG = "LocusLog";

Expand Down
1 change: 1 addition & 0 deletions lib/screens/view_alarm_screen_widgets/ViewAlarmScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class _ViewAlarmScreenState extends State<ViewAlarmScreen> {
final child = (() {
switch (alarm.IDENTIFIER) {
case LocationAlarmType.geo:
case LocationAlarmType.radiusBasedRegion:
return GeoLocationAlarmPreview(
view: widget.view,
alarm: alarm as GeoLocationAlarm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class _ViewAlarmSelectRadiusBasedScreenState

switch (widget.type) {
case LocationAlarmType.geo:
case LocationAlarmType.radiusBasedRegion:
alarm = await showPlatformModalSheet(
context: context,
material: MaterialModalSheetData(
Expand Down
2 changes: 2 additions & 0 deletions lib/services/location_alarm_service/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enum LocationAlarmTriggerType {
enum LocationAlarmType {
geo,
proximity,
// Required for migration, same as `geo`
radiusBasedRegion,
}

enum LocationRadiusBasedTriggerType {
Expand Down
5 changes: 3 additions & 2 deletions lib/services/task_service/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class Task extends ChangeNotifier with LocationBase {
throw Exception("Unknown timer type");
}
})),
outstandingLocations: Map<String, int>.from(json["outstandingLocations"])
.map<LocationPointService, int>(
outstandingLocations:
Map<String, int>.from(json["outstandingLocations"] ?? {})
.map<LocationPointService, int>(
(rawLocationData, tries) => MapEntry(
LocationPointService.fromJSON(jsonDecode(rawLocationData)),
tries,
Expand Down
26 changes: 14 additions & 12 deletions lib/services/view_service/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class TaskView extends ChangeNotifier with LocationBase {
String? id,
DateTime? lastAlarmCheck,
List<LocationAlarmServiceBase>? alarms,
})
: _encryptionPassword = encryptionPassword,
}) : _encryptionPassword = encryptionPassword,
alarms = alarms ?? [],
lastAlarmCheck = lastAlarmCheck ?? DateTime.now(),
id = id ?? const Uuid().v4();
Expand All @@ -62,7 +61,7 @@ class TaskView extends ChangeNotifier with LocationBase {
final fragment = uri.fragment;

final rawParameters =
const Utf8Decoder().convert(base64Url.decode(fragment));
const Utf8Decoder().convert(base64Url.decode(fragment));
final parameters = jsonDecode(rawParameters);

return ViewServiceLinkParameters(
Expand All @@ -76,10 +75,9 @@ class TaskView extends ChangeNotifier with LocationBase {
);
}

factory TaskView.fromJSON(final Map<String, dynamic> json) =>
TaskView(
factory TaskView.fromJSON(final Map<String, dynamic> json) => TaskView(
encryptionPassword:
SecretKey(List<int>.from(json["encryptionPassword"])),
SecretKey(List<int>.from(json["encryptionPassword"])),
nostrPublicKey: json["nostrPublicKey"],
relays: List<String>.from(json["relays"]),
name: json["name"] ?? "Unnamed Task",
Expand All @@ -92,6 +90,7 @@ class TaskView extends ChangeNotifier with LocationBase {

switch (identifier) {
case LocationAlarmType.geo:
case LocationAlarmType.radiusBasedRegion:
return GeoLocationAlarm.fromJSON(alarm);
case LocationAlarmType.proximity:
return ProximityLocationAlarm.fromJSON(alarm);
Expand All @@ -109,8 +108,10 @@ class TaskView extends ChangeNotifier with LocationBase {
: Colors.primaries[Random().nextInt(Colors.primaries.length)],
);

static Future<TaskView> fetchFromNostr(final AppLocalizations l10n,
final ViewServiceLinkParameters parameters,) async {
static Future<TaskView> fetchFromNostr(
final AppLocalizations l10n,
final ViewServiceLinkParameters parameters,
) async {
final completer = Completer<TaskView>();

final request = Request(generate64RandomHexChars(), [
Expand Down Expand Up @@ -152,7 +153,7 @@ class TaskView extends ChangeNotifier with LocationBase {
relays: List<String>.from(data['relays']),
name: l10n.longFormattedDate(DateTime.now()),
color:
Colors.primaries[Random().nextInt(Colors.primaries.length)],
Colors.primaries[Random().nextInt(Colors.primaries.length)],
),
);
} catch (error) {
Expand Down Expand Up @@ -199,7 +200,8 @@ class TaskView extends ChangeNotifier with LocationBase {
};
}

Future<String?> validate(final AppLocalizations l10n, {
Future<String?> validate(
final AppLocalizations l10n, {
required final TaskService taskService,
required final ViewService viewService,
}) async {
Expand All @@ -208,14 +210,14 @@ class TaskView extends ChangeNotifier with LocationBase {
}

final sameTask = taskService.tasks.firstWhereOrNull(
(element) => element.nostrPublicKey == nostrPublicKey);
(element) => element.nostrPublicKey == nostrPublicKey);

if (sameTask != null) {
return l10n.taskImport_error_sameTask(sameTask.name);
}

final sameView = viewService.views.firstWhereOrNull(
(element) => element.nostrPublicKey == nostrPublicKey);
(element) => element.nostrPublicKey == nostrPublicKey);

if (sameView != null) {
return l10n.taskImport_error_sameView(sameView.name);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.15.0+36
version: 0.15.1+37

environment:
sdk: '>=3.0.0'
Expand Down

0 comments on commit fb2500b

Please sign in to comment.