Skip to content

Commit

Permalink
[Infrastructure] Implemented the deleteItemsFromInventory method
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jul 10, 2021
1 parent 6bb0a85 commit d6d575f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/infrastructure/data_service.dart
Expand Up @@ -228,6 +228,29 @@ class DataServiceImpl implements DataService {
}
}

@override
Future<void> deleteItemsFromInventory(ItemType type) async {
switch (type) {
case ItemType.character:
case ItemType.weapon:
case ItemType.artifact:
final toDeleteKeys = _inventoryBox.values.where((el) => el.type == type.index).map((e) => e.key).toList();
if (toDeleteKeys.isNotEmpty) {
await _inventoryBox.deleteAll(toDeleteKeys);
}
break;
case ItemType.material:
final materialsInInventory = _inventoryBox.values.where((el) => el.type == ItemType.material.index && el.quantity > 0).toList();
for (final material in materialsInInventory) {
material.quantity = 0;
await material.save();
}
final usedItemKeys = _inventoryUsedItemsBox.values.map((e) => e.key).toList();
_inventoryUsedItemsBox.deleteAll(usedItemKeys);
break;
}
}

@override
List<CharacterCardModel> getAllCharactersInInventory() {
final characters = _inventoryBox.values
Expand Down
4 changes: 4 additions & 0 deletions lib/infrastructure/telemetry/telemetry_service.dart
Expand Up @@ -141,6 +141,10 @@ class TelemetryServiceImpl implements TelemetryService {
@override
Future<void> trackItemUpdatedInInventory(String key, int quantity) => trackEventAsync('MyInventory-Updated', {'Key_Qty': '${key}_$quantity'});

@override
Future<void> trackItemsDeletedFromInventory(ItemType type) =>
trackEventAsync('MyInventory-Clear-All', {'Type': EnumToString.convertToString(type)});

@override
Future<void> trackNotificationCreated(AppNotificationType type) =>
trackEventAsync('Notification-Created', {'Type': EnumToString.convertToString(type)});
Expand Down

0 comments on commit d6d575f

Please sign in to comment.