Skip to content

Commit

Permalink
Added a char filter to filter via role
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Feb 28, 2021
1 parent da6cadf commit 4db6bd7
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/application/character/character_state.dart
Expand Up @@ -12,7 +12,7 @@ abstract class CharacterState with _$CharacterState {
@required ElementType elementType,
@required WeaponType weaponType,
@required RegionType region,
@required CharacterType role,
@required CharacterRoleType role,
@required bool isFemale,
String birthday,
@required List<CharacterFileAscensionMaterialModel> ascensionMaterials,
Expand Down
15 changes: 12 additions & 3 deletions lib/application/characters/characters_bloc.dart
Expand Up @@ -36,9 +36,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
return currentState.copyWith.call(tempElementTypes: types);
},
rarityChanged: (e) => currentState.copyWith.call(tempRarity: e.rarity),
itemStatusChanged: (e) => currentState.copyWith.call(
tempStatusType: e.statusType,
),
itemStatusChanged: (e) => currentState.copyWith.call(tempStatusType: e.statusType),
sortDirectionTypeChanged: (e) => currentState.copyWith.call(tempSortDirectionType: e.sortDirectionType),
weaponTypeChanged: (e) {
var types = <WeaponType>[];
Expand All @@ -49,6 +47,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
}
return currentState.copyWith.call(tempWeaponTypes: types);
},
roleTypeChanged: (e) => currentState.copyWith.call(tempRoleType: e.roleType),
searchChanged: (e) => _buildInitialState(
search: e.search,
characterFilterType: currentState.characterFilterType,
Expand All @@ -57,6 +56,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
statusType: currentState.statusType,
sortDirectionType: currentState.sortDirectionType,
weaponTypes: currentState.weaponTypes,
roleType: currentState.tempRoleType,
),
applyFilterChanges: (_) => _buildInitialState(
search: currentState.search,
Expand All @@ -66,6 +66,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
statusType: currentState.tempStatusType,
sortDirectionType: currentState.tempSortDirectionType,
weaponTypes: currentState.tempWeaponTypes,
roleType: currentState.tempRoleType,
),
cancelChanges: (_) => currentState.copyWith.call(
tempCharacterFilterType: currentState.characterFilterType,
Expand All @@ -74,6 +75,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
tempStatusType: currentState.statusType,
tempSortDirectionType: currentState.sortDirectionType,
tempWeaponTypes: currentState.weaponTypes,
tempRoleType: currentState.roleType,
),
);
yield s;
Expand All @@ -88,6 +90,7 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
ItemStatusType statusType = ItemStatusType.all,
CharacterFilterType characterFilterType = CharacterFilterType.name,
SortDirectionType sortDirectionType = SortDirectionType.asc,
CharacterRoleType roleType = CharacterRoleType.all,
}) {
final isLoaded = state is _LoadedState;
var characters = _genshinService.getCharactersForCard();
Expand All @@ -112,6 +115,8 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
sortDirectionType: sortDirectionType,
tempSortDirectionType: sortDirectionType,
showCharacterDetails: _settingsService.showCharacterDetails,
roleType: roleType,
tempRoleType: roleType,
);
}

Expand All @@ -131,6 +136,10 @@ class CharactersBloc extends Bloc<CharactersEvent, CharactersState> {
characters = characters.where((el) => elementTypes.contains(el.elementType)).toList();
}

if (roleType != CharacterRoleType.all) {
characters = characters.where((el) => el.roleType == roleType).toList();
}

