WT 1.1.26+3 bloc migration
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'package:aitrainer_app/repository/mautic_repository.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:aitrainer_app/main.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_ability.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_device_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -40,13 +33,87 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
|
||||
MenuBloc({required this.menuTreeRepository}) : super(MenuInitial()) {
|
||||
parent = 0;
|
||||
on<MenuCreate>(_onCreate);
|
||||
on<MenuRecreateTree>(_onRecreateTree);
|
||||
on<MenuTreeDown>(_onTreeDown);
|
||||
on<MenuTreeUp>(_onTreeUp);
|
||||
on<MenuTreeJump>(_onTreeJump);
|
||||
on<MenuFilterExerciseType>(_onFilterExercise);
|
||||
}
|
||||
|
||||
void _onCreate(MenuCreate event, Emitter<MenuState> emit) {
|
||||
emit(MenuLoading());
|
||||
if (Cache().getDevices() != null) {
|
||||
exerciseDeviceRepository.setDevices(Cache().getDevices()!);
|
||||
}
|
||||
emit(MenuReady());
|
||||
}
|
||||
|
||||
void _onRecreateTree(MenuRecreateTree event, Emitter<MenuState> emit) {
|
||||
emit(MenuLoading());
|
||||
// ie. at language changes
|
||||
menuTreeRepository.createTree();
|
||||
emit(MenuReady());
|
||||
}
|
||||
|
||||
Future<void> _onTreeDown(MenuTreeDown event, Emitter<MenuState> emit) async {
|
||||
emit(MenuLoading());
|
||||
parent = event.parent;
|
||||
workoutItem = event.item;
|
||||
|
||||
if (workoutItem != null) {
|
||||
setAbility(workoutItem!.internalName);
|
||||
}
|
||||
final LinkedHashMap<String, WorkoutMenuTree> branch = menuTreeRepository.getBranch(event.parent);
|
||||
|
||||
await getImages(branch);
|
||||
emit(MenuReady());
|
||||
}
|
||||
|
||||
Future<void> _onTreeUp(MenuTreeUp event, Emitter<MenuState> emit) async {
|
||||
emit(MenuLoading());
|
||||
// get parent menus or exercises
|
||||
parent = event.parent;
|
||||
workoutItem = menuTreeRepository.getParentItem(parent);
|
||||
|
||||
LinkedHashMap<String, WorkoutMenuTree> branch;
|
||||
if (workoutItem != null) {
|
||||
setAbility(workoutItem!.internalName);
|
||||
branch = menuTreeRepository.getBranch(workoutItem!.parent);
|
||||
await getImages(branch);
|
||||
}
|
||||
emit(MenuReady());
|
||||
}
|
||||
|
||||
Future<void> _onTreeJump(MenuTreeJump event, Emitter<MenuState> emit) async {
|
||||
emit(MenuLoading());
|
||||
parent = event.parent;
|
||||
workoutItem = menuTreeRepository.getParentItem(parent);
|
||||
|
||||
if (workoutItem != null) {
|
||||
setAbility(workoutItem!.internalName);
|
||||
}
|
||||
final LinkedHashMap<String, WorkoutMenuTree> branch = menuTreeRepository.getBranch(workoutItem!.parent);
|
||||
await getImages(branch);
|
||||
emit(MenuReady());
|
||||
}
|
||||
|
||||
Future<void> _onFilterExercise(MenuFilterExerciseType event, Emitter<MenuState> emit) async {
|
||||
emit(MenuLoading());
|
||||
final int deviceId = event.deviceId;
|
||||
if (selectedDevice(deviceId)) {
|
||||
listFilterDevice.add(deviceId);
|
||||
} else {
|
||||
listFilterDevice.remove(deviceId);
|
||||
}
|
||||
emit(MenuReady());
|
||||
}
|
||||
|
||||
void setContext(BuildContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@override
|
||||
/* @override
|
||||
Stream<MenuState> mapEventToState(
|
||||
MenuEvent event,
|
||||
) async* {
|
||||
@@ -141,7 +208,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
} on Exception catch (ex) {
|
||||
yield MenuError(message: ex.toString());
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
void setAbility(String name) {
|
||||
switch (name) {
|
||||
|
||||
@@ -41,14 +41,6 @@ class MenuTreeJump extends MenuEvent {
|
||||
List<Object> get props => [parent];
|
||||
}
|
||||
|
||||
class MenuClickExercise extends MenuEvent {
|
||||
final int exerciseTypeId;
|
||||
const MenuClickExercise({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
}
|
||||
|
||||
class MenuRecreateTree extends MenuEvent {
|
||||
const MenuRecreateTree();
|
||||
}
|
||||
@@ -60,11 +52,3 @@ class MenuFilterExerciseType extends MenuEvent {
|
||||
@override
|
||||
List<Object> get props => [deviceId];
|
||||
}
|
||||
|
||||
class MenuStartTrial extends MenuEvent {
|
||||
final DateTime start;
|
||||
const MenuStartTrial({required this.start});
|
||||
|
||||
@override
|
||||
List<Object> get props => [start];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user