Skip to content

Commit

Permalink
1.7.2 - Tidy (#140)
Browse files Browse the repository at this point in the history
* not showing playthough snackbar when navigating away

* manually logging the screen view analytics
  • Loading branch information
mkieres authored Nov 6, 2022
1 parent 8bc9b68 commit 73a1ae5
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data android:name="flutterEmbedding" android:value="2" />

<!-- MK Disable automatic screen reporting for Firebase analytics https://firebase.google.com/docs/analytics/screenviews#disable_screenview_tracking.
We're traking screen views manually in the analytics_route_observer -->
<meta-data android:name="google_analytics_automatic_screen_reporting_enabled" android:value="false" />
</application>
</manifest>
2 changes: 2 additions & 0 deletions board_games_companion/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
<false />
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>FirebaseAutomaticScreenReportingEnabled</key>
<false/>
</dict>
</plist>
22 changes: 3 additions & 19 deletions board_games_companion/lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:board_games_companion/pages/edit_playthrough/playthrough_note_page.dart';
import 'package:board_games_companion/pages/games/games_view_model.dart';
import 'package:board_games_companion/pages/settings/settings_view_model.dart';
import 'package:firebase_analytics/observer.dart';
import 'package:flutter/material.dart';
Expand All @@ -18,16 +17,13 @@ import 'pages/edit_playthrough/edit_playthrough_page.dart';
import 'pages/edit_playthrough/edit_playthrough_view_model.dart';
import 'pages/edit_playthrough/playthrough_note_view_model.dart';
import 'pages/home/home_page.dart';
import 'pages/home/home_view_model.dart';
import 'pages/players/player_page.dart';
import 'pages/players/players_view_model.dart';
import 'pages/playthroughs/playthroughs_page.dart';
import 'pages/playthroughs/playthroughs_view_model.dart';
import 'pages/search_board_games/search_board_games_view_model.dart';
import 'pages/settings/settings_page.dart';
import 'services/analytics_service.dart';
import 'services/preferences_service.dart';
import 'services/rate_and_review_service.dart';
import 'stores/board_games_filters_store.dart';
import 'utilities/analytics_route_observer.dart';

class BoardGamesCompanionApp extends StatefulWidget {
Expand Down Expand Up @@ -61,23 +57,11 @@ class BoardGamesCompanionAppState extends State<BoardGamesCompanionApp> {
onGenerateRoute: (RouteSettings routeSettings) {
switch (routeSettings.name) {
case HomePage.pageRoute:
final analyticsService = getIt<AnalyticsService>();
final rateAndReviewService = getIt<RateAndReviewService>();
final playersViewModel = getIt<PlayersViewModel>();
final boardGamesFiltersStore = getIt<BoardGamesFiltersStore>();
final gamesViewModel = getIt<GamesViewModel>();
final searchViewModel = getIt<SearchBoardGamesViewModel>();
final viewModel = getIt<HomeViewModel>();

return MaterialPageRoute<dynamic>(
settings: routeSettings,
builder: (_) => HomePage(
analyticsService: analyticsService,
rateAndReviewService: rateAndReviewService,
gamesViewModel: gamesViewModel,
playersViewModel: playersViewModel,
searchViewModel: searchViewModel,
boardGamesFiltersStore: boardGamesFiltersStore,
),
builder: (_) => HomePage(viewModel: viewModel),
);

case BoardGamesDetailsPage.pageRoute:
Expand Down
2 changes: 1 addition & 1 deletion board_games_companion/lib/common/analytics.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Analytics {
static const String filterCollection = 'filter_collection';
static const String sortCollection = 'sort_collection';
static const String viewPage = 'view_page';
static const String viewGameStats = 'view_game_stats';
static const String viewGameDetails = 'view_game_details';
static const String viewHotBoardGame = 'view_hot_board_game';
Expand All @@ -10,6 +9,7 @@ class Analytics {
static const String editPlaythrough = 'edit_playthough';
static const String logPlaythrough = 'log_playthough';
static const String importBggPlays = 'import_bgg_plays';
static const String openGamesPlaylist = 'open_games_playlist';

static const String routeName = 'route_name';

Expand Down
58 changes: 58 additions & 0 deletions board_games_companion/lib/extensions/route_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter/widgets.dart';

import '../pages/about/about_page.dart';
import '../pages/board_game_details/board_game_details_page.dart';
import '../pages/edit_playthrough/edit_playthrough_page.dart';
import '../pages/edit_playthrough/playthrough_note_page.dart';
import '../pages/home/home_page.dart';
import '../pages/players/player_page.dart';
import '../pages/playthroughs/playthroughs_page.dart';
import '../pages/settings/settings_page.dart';

extension RouteExtensions on Route {
String toScreenName() {
switch (settings.name) {
case AboutPage.pageRoute:
return 'About';
case BoardGamesDetailsPage.pageRoute:
return 'Board Games Details';
case EditPlaythroughPage.pageRoute:
return 'Edit Playthrough';
case HomePage.pageRoute:
return 'Home';
case PlaythroughsPage.pageRoute:
return 'Playthroughs';
case PlaythroughNotePage.pageRoute:
return 'Playthrough Note';
case PlayerPage.pageRoute:
return 'Player';
case SettingsPage.pageRoute:
return 'Settings';
default:
return 'Undefined';
}
}

String toScreenClassName() {
switch (settings.name) {
case AboutPage.pageRoute:
return 'AboutPage';
case BoardGamesDetailsPage.pageRoute:
return 'BoardGamesDetailsPage';
case EditPlaythroughPage.pageRoute:
return 'EditPlaythroughPage';
case HomePage.pageRoute:
return 'HomePage';
case PlaythroughsPage.pageRoute:
return 'PlaythroughsPage';
case PlaythroughNotePage.pageRoute:
return 'PlaythroughNotePage';
case PlayerPage.pageRoute:
return 'PlayerPage';
case SettingsPage.pageRoute:
return 'SettingsPage';
default:
return 'Undefined';
}
}
}
12 changes: 10 additions & 2 deletions board_games_companion/lib/injectable.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 10 additions & 24 deletions board_games_companion/lib/pages/home/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import 'package:board_games_companion/pages/games/games_view_model.dart';
import 'package:board_games_companion/pages/players/players_view_model.dart';
import 'package:board_games_companion/pages/search_board_games/search_board_games_view_model.dart';
import 'package:board_games_companion/pages/home/home_view_model.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';

import '../../common/app_colors.dart';
import '../../common/dimensions.dart';
import '../../services/analytics_service.dart';
import '../../services/rate_and_review_service.dart';
import '../../stores/board_games_filters_store.dart';
import '../../widgets/bottom_tab_icon.dart';
import '../../widgets/common/page_container.dart';
import '../base_page_state.dart';
Expand All @@ -19,23 +14,13 @@ import 'home_page_drawer.dart';

class HomePage extends StatefulWidget {
const HomePage({
required this.analyticsService,
required this.rateAndReviewService,
required this.gamesViewModel,
required this.playersViewModel,
required this.searchViewModel,
required this.boardGamesFiltersStore,
required this.viewModel,
Key? key,
}) : super(key: key);

static const String pageRoute = '/home';

final AnalyticsService analyticsService;
final RateAndReviewService rateAndReviewService;
final GamesViewModel gamesViewModel;
final PlayersViewModel playersViewModel;
final SearchBoardGamesViewModel searchViewModel;
final BoardGamesFiltersStore boardGamesFiltersStore;
final HomeViewModel viewModel;

static final GlobalKey<ScaffoldMessengerState> homePageGlobalKey =
GlobalKey<ScaffoldMessengerState>();
Expand Down Expand Up @@ -73,13 +58,13 @@ class HomePageState extends BasePageState<HomePage> with SingleTickerProviderSta
controller: tabController,
children: <Widget>[
GamesPage(
widget.gamesViewModel,
widget.boardGamesFiltersStore,
widget.analyticsService,
widget.rateAndReviewService,
widget.viewModel.gamesViewModel,
widget.viewModel.boardGamesFiltersStore,
widget.viewModel.analyticsService,
widget.viewModel.rateAndReviewService,
),
SearchBoardGamesPage(viewModel: widget.searchViewModel),
PlayersPage(playersViewModel: widget.playersViewModel),
SearchBoardGamesPage(viewModel: widget.viewModel.searchBoardGamesViewModel),
PlayersPage(playersViewModel: widget.viewModel.playersViewModel),
],
),
),
Expand Down Expand Up @@ -108,6 +93,7 @@ class HomePageState extends BasePageState<HomePage> with SingleTickerProviderSta
initialActiveIndex: _initialTabIndex,
activeColor: AppColors.accentColor,
color: AppColors.inactiveBottomTabColor,
onTap: (int tabIndex) => widget.viewModel.trackTabChange(tabIndex),
),
),
);
Expand Down
48 changes: 48 additions & 0 deletions board_games_companion/lib/pages/home/home_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ignore_for_file: library_private_types_in_public_api

import 'package:injectable/injectable.dart';
import 'package:mobx/mobx.dart';
import 'package:tuple/tuple.dart';

import '../../services/analytics_service.dart';
import '../../services/rate_and_review_service.dart';
import '../../stores/board_games_filters_store.dart';
import '../games/games_view_model.dart';
import '../players/players_view_model.dart';
import '../search_board_games/search_board_games_view_model.dart';

part 'home_view_model.g.dart';

@injectable
class HomeViewModel = _HomeViewModelBase with _$HomeViewModel;

abstract class _HomeViewModelBase with Store {
_HomeViewModelBase(
this.analyticsService,
this.rateAndReviewService,
this.playersViewModel,
this.boardGamesFiltersStore,
this.gamesViewModel,
this.searchBoardGamesViewModel,
);

final AnalyticsService analyticsService;
final RateAndReviewService rateAndReviewService;
final PlayersViewModel playersViewModel;
final BoardGamesFiltersStore boardGamesFiltersStore;
final GamesViewModel gamesViewModel;
final SearchBoardGamesViewModel searchBoardGamesViewModel;

static const Map<int, Tuple2<String, String>> _screenViewByTabIndex = {
0: Tuple2<String, String>('Games', 'GamesPage'),
1: Tuple2<String, String>('Search', 'SearchBoardGamesPage'),
2: Tuple2<String, String>('Players', 'PlayersPage'),
};

Future<void> trackTabChange(int tabIndex) async {
await analyticsService.logScreenView(
screenName: _screenViewByTabIndex[tabIndex]!.item1,
screenClass: _screenViewByTabIndex[tabIndex]!.item2,
);
}
}
18 changes: 18 additions & 0 deletions board_games_companion/lib/pages/home/home_view_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 73a1ae5

Please sign in to comment.