Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infrastructure] Splitted the data service into multiple chunks
- Loading branch information
Showing
16 changed files
with
2,114 additions
and
1,890 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,321 +1,28 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:shiori/domain/enums/enums.dart'; | ||
import 'package:shiori/domain/models/entities.dart'; | ||
import 'package:shiori/domain/models/models.dart'; | ||
import 'package:shiori/domain/services/persistence/calculator_data_service.dart'; | ||
import 'package:shiori/domain/services/persistence/custom_builds_data_service.dart'; | ||
import 'package:shiori/domain/services/persistence/game_codes_data_service.dart'; | ||
import 'package:shiori/domain/services/persistence/inventory_data_service.dart'; | ||
import 'package:shiori/domain/services/persistence/notifications_data_service.dart'; | ||
import 'package:shiori/domain/services/persistence/tier_list_data_service.dart'; | ||
|
||
abstract class DataService { | ||
StreamController<ItemType> get itemAddedToInventory; | ||
CalculatorDataService get calculator; | ||
|
||
StreamController<ItemType> get itemUpdatedInInventory; | ||
|
||
StreamController<ItemType> get itemDeletedFromInventory; | ||
InventoryDataService get inventory; | ||
|
||
CustomBuildsDataService get customBuilds; | ||
|
||
Future<void> init({String dir = 'shiori_data'}); | ||
|
||
Future<void> deleteThemAll(); | ||
|
||
Future<void> closeThemAll(); | ||
|
||
List<CalculatorSessionModel> getAllCalAscMatSessions(); | ||
|
||
CalculatorSessionModel getCalcAscMatSession(int sessionKey); | ||
|
||
Future<int> createCalAscMatSession(String name, int position); | ||
|
||
Future<void> updateCalAscMatSession(int sessionKey, String name, int position, {bool redistributeMaterials = false}); | ||
|
||
Future<void> deleteCalAscMatSession(int sessionKey); | ||
|
||
Future<void> deleteAllCalAscMatSession(); | ||
|
||
Future<void> addCalAscMatSessionItems(int sessionKey, List<ItemAscensionMaterials> items); | ||
|
||
/// Adds a new calc. item to the provided session by using the [sessionKey]. | ||
/// | ||
/// If [item.useMaterialsFromInventory] is set to false, the same item will be returned without changes. | ||
/// Otherwise, it will be returned with [item.materials] property updated. | ||
Future<ItemAscensionMaterials> addCalAscMatSessionItem(int sessionKey, ItemAscensionMaterials item, {bool redistribute = true}); | ||
|
||
/// Updates the provided item associated to the session [sessionKey] | ||
/// | ||
/// The item will be retrieved using the current value of [item.position] | ||
/// and it will also be updated to the new position provided by [newItemPosition] | ||
/// | ||
/// If [item.useMaterialsFromInventory] is set to false, the same item will be returned without changes. | ||
/// Otherwise, it will be returned with [item.materials] property updated. | ||
Future<ItemAscensionMaterials> updateCalAscMatSessionItem( | ||
int sessionKey, | ||
int newItemPosition, | ||
ItemAscensionMaterials item, { | ||
bool redistribute = true, | ||
}); | ||
|
||
Future<void> deleteCalAscMatSessionItem(int sessionKey, int itemIndex, {bool redistribute = true}); | ||
|
||
Future<void> deleteAllCalAscMatSessionItems(int sessionKey); | ||
|
||
List<CharacterCardModel> getAllCharactersInInventory(); | ||
|
||
List<WeaponCardModel> getAllWeaponsInInventory(); | ||
|
||
List<MaterialCardModel> getAllMaterialsInInventory(); | ||
|
||
MaterialCardModel getMaterialFromInventory(String image); | ||
|
||
Future<void> addCharacterToInventory(String key, {bool raiseEvent = true}); | ||
|
||
Future<void> deleteCharacterFromInventory(String key, {bool raiseEvent = true}); | ||
|
||
Future<void> addWeaponToInventory(String key, {bool raiseEvent = true}); | ||
|
||
Future<void> deleteWeaponFromInventory(String key, {bool raiseEvent = true}); | ||
|
||
Future<void> addItemToInventory(String key, ItemType type, int quantity, {bool raiseEvent = true}); | ||
|
||
Future<void> updateItemInInventory(String key, ItemType type, int quantity, {bool raiseEvent = true}); | ||
|
||
Future<void> deleteItemFromInventory(String key, ItemType type, {bool raiseEvent = true}); | ||
|
||
Future<void> deleteItemsFromInventory(ItemType type, {bool raiseEvent = true}); | ||
|
||
bool isItemInInventory(String key, ItemType type); | ||
|
||
/// This method redistributes all the materials in the inventory by calling [redistributeInventoryMaterial] | ||
/// for each of the available sessions. | ||
/// | ||
/// This method should only be called when the priority of a session or calc. session changes | ||
Future<void> redistributeAllInventoryMaterials(); | ||
|
||
/// This method redistributes the material associated to [itemKey] based on the [newQuantity] | ||
/// | ||
/// This method should only be called when the quantity of a material changes | ||
/// | ||
/// | ||
/// E.g: If we now have more, we may update the used quantity in a [InventoryUsedItem] to use more, | ||
/// otherwise we may reduce the used quantity or even delete the whole thing | ||
Future<void> redistributeInventoryMaterial(String itemKey, int newQuantity); | ||
NotificationsDataService get notifications; | ||
|
||
List<GameCodeModel> getAllGameCodes(); | ||
GameCodesDataService get gameCodes; | ||
|
||
Future<void> saveGameCodes(List<GameCodeModel> items); | ||
TierListDataService get tierList; | ||
|
||
Future<void> saveGameCodeRewards(int gameCodeKey, List<ItemAscensionMaterialModel> rewards); | ||
|
||
Future<void> deleteAllGameCodeRewards(int gameCodeKey); | ||
|
||
Future<void> markCodeAsUsed(String code, {bool wasUsed = true}); | ||
|
||
List<TierListRowModel> getTierList(); | ||
|
||
Future<void> saveTierList(List<TierListRowModel> tierList); | ||
|
||
Future<void> deleteTierList(); | ||
|
||
List<NotificationItem> getAllNotifications(); | ||
|
||
NotificationItem getNotification(int key, AppNotificationType type); | ||
|
||
Future<NotificationItem> saveResinNotification( | ||
String itemKey, | ||
String title, | ||
String body, | ||
int currentResinValue, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveExpeditionNotification( | ||
String itemKey, | ||
String title, | ||
String body, | ||
ExpeditionTimeType expeditionTimeType, { | ||
String? note, | ||
bool showNotification = true, | ||
bool withTimeReduction = false, | ||
}); | ||
|
||
Future<NotificationItem> saveGadgetNotification( | ||
String itemKey, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveFurnitureNotification( | ||
String itemKey, | ||
FurnitureCraftingTimeType type, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveFarmingArtifactNotification( | ||
String itemKey, | ||
ArtifactFarmingTimeType type, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveFarmingMaterialNotification( | ||
String itemKey, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveRealmCurrencyNotification( | ||
String itemKey, | ||
RealmRankType realmRankType, | ||
int currentTrustRankLevel, | ||
int currentRealmCurrency, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveWeeklyBossNotification( | ||
String itemKey, | ||
AppServerResetTimeType serverResetTimeType, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveCustomNotification( | ||
String itemKey, | ||
String title, | ||
String body, | ||
DateTime completesAt, | ||
AppNotificationItemType notificationItemType, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<NotificationItem> saveDailyCheckInNotification( | ||
String itemKey, | ||
String title, | ||
String body, { | ||
String? note, | ||
bool showNotification = true, | ||
}); | ||
|
||
Future<void> deleteNotification(int key, AppNotificationType type); | ||
|
||
Future<NotificationItem> resetNotification(int key, AppNotificationType type, AppServerResetTimeType serverResetTimeType); | ||
|
||
Future<NotificationItem> stopNotification(int key, AppNotificationType type); | ||
|
||
Future<NotificationItem> updateResinNotification( | ||
int key, | ||
String itemKey, | ||
String title, | ||
String body, | ||
int currentResinValue, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateExpeditionNotification( | ||
int key, | ||
String itemKey, | ||
ExpeditionTimeType expeditionTimeType, | ||
String title, | ||
String body, | ||
bool showNotification, | ||
bool withTimeReduction, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateFurnitureNotification( | ||
int key, | ||
String itemKey, | ||
FurnitureCraftingTimeType type, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateFarmingMaterialNotification( | ||
int key, | ||
String itemKey, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateFarmingArtifactNotification( | ||
int key, | ||
String itemKey, | ||
ArtifactFarmingTimeType type, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateGadgetNotification( | ||
int key, | ||
String itemKey, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateRealmCurrencyNotification( | ||
int key, | ||
String itemKey, | ||
RealmRankType realmRankType, | ||
int currentTrustRankLevel, | ||
int currentRealmCurrency, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateWeeklyBossNotification( | ||
int key, | ||
AppServerResetTimeType serverResetTimeType, | ||
String itemKey, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
|
||
Future<NotificationItem> updateCustomNotification( | ||
int key, | ||
String itemKey, | ||
String title, | ||
String body, | ||
DateTime completesAt, | ||
bool showNotification, | ||
AppNotificationItemType notificationItemType, { | ||
String? note, | ||
}); | ||
Future<void> init({String dir = 'shiori_data'}); | ||
|
||
Future<NotificationItem> updateDailyCheckInNotification( | ||
int key, | ||
String itemKey, | ||
String title, | ||
String body, | ||
bool showNotification, { | ||
String? note, | ||
}); | ||
Future<void> deleteThemAll(); | ||
|
||
Future<NotificationItem> reduceNotificationHours(int key, AppNotificationType type, int hours); | ||
Future<void> closeThemAll(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
abstract class BaseDataService { | ||
Future<void> init(); | ||
|
||
Future<void> deleteThemAll(); | ||
} |
57 changes: 57 additions & 0 deletions
57
lib/domain/services/persistence/calculator_data_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:shiori/domain/models/models.dart'; | ||
import 'package:shiori/domain/services/persistence/base_data_service.dart'; | ||
|
||
abstract class CalculatorDataService implements BaseDataService { | ||
List<CalculatorSessionModel> getAllCalAscMatSessions(); | ||
|
||
CalculatorSessionModel getCalcAscMatSession(int sessionKey); | ||
|
||
Future<int> createCalAscMatSession(String name, int position); | ||
|
||
Future<void> updateCalAscMatSession(int sessionKey, String name, int position, {bool redistributeMaterials = false}); | ||
|
||
Future<void> deleteCalAscMatSession(int sessionKey); | ||
|
||
Future<void> deleteAllCalAscMatSession(); | ||
|
||
Future<void> addCalAscMatSessionItems(int sessionKey, List<ItemAscensionMaterials> items); | ||
|
||
/// Adds a new calc. item to the provided session by using the [sessionKey]. | ||
/// | ||
/// If [item.useMaterialsFromInventory] is set to false, the same item will be returned without changes. | ||
/// Otherwise, it will be returned with [item.materials] property updated. | ||
Future<ItemAscensionMaterials> addCalAscMatSessionItem(int sessionKey, ItemAscensionMaterials item, {bool redistribute = true}); | ||
|
||
/// Updates the provided item associated to the session [sessionKey] | ||
/// | ||
/// The item will be retrieved using the current value of [item.position] | ||
/// and it will also be updated to the new position provided by [newItemPosition] | ||
/// | ||
/// If [item.useMaterialsFromInventory] is set to false, the same item will be returned without changes. | ||
/// Otherwise, it will be returned with [item.materials] property updated. | ||
Future<ItemAscensionMaterials> updateCalAscMatSessionItem( | ||
int sessionKey, | ||
int newItemPosition, | ||
ItemAscensionMaterials item, { | ||
bool redistribute = true, | ||
}); | ||
|
||
Future<void> deleteCalAscMatSessionItem(int sessionKey, int itemIndex, {bool redistribute = true}); | ||
|
||
Future<void> deleteAllCalAscMatSessionItems(int sessionKey); | ||
|
||
/// This method redistributes all the materials in the inventory by calling [redistributeInventoryMaterial] | ||
/// for each of the available sessions. | ||
/// | ||
/// This method should only be called when the priority of a session or calc. session changes | ||
Future<void> redistributeAllInventoryMaterials(); | ||
|
||
/// This method redistributes the material associated to [itemKey] based on the [newQuantity] | ||
/// | ||
/// This method should only be called when the quantity of a material changes | ||
/// | ||
/// | ||
/// E.g: If we now have more, we may update the used quantity in a [InventoryUsedItem] to use more, | ||
/// otherwise we may reduce the used quantity or even delete the whole thing | ||
Future<void> redistributeInventoryMaterial(String itemKey, int newQuantity); | ||
} |
Oops, something went wrong.