Skip to content

Commit

Permalink
[Presentation] Added a dialog to show the release history of an item.
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
Wolfteam committed Apr 19, 2022
1 parent 5d2cd30 commit 1fc468d
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 183 deletions.
19 changes: 19 additions & 0 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -918,6 +918,25 @@ class GenshinServiceImpl implements GenshinService {
.toList()
..sort((x, y) => x.from.compareTo(y.from));

@override
List<ItemReleaseHistoryModel> getItemReleaseHistory(String itemKey) {
final history = _bannerHistoryFile.banners
.where((el) => el.itemKeys.contains(itemKey))
.map((e) => ItemReleaseHistoryModel(version: e.version, dates: [ItemReleaseHistoryDatesModel(from: e.from, until: e.until)]))
.toList();

if (history.isEmpty) {
throw Exception('There is no banner history associated to itemKey = $itemKey');
}

return history
.groupListsBy((el) => el.version)
.entries
.map((e) => ItemReleaseHistoryModel(version: e.key, dates: e.value.expand((el) => el.dates).toList()))
.toList()
..sort((x, y) => x.version.compareTo(y.version));
}

CharacterCardModel _toCharacterForCard(CharacterFileModel character) {
final translation = getCharacterTranslation(character.key);

Expand Down
3 changes: 3 additions & 0 deletions lib/infrastructure/telemetry/telemetry_service.dart
Expand Up @@ -165,4 +165,7 @@ class TelemetryServiceImpl implements TelemetryService {

@override
Future<void> trackBannerHistoryItemOpened(double version) => trackEventAsync('Banner-History-Item-Opened', {'Version': '$version'});

@override
Future<void> trackItemReleaseHistoryOpened(String itemKey) => trackEventAsync('Banner-History-Item-Release-History-Opened', {'ItemKey': itemKey});
}
6 changes: 6 additions & 0 deletions lib/injection.dart
Expand Up @@ -156,6 +156,12 @@ class Injection {
return BannerHistoryItemBloc(genshinService, telemetryService);
}

static ItemReleaseHistoryBloc get itemReleaseHistoryBloc {
final genshinService = getIt<GenshinService>();
final telemetryService = getIt<TelemetryService>();
return ItemReleaseHistoryBloc(genshinService, telemetryService);
}

//TODO: USE THIS PROP
// static CalculatorAscMaterialsItemBloc get calculatorAscMaterialsItemBloc {
// final genshinService = getIt<GenshinService>();
Expand Down
5 changes: 4 additions & 1 deletion lib/l10n/intl_en.arb
Expand Up @@ -425,5 +425,8 @@
"nameAsc": "Name asc.",
"nameDesc": "Name desc.",
"versionAsc": "Version asc.",
"versionDesc": "Version desc."
"versionDesc": "Version desc.",
"releaseHistory": "Release History",
"selectAnOption": "Select an option",
"details": "Details"
}
100 changes: 94 additions & 6 deletions lib/presentation/banner_history/banner_history_page.dart
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:responsive_builder/responsive_builder.dart';
import 'package:shiori/application/bloc.dart';
import 'package:shiori/domain/enums/enums.dart';
import 'package:shiori/domain/extensions/string_extensions.dart';
import 'package:shiori/domain/models/models.dart';
import 'package:shiori/generated/l10n.dart';
import 'package:shiori/injection.dart';
import 'package:shiori/presentation/banner_history/widgets/content.dart';
Expand All @@ -13,9 +16,11 @@ import 'package:shiori/presentation/shared/item_popupmenu_filter.dart';
import 'package:shiori/presentation/shared/mixins/app_fab_mixin.dart';
import 'package:shiori/presentation/shared/sync_controller.dart';

const double _firstCellWidth = 150;
const double _tabletFirstCellWidth = 150;
const double _mobileFirstCellWidth = 120;
const double _firstCellHeight = 70;
const double _cellWidth = 100;
const double _tabletCellWidth = 100;
const double _mobileCellWidth = 80;
const double _cellHeight = 120;

class BannerHistoryPage extends StatefulWidget {
Expand All @@ -41,6 +46,12 @@ class _BannerHistoryPageState extends State<BannerHistoryPage> with SingleTicker
@override
Widget build(BuildContext context) {
const margin = EdgeInsets.all(4.0);
double firstCellWidth = _tabletFirstCellWidth;
double cellWidth = _tabletCellWidth;
if (getDeviceType(MediaQuery.of(context).size) == DeviceScreenType.mobile) {
firstCellWidth = _mobileFirstCellWidth;
cellWidth = _mobileCellWidth;
}
return BlocProvider(
create: (_) => Injection.bannerHistoryBloc..add(const BannerHistoryEvent.init()),
child: Scaffold(
Expand All @@ -62,9 +73,9 @@ class _BannerHistoryPageState extends State<BannerHistoryPage> with SingleTicker
versions: state.versions,
selectedVersions: state.selectedVersions,
margin: margin,
firstCellWidth: _firstCellWidth,
firstCellWidth: firstCellWidth,
firstCellHeight: _firstCellHeight,
cellWidth: _cellWidth,
cellWidth: cellWidth,
cellHeight: 60,
),
),
Expand All @@ -79,7 +90,7 @@ class _BannerHistoryPageState extends State<BannerHistoryPage> with SingleTicker
BlocBuilder<BannerHistoryBloc, BannerHistoryState>(
builder: (ctx, state) => FixedLeftColumn(
margin: margin,
cellWidth: _firstCellWidth,
cellWidth: firstCellWidth,
cellHeight: _cellHeight,
items: state.banners,
),
Expand All @@ -98,7 +109,7 @@ class _BannerHistoryPageState extends State<BannerHistoryPage> with SingleTicker
banners: state.banners,
versions: state.versions,
margin: margin,
cellWidth: _cellWidth,
cellWidth: cellWidth,
cellHeight: _cellHeight,
),
),
Expand Down Expand Up @@ -131,6 +142,21 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
builder: (ctx, state) => AppBar(
title: Text(s.bannerHistory),
actions: [
IconButton(
icon: const Icon(Icons.search),
onPressed: () => showSearch<List<String>>(
context: context,
delegate: _AppBarSearchDelegate(
ctx.read<BannerHistoryBloc>().getItemsForSearch(),
[...state.selectedItemKeys],
),
).then((keys) {
if (keys == null) {
return;
}
context.read<BannerHistoryBloc>().add(BannerHistoryEvent.itemsSelected(keys: keys));
}),
),
ItemPopupMenuFilter<BannerHistoryItemType>(
tooltipText: s.bannerType,
selectedValue: state.type,
Expand All @@ -155,3 +181,65 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}

class _AppBarSearchDelegate extends SearchDelegate<List<String>> {
final List<ItemCommonWithName> items;
final List<String> selected;

_AppBarSearchDelegate(this.items, this.selected);

@override
List<Widget> buildActions(BuildContext context) => [
IconButton(
icon: const Icon(Icons.check, color: Colors.green),
onPressed: () => close(context, selected),
),
IconButton(
icon: const Icon(Icons.clear, color: Colors.red),
onPressed: () {
if (query.isNullEmptyOrWhitespace) {
close(context, []);
} else {
query = '';
}
},
)
];

@override
Widget buildLeading(BuildContext context) => IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => close(context, selected),
);

@override
Widget buildResults(BuildContext context) => Text(query);

@override
Widget buildSuggestions(BuildContext context) {
final possibilities = query.isNullEmptyOrWhitespace ? items : items.where((el) => el.name.toLowerCase().contains(query.toLowerCase())).toList();
possibilities.sort((x, y) => x.name.compareTo(y.name));

return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) => ListView.builder(
itemCount: possibilities.length,
itemBuilder: (ctx, index) {
final item = possibilities[index];
final isSelected = selected.any((el) => el == item.key);
return ListTile(
title: Text(item.name),
leading: isSelected ? const Icon(Icons.check) : null,
minLeadingWidth: 10,
onTap: () {
if (isSelected) {
setState(() => selected.remove(item.key));
} else {
setState(() => selected.add(item.key));
}
},
);
},
),
);
}
}
3 changes: 1 addition & 2 deletions lib/presentation/banner_history/widgets/content.dart
Expand Up @@ -65,7 +65,6 @@ class _ContentCard extends StatelessWidget {
return SizedBox.fromSize(size: Size(cellWidth + margin.horizontal, cellHeight + margin.vertical));
}
final theme = Theme.of(context);
//TODO: LIGHT COLOR
return SizedBox(
child: Container(
width: cellWidth,
Expand All @@ -74,7 +73,7 @@ class _ContentCard extends StatelessWidget {
child: Container(
alignment: Alignment.center,
margin: const EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10),
color: theme.colorScheme.background.withOpacity(0.2),
color: theme.brightness == Brightness.dark ? theme.colorScheme.background.withOpacity(0.2) : theme.dividerColor,
child: number != null
? Text(
'$number',
Expand Down

0 comments on commit 1fc468d

Please sign in to comment.