Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
269 additions
and
49 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
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
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
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,6 +1,17 @@ | ||
part of 'materials_bloc.dart'; | ||
|
||
@freezed | ||
abstract class MaterialsEvent with _$MaterialsEvent { | ||
abstract class MaterialsEvent implements _$MaterialsEvent { | ||
const factory MaterialsEvent.init() = _Init; | ||
const factory MaterialsEvent.searchChanged({ | ||
@required String search, | ||
}) = _SearchChanged; | ||
|
||
const factory MaterialsEvent.rarityChanged(int rarity) = _RarityChanged; | ||
const factory MaterialsEvent.typeChanged(MaterialType type) = _TypeChanged; | ||
const factory MaterialsEvent.filterTypeChanged(MaterialFilterType type) = _FilterTypeChanged; | ||
const factory MaterialsEvent.applyFilterChanges() = _ApplyFilterChanges; | ||
const factory MaterialsEvent.sortDirectionTypeChanged(SortDirectionType sortDirectionType) = _SortDirectionTypeChanged; | ||
|
||
const factory MaterialsEvent.cancelChanges() = _CancelChanges; | ||
} |
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,10 +1,19 @@ | ||
part of 'materials_bloc.dart'; | ||
|
||
@freezed | ||
abstract class MaterialsState with _$MaterialsState { | ||
abstract class MaterialsState implements _$MaterialsState { | ||
const factory MaterialsState.loading() = _LoadingState; | ||
|
||
const factory MaterialsState.loaded({ | ||
@required List<TodayCharAscensionMaterialsModel> charAscMaterials, | ||
@required List<TodayWeaponAscensionMaterialModel> weaponAscMaterials, | ||
@required List<MaterialCardModel> materials, | ||
String search, | ||
@required int rarity, | ||
@required int tempRarity, | ||
@required MaterialFilterType filterType, | ||
@required MaterialFilterType tempFilterType, | ||
@required MaterialType type, | ||
@required MaterialType tempType, | ||
@required SortDirectionType sortDirectionType, | ||
@required SortDirectionType tempSortDirectionType, | ||
}) = _LoadedState; | ||
} |
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,64 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:genshindb/domain/models/models.dart'; | ||
import 'package:genshindb/domain/services/genshin_service.dart'; | ||
import 'package:genshindb/domain/services/telemetry_service.dart'; | ||
|
||
part 'today_materials_bloc.freezed.dart'; | ||
part 'today_materials_event.dart'; | ||
part 'today_materials_state.dart'; | ||
|
||
class TodayMaterialsBloc extends Bloc<TodayMaterialsEvent, TodayMaterialsState> { | ||
final GenshinService _genshinService; | ||
final TelemetryService _telemetryService; | ||
|
||
TodayMaterialsBloc(this._genshinService, this._telemetryService) : super(const TodayMaterialsState.loading()); | ||
|
||
@override | ||
Stream<TodayMaterialsState> mapEventToState( | ||
TodayMaterialsEvent event, | ||
) async* { | ||
await _telemetryService.trackAscensionMaterialsOpened(); | ||
final s = event.when( | ||
init: () { | ||
final days = [ | ||
DateTime.monday, | ||
DateTime.tuesday, | ||
DateTime.wednesday, | ||
DateTime.thursday, | ||
DateTime.friday, | ||
DateTime.saturday, | ||
DateTime.sunday, | ||
]; | ||
|
||
final charMaterials = <TodayCharAscensionMaterialsModel>[]; | ||
final weaponMaterials = <TodayWeaponAscensionMaterialModel>[]; | ||
//TODO: YOU MAY WANT TO SHOW THE BOSS ITEMS AS WELL | ||
for (final day in days) { | ||
final charMaterialsForDay = _genshinService.getCharacterAscensionMaterials(day); | ||
final weaponMaterialsForDay = _genshinService.getWeaponAscensionMaterials(day); | ||
|
||
for (final material in charMaterialsForDay) { | ||
if (charMaterials.any((m) => m.name == material.name)) { | ||
continue; | ||
} | ||
charMaterials.add(material); | ||
} | ||
|
||
for (final material in weaponMaterialsForDay) { | ||
if (weaponMaterials.any((m) => m.name == material.name)) { | ||
continue; | ||
} | ||
weaponMaterials.add(material); | ||
} | ||
} | ||
|
||
return TodayMaterialsState.loaded(charAscMaterials: charMaterials, weaponAscMaterials: weaponMaterials); | ||
}, | ||
); | ||
|
||
yield s; | ||
} | ||
} |
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,6 @@ | ||
part of 'today_materials_bloc.dart'; | ||
|
||
@freezed | ||
abstract class TodayMaterialsEvent with _$TodayMaterialsEvent { | ||
const factory TodayMaterialsEvent.init() = _Init; | ||
} |
10 changes: 10 additions & 0 deletions
10
lib/application/today_materials/today_materials_state.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,10 @@ | ||
part of 'today_materials_bloc.dart'; | ||
|
||
@freezed | ||
abstract class TodayMaterialsState with _$TodayMaterialsState { | ||
const factory TodayMaterialsState.loading() = _LoadingState; | ||
const factory TodayMaterialsState.loaded({ | ||
@required List<TodayCharAscensionMaterialsModel> charAscMaterials, | ||
@required List<TodayWeaponAscensionMaterialModel> weaponAscMaterials, | ||
}) = _LoadedState; | ||
} |
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
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
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,18 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:genshindb/domain/enums/material_type.dart'; | ||
|
||
class MaterialCardModel { | ||
final String key; | ||
final String name; | ||
final int rarity; | ||
final String image; | ||
final MaterialType type; | ||
|
||
MaterialCardModel({ | ||
@required this.key, | ||
@required this.name, | ||
@required this.rarity, | ||
@required this.image, | ||
@required this.type, | ||
}); | ||
} |
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
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
Oops, something went wrong.