Skip to content

Commit

Permalink
1.7.3 - New tab showing played games history (#146)
Browse files Browse the repository at this point in the history
* progress on play history page

* progress on grouping and UI of the play history page

* updating UI of the play history item

* fixing an issue with null reference when removing bgg games

* ensuring that play history updates when playthroughs updated

* adding empty state to the play history page
  • Loading branch information
mkieres authored Nov 19, 2022
1 parent bb53909 commit 251b574
Show file tree
Hide file tree
Showing 56 changed files with 2,238 additions and 425 deletions.
2 changes: 2 additions & 0 deletions board_games_companion/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BoardGamesCompanionAppState extends State<BoardGamesCompanionApp> {
viewModel.setBoardGameId(arguments.boardGameId);
viewModel.setBoardGameName(arguments.boardGameName);
viewModel.setBoardGameImageUrl(arguments.boardGameImageUrl);
viewModel.setBoardGameImageHeroId(arguments.boardGameImageHeroId);

return MaterialPageRoute<dynamic>(
settings: routeSettings,
Expand All @@ -98,6 +99,7 @@ class BoardGamesCompanionAppState extends State<BoardGamesCompanionApp> {

final viewModel = getIt<PlaythroughsViewModel>();
viewModel.setBoardGame(arguments.boardGameDetails);
viewModel.setBoardGameImageHeroId(arguments.boardGameImageHeroId);

return MaterialPageRoute<dynamic>(
settings: routeSettings,
Expand Down
16 changes: 16 additions & 0 deletions board_games_companion/lib/common/app_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class AppText {

static const goBack = 'Go Back';

static const today = 'today';
static const yesteday = 'yesterday';
static const dayBeforeYesteday = 'day before yesterday';
static const daysAgoFormat = '%s days ago';

static const homePageGamesTabTitle = 'Games';
static const homePageSearchTabTitle = 'Search';
static const homePageGamesHistoryTabTitle = 'Play History';
static const homePageGamesPlayersTabTitle = 'Players';

static const aboutPageAuthorSectionTitle = 'Author';
static const aboutPageDesignAndArtSectionTitle = 'Design & Art';
static const aboutPageContentAndDataSectionTitle = 'Content & Data';
Expand Down Expand Up @@ -172,6 +182,11 @@ class AppText {
static const settingsPageRestoreFailedMessage =
'Unfortunately we ran into a problem with restoring your data. Please try again or contact support at [email protected]';

static const playHistoryPageEmptyTitle = "You haven't played any games yet";
static const playHistoryPageEmptyTextPartOne = 'Nothing to worry about though! ';
static const playHistoryPageEmptyTextPartTwo =
'Start recording your plays in the app and this screen will automatically populate with a history of your playthroughs.';

static const gamePlaytimeFormat = '%s min';
static const gamePlayersSingularFormat = '%i players';
static const gamePlayersPluralFormat = '%i players';
Expand All @@ -181,6 +196,7 @@ class AppText {
static const collectionsPageTitle = 'Collections';
static const settingsPageTitle = 'Settings';
static const newPlayerPageTitle = 'New Player';
static const playHistoryPageTitle = 'Play History';

static const drawerVersionFormat = 'Version %s';
static const drawerReleaseNotes = 'Release notes';
Expand Down
3 changes: 3 additions & 0 deletions board_games_companion/lib/common/dimensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Dimensions {

static const double boardGameDetailsImageHeight = 80;

static const double emptyPageTitleTopSpacing = 40;
static const double emptyPageTitleIconSize = 80;

static const double extraSmallFontSize = 10;
static const double smallFontSize = 12;
static const double standardFontSize = 14;
Expand Down
47 changes: 36 additions & 11 deletions board_games_companion/lib/extensions/date_time_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:board_games_companion/common/app_text.dart';
import 'package:intl/intl.dart';
import 'package:sprintf/sprintf.dart';

import '../common/constants.dart';

Expand All @@ -20,24 +22,47 @@ extension DateTimeExtensions on DateTime? {
}

String toDaysAgo() {
const String daysAgoText = 'days ago';
if (this == null) {
return '- $daysAgoText';
return sprintf(AppText.daysAgoFormat, ['-']);
}

final nowUtc = DateTime.now().toUtc();
final daysAgo = nowUtc.difference(this!).inDays;
if (daysAgo == 0) {
return 'today';
if (isToday) {
return AppText.today;
}
if (daysAgo == 1) {
return 'yesterday';
if (isYesterday) {
return AppText.yesteday;
}
if (daysAgo == 2) {
return 'day before yesterday';
if (isDayBeforeYesterday) {
return AppText.dayBeforeYesteday;
}

return '$daysAgo $daysAgoText';
return sprintf(AppText.daysAgoFormat, [daysAgo]);
}

int get daysAgo {
final nowUtc = DateTime.now().toUtc();
return nowUtc.difference(this!).inDays;
}

bool get isToday {
final nowUtc = DateTime.now().toUtc();
final daysAgo = nowUtc.difference(this!).inDays;

return daysAgo == 0;
}

bool get isYesterday {
final nowUtc = DateTime.now().toUtc();
final daysAgo = nowUtc.difference(this!).inDays;

return daysAgo == 1;
}

bool get isDayBeforeYesterday {
final nowUtc = DateTime.now().toUtc();
final daysAgo = nowUtc.difference(this!).inDays;

return daysAgo == 2;
}

int safeCompareTo(DateTime? dateTimeToCompare) {
Expand Down
2 changes: 1 addition & 1 deletion board_games_companion/lib/extensions/int_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension IntExtensions on int? {
}
}

String toPlaytimeDuration([String? fallbackValue, bool showSeconds = true]) {
String toPlaytimeDuration({String? fallbackValue, bool showSeconds = true}) {
if (this == null) {
return fallbackValue ?? '';
}
Expand Down
12 changes: 12 additions & 0 deletions board_games_companion/lib/extensions/player_score_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import '../common/enums/game_winning_condition.dart';
import '../extensions/scores_extensions.dart';
import '../models/player_score.dart';

extension PlayerScoresExtesions on List<PlayerScore> {
List<PlayerScore> sortByScore(GameWinningCondition winningCondition) {
return this
..sort((PlayerScore playerScore, PlayerScore otherPlayerScore) {
return compareScores(playerScore.score, otherPlayerScore.score, winningCondition);
});
}
}
88 changes: 49 additions & 39 deletions board_games_companion/lib/extensions/scores_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import 'package:board_games_companion/common/enums/game_winning_condition.dart';

import '../models/hive/score.dart';

extension ScoreExtesions on Score {
String toMapKey() {
return '$playthroughId$playerId';
}
}

extension ScoresExtesions on List<Score>? {
List<Score> onlyScoresWithValue() {
return this
Expand All @@ -16,45 +22,7 @@ extension ScoresExtesions on List<Score>? {
List<Score>? sortByScore(GameWinningCondition winningCondition) {
return this
?..sort((Score score, Score otherScore) {
switch (winningCondition) {
case GameWinningCondition.LowestScore:
// MK Swap scores around
final buffer = otherScore;
otherScore = score;
score = buffer;
break;
case GameWinningCondition.HighestScore:
// MK No swapping needed
break;
}

if (score.value == null && otherScore.value == null) {
return Constants.leaveAsIs;
}

if (score.value == null) {
return Constants.moveBelow;
}

if (otherScore.value == null) {
return Constants.moveAbove;
}

final num? aNumber = num.tryParse(score.value!);
final num? bNumber = num.tryParse(otherScore.value!);
if (aNumber == null && bNumber == null) {
return Constants.leaveAsIs;
}

if (aNumber == null) {
return Constants.moveBelow;
}

if (bNumber == null) {
return Constants.moveAbove;
}

return bNumber.compareTo(aNumber);
return compareScores(score, otherScore, winningCondition);
});
}

Expand Down Expand Up @@ -84,3 +52,45 @@ extension ScoresExtesions on List<Score>? {
return scores.reduce((a, b) => a + b) / scores.length;
}
}

int compareScores(Score score, Score otherScore, GameWinningCondition winningCondition) {
switch (winningCondition) {
case GameWinningCondition.LowestScore:
// MK Swap scores around
final buffer = otherScore;
otherScore = score;
score = buffer;
break;
case GameWinningCondition.HighestScore:
// MK No swapping needed
break;
}

if (score.value == null && otherScore.value == null) {
return Constants.leaveAsIs;
}

if (score.value == null) {
return Constants.moveBelow;
}

if (otherScore.value == null) {
return Constants.moveAbove;
}

final num? aNumber = num.tryParse(score.value!);
final num? bNumber = num.tryParse(otherScore.value!);
if (aNumber == null && bNumber == null) {
return Constants.leaveAsIs;
}

if (aNumber == null) {
return Constants.moveBelow;
}

if (bNumber == null) {
return Constants.moveAbove;
}

return bNumber.compareTo(aNumber);
}
8 changes: 8 additions & 0 deletions board_games_companion/lib/extensions/string_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ extension StringExtensions on String? {

return this!.compareTo(stringToCompare!);
}

String toCapitalized() {
if (this == null) {
return '';
}

return this!.isNotEmpty ? '${this![0].toUpperCase()}${this!.substring(1).toLowerCase()}' : '';
}
}
Loading

0 comments on commit 251b574

Please sign in to comment.