switch (statusType) {
case ItemStatusType.released:
characters = characters.where((el) => !el.isComingSoon).toList();
Expand Down
7 changes: 3 additions & 4 deletions lib/application/characters/characters_event.dart
Expand Up @@ -11,10 +11,9 @@ abstract class CharactersEvent with _$CharactersEvent {
const factory CharactersEvent.elementTypeChanged(ElementType elementType) = _ElementTypesChanged;
const factory CharactersEvent.rarityChanged(int rarity) = _RarityChanged;
const factory CharactersEvent.itemStatusChanged(ItemStatusType statusType) = _ReleasedUnreleasedTypeChanged;
const factory CharactersEvent.characterFilterTypeChanged(CharacterFilterType characterFilterType) =
_CharacterFilterChanged;
const factory CharactersEvent.sortDirectionTypeChanged(SortDirectionType sortDirectionType) =
_SortDirectionTypeChanged;
const factory CharactersEvent.characterFilterTypeChanged(CharacterFilterType characterFilterType) = _CharacterFilterChanged;
const factory CharactersEvent.sortDirectionTypeChanged(SortDirectionType sortDirectionType) = _SortDirectionTypeChanged;
const factory CharactersEvent.roleTypeChanged(CharacterRoleType roleType) = _CharacterTypeChanged;

const factory CharactersEvent.applyFilterChanges() = _ApplyFilterChanges;
const factory CharactersEvent.cancelChanges() = _CancelChanges;
Expand Down
2 changes: 2 additions & 0 deletions lib/application/characters/characters_state.dart
Expand Up @@ -19,5 +19,7 @@ abstract class CharactersState with _$CharactersState {
@required CharacterFilterType tempCharacterFilterType,
@required SortDirectionType sortDirectionType,
@required SortDirectionType tempSortDirectionType,
@required CharacterRoleType roleType,
@required CharacterRoleType tempRoleType,
}) = _LoadedState;
}
5 changes: 3 additions & 2 deletions lib/application/weapons/weapons_bloc.dart
Expand Up @@ -37,16 +37,17 @@ class WeaponsBloc extends Bloc<WeaponsEvent, WeaponsState> {
}
return currentState.copyWith.call(tempWeaponTypes: types);
},
weaponSubStatTypeChanged: (e) => currentState.copyWith.call(tempWeaponSubStatType: e.subStatType),
weaponLocationTypeChanged: (e) => currentState.copyWith.call(tempWeaponLocationType: e.locationType),
searchChanged: (e) => _buildInitialState(
search: e.search,
weaponFilterType: currentState.weaponFilterType,
rarity: currentState.rarity,
sortDirectionType: currentState.sortDirectionType,
weaponTypes: currentState.weaponTypes,
weaponSubStatType: currentState.weaponSubStatType,
locationType: currentState.weaponLocationType,
),
weaponSubStatTypeChanged: (e) => currentState.copyWith.call(tempWeaponSubStatType: e.subStatType),
weaponLocationTypeChanged: (e) => currentState.copyWith.call(tempWeaponLocationType: e.locationType),
applyFilterChanges: (_) => _buildInitialState(
search: currentState.search,
weaponFilterType: currentState.tempWeaponFilterType,
Expand Down
@@ -1,4 +1,5 @@
enum CharacterType {
enum CharacterRoleType {
all,
mainDps,
supportDps,
utility,
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/enums/enums.dart
Expand Up @@ -6,9 +6,9 @@ export 'artifact_filter_type.dart';
export 'artifact_type.dart';
export 'ascension_material_summary_type.dart';
export 'character_filter_type.dart';
export 'character_role_type.dart';
export 'character_skill_ability_type.dart';
export 'character_skill_type.dart';
export 'character_type.dart';
export 'day_type.dart';
export 'element_type.dart';
export 'item_location_type.dart';
Expand Down
5 changes: 3 additions & 2 deletions lib/domain/models/characters/character_card_model.dart
@@ -1,7 +1,6 @@
import 'package:flutter/widgets.dart';

import '../../enums/element_type.dart';
import '../../enums/weapon_type.dart';
import '../../enums/enums.dart';

class CharacterCardModel {
final String key;
Expand All @@ -13,6 +12,7 @@ class CharacterCardModel {
final bool isNew;
final bool isComingSoon;
final List<String> materials;
final CharacterRoleType roleType;

const CharacterCardModel({
@required this.key,
Expand All @@ -22,6 +22,7 @@ class CharacterCardModel {
@required this.weaponType,
@required this.elementType,
@required this.materials,
@required this.roleType,
this.isNew = false,
this.isComingSoon = false,
});
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/models/db/characters/character_file_model.dart
Expand Up @@ -3,9 +3,9 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:genshindb/domain/enums/enums.dart';

import '../../../assets.dart';
import '../../../enums/character_role_type.dart';
import '../../../enums/character_skill_ability_type.dart';
import '../../../enums/character_skill_type.dart';
import '../../../enums/character_type.dart';
import '../../../enums/element_type.dart';
import '../../../enums/region_type.dart';
import '../../../enums/weapon_type.dart';
Expand All @@ -28,7 +28,7 @@ abstract class CharacterFileModel implements _$CharacterFileModel {
@required bool isFemale,
@required bool isComingSoon,
@required bool isNew,
@required CharacterType role,
@required CharacterRoleType role,
@required String tier,
String birthday,
@required List<CharacterFileAscensionMaterialModel> ascensionMaterials,
Expand Down
1 change: 1 addition & 0 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -110,6 +110,7 @@ class GenshinServiceImpl implements GenshinService {
weaponType: e.weaponType,
isComingSoon: e.isComingSoon,
isNew: e.isNew,
roleType: e.role,
);
},
).toList();
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/artifacts/widgets/artifact_card.dart
Expand Up @@ -58,7 +58,7 @@ class ArtifactCard extends StatelessWidget {
elevation: withElevation ? Styles.cardTenElevation : 0,
gradient: rarity.getRarityGradient(),
child: Padding(
padding: Styles.edgeInsetAll5,
padding: withoutDetails ? Styles.edgeInsetAll5 : Styles.edgeInsetAll10,
child: Column(
children: [
FadeInImage(
Expand Down
Expand Up @@ -56,6 +56,14 @@ class CharacterBottomSheet extends StatelessWidget {
ButtonBar(
alignment: MainAxisAlignment.spaceEvenly,
children: [
ItemPopupMenuFilter<CharacterRoleType>(
tooltipText: s.role,
values: CharacterRoleType.values.where((el) => el != CharacterRoleType.na).toList(),
selectedValue: state.tempRoleType,
onSelected: (v) => context.read<CharactersBloc>().add(CharactersEvent.roleTypeChanged(v)),
itemText: (val) => s.translateCharacterType(val),
icon: const Icon(GenshinDb.trefoil_lily, size: 18),
),
ItemPopupMenuFilter<ItemStatusType>(
tooltipText: '${s.released} / ${s.brandNew} / ${s.comingSoon}',
values: ItemStatusType.values,
Expand Down
12 changes: 7 additions & 5 deletions lib/presentation/shared/extensions/i18n_extensions.dart
Expand Up @@ -240,16 +240,18 @@ extension I18nExtensions on S {
}
}

String translateCharacterType(CharacterType type) {
String translateCharacterType(CharacterRoleType type) {
switch (type) {
case CharacterType.mainDps:
case CharacterRoleType.mainDps:
return mainDps;
case CharacterType.supportDps:
case CharacterRoleType.supportDps:
return supportDps;
case CharacterType.utility:
case CharacterRoleType.utility:
return utility;
case CharacterType.na:
case CharacterRoleType.na:
return na;
case CharacterRoleType.all:
return all;
default:
throw Exception('Invalid character type = $type');
}
Expand Down

0 comments on commit 4db6bd7

Please sign in to comment.