Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Application] Added initial banner history item impl.
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
lib/application/banner_history_item/banner_history_item_bloc.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,31 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:shiori/domain/models/models.dart'; | ||
import 'package:shiori/domain/services/genshin_service.dart'; | ||
import 'package:shiori/domain/services/telemetry_service.dart'; | ||
|
||
part 'banner_history_item_bloc.freezed.dart'; | ||
part 'banner_history_item_event.dart'; | ||
part 'banner_history_item_state.dart'; | ||
|
||
class BannerHistoryItemBloc extends Bloc<BannerHistoryItemEvent, BannerHistoryItemState> { | ||
final GenshinService _genshinService; | ||
final TelemetryService _telemetryService; | ||
|
||
BannerHistoryItemBloc(this._genshinService, this._telemetryService) : super(const BannerHistoryItemState.loading()); | ||
|
||
@override | ||
Stream<BannerHistoryItemState> mapEventToState(BannerHistoryItemEvent event) async* { | ||
final s = await event.map( | ||
init: (e) => _init(e.version), | ||
); | ||
|
||
yield s; | ||
} | ||
|
||
Future<BannerHistoryItemState> _init(double version) async { | ||
await _telemetryService.trackBannerHistoryItemOpened(version); | ||
final banners = _genshinService.getBanners(version); | ||
return BannerHistoryItemState.loadedState(version: version, items: banners); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
lib/application/banner_history_item/banner_history_item_event.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,8 @@ | ||
part of 'banner_history_item_bloc.dart'; | ||
|
||
@freezed | ||
class BannerHistoryItemEvent with _$BannerHistoryItemEvent { | ||
const factory BannerHistoryItemEvent.init({ | ||
required double version, | ||
}) = _Init; | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/application/banner_history_item/banner_history_item_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,11 @@ | ||
part of 'banner_history_item_bloc.dart'; | ||
|
||
@freezed | ||
class BannerHistoryItemState with _$BannerHistoryItemState { | ||
const factory BannerHistoryItemState.loading() = _LoadingState; | ||
|
||
const factory BannerHistoryItemState.loadedState({ | ||
required double version, | ||
required List<BannerHistoryPeriodModel> items, | ||
}) = _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