Skip to content

Commit

Permalink
Merge pull request #161 from LittleLightForDestiny/quickfixes
Browse files Browse the repository at this point in the history
fixing equipment page and adding better error logging
  • Loading branch information
joaopmarquesini authored Feb 19, 2022
2 parents 8260fd7 + cef7a46 commit 85149fa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 57 deletions.
91 changes: 41 additions & 50 deletions lib/pages/equipment/equipment.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,29 @@ class EquipmentScreenState extends State<EquipmentScreen>
int currentGroup = DestinyItemCategory.Weapon;
Map<int, double> scrollPositions = Map();

// TabController charTabController;
// TabController typeTabController;
StreamSubscription<NotificationEvent> subscription;

get totalCharacterTabs => (characters?.length ?? 0) + 1;
TabController _charTabController;
TabController get charTabController {
final totalCharacterTabs = (characters?.length ?? 0) + 1;
final current = _charTabController;
if (current != null && current?.length == totalCharacterTabs) return current;
_charTabController = TabController(length: totalCharacterTabs, vsync: this, initialIndex: current?.index ?? 0);
return _charTabController;
}

TabController _typeTabController;
TabController get typeTabController {
final current = _typeTabController;
final length = widget.itemTypes.length;
if (current != null && current?.length == length) return current;
_typeTabController = TabController(
initialIndex: current?.index ?? 0,
length: length,
vsync: this,
);
return _typeTabController;
}

@override
void initState() {
Expand Down Expand Up @@ -85,37 +103,21 @@ class EquipmentScreenState extends State<EquipmentScreen>
Widget build(BuildContext context) {
super.build(context);

final typeTabController = TabController(
initialIndex: 0,
length: widget.itemTypes.length,
vsync: this,
);
final charTabController = TabController(
initialIndex: 0,
length: totalCharacterTabs,
vsync: this,
);

var query = MediaQueryHelper(context);
if (query.isLandscape || query.tabletOrBigger) {
return buildTablet(
context,
typeTabController,
charTabController,
);
return buildTablet(context);
}

return buildPhone(context, typeTabController, charTabController);
return buildPhone(context);
}

Widget buildTablet(BuildContext context, TabController typeTabController, TabController charTabController) {
Widget buildTablet(BuildContext context) {
EdgeInsets screenPadding = MediaQuery.of(context).padding;
return Material(
child: Stack(
children: <Widget>[
buildBackground(context, charTabController),
Positioned(
top: 0, left: 0, right: 0, bottom: 0, child: buildTabletCharacterTabView(context, charTabController)),
buildBackground(context),
Positioned(top: 0, left: 0, right: 0, bottom: 0, child: buildTabletCharacterTabView(context)),
Positioned(
top: screenPadding.top,
width: kToolbarHeight,
Expand All @@ -131,7 +133,7 @@ class EquipmentScreenState extends State<EquipmentScreen>
Positioned(
top: MediaQuery.of(context).padding.top + kToolbarHeight - 52,
right: 8,
child: buildCharacterMenu(context, typeTabController, charTabController)),
child: buildCharacterMenu(context)),
InventoryNotificationWidget(
notificationMargin: EdgeInsets.only(right: 44), barHeight: 0, key: Key('inventory_notification_widget')),
Positioned(
Expand All @@ -151,20 +153,15 @@ class EquipmentScreenState extends State<EquipmentScreen>
);
}

Widget buildPhone(BuildContext context, TabController typeTabController, TabController charTabController) {
Widget buildPhone(BuildContext context) {
EdgeInsets screenPadding = MediaQuery.of(context).padding;
var topOffset = screenPadding.top + kToolbarHeight;
return Material(
child: Stack(
children: <Widget>[
buildBackground(context, charTabController),
buildItemTypeTabBarView(context, typeTabController, charTabController),
Positioned(
top: 0,
left: 0,
right: 0,
height: topOffset + 16,
child: buildCharacterHeaderTabView(context, charTabController)),
buildBackground(context),
buildItemTypeTabBarView(context),
Positioned(top: 0, left: 0, right: 0, height: topOffset + 16, child: buildCharacterHeaderTabView(context)),
Positioned(
top: screenPadding.top,
width: kToolbarHeight,
Expand All @@ -180,7 +177,7 @@ class EquipmentScreenState extends State<EquipmentScreen>
Positioned(
top: MediaQuery.of(context).padding.top + kToolbarHeight - 52,
right: 8,
child: buildCharacterMenu(context, typeTabController, charTabController)),
child: buildCharacterMenu(context)),
ItemTypeMenuWidget(widget.itemTypes, controller: typeTabController),
InventoryNotificationWidget(key: Key('inventory_notification_widget')),
Positioned(bottom: screenPadding.bottom, left: 0, right: 0, child: SelectedItemsWidget()),
Expand All @@ -189,7 +186,7 @@ class EquipmentScreenState extends State<EquipmentScreen>
);
}

Widget buildCharacterHeaderTabView(BuildContext context, TabController charTabController) {
Widget buildCharacterHeaderTabView(BuildContext context) {
var headers = characters
?.map((character) => TabHeaderWidget(
character,
Expand All @@ -198,15 +195,10 @@ class EquipmentScreenState extends State<EquipmentScreen>
?.toList();
headers?.add(VaultTabHeaderWidget());

if (charTabController?.length != headers?.length) {
charTabController?.dispose();
charTabController = TabController(length: headers?.length, vsync: this);
}

return TabBarView(controller: charTabController, children: headers ?? []);
}

Widget buildTabletCharacterTabView(BuildContext context, TabController charTabController) {
Widget buildTabletCharacterTabView(BuildContext context) {
EdgeInsets screenPadding = MediaQuery.of(context).padding;
var topOffset = screenPadding.top + kToolbarHeight;
var pages = characters
Expand Down Expand Up @@ -237,24 +229,23 @@ class EquipmentScreenState extends State<EquipmentScreen>
return TabBarView(controller: charTabController, children: pages ?? []);
}

Widget buildBackground(BuildContext context, TabController charTabController) {
Widget buildBackground(BuildContext context) {
if (characters == null) return Container();
return AnimatedCharacterBackgroundWidget(
tabController: charTabController,
);
}

Widget buildItemTypeTabBarView(
BuildContext context, TabController typeTabController, TabController charTabController) {
Widget buildItemTypeTabBarView(BuildContext context) {
if (characters == null) return Container();
return TabBarView(controller: typeTabController, children: buildItemTypeTabs(context, charTabController));
return TabBarView(controller: typeTabController, children: buildItemTypeTabs(context));
}

List<Widget> buildItemTypeTabs(BuildContext context, TabController charTabController) {
return widget.itemTypes.map((type) => buildCharacterTabBarView(context, type, charTabController)).toList();
List<Widget> buildItemTypeTabs(BuildContext context) {
return widget.itemTypes.map((type) => buildCharacterTabBarView(context, type)).toList();
}

Widget buildCharacterTabBarView(BuildContext context, int group, TabController charTabController) {
Widget buildCharacterTabBarView(BuildContext context, int group) {
if (characters == null) return Container();
return PassiveTabBarView(
physics: NeverScrollableScrollPhysics(), controller: charTabController, children: buildCharacterTabs(group));
Expand All @@ -272,7 +263,7 @@ class EquipmentScreenState extends State<EquipmentScreen>
return profile.getCharacters(userSettings.characterOrdering);
}

buildCharacterMenu(BuildContext context, TabController typeTabController, TabController charTabController) {
buildCharacterMenu(BuildContext context) {
if (characters == null) return Container();
return Row(children: [
IconButton(
Expand Down
30 changes: 29 additions & 1 deletion lib/services/analytics/analytics.service.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//@dart=2.12
import 'package:collection/collection.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:little_light/services/auth/auth.consumer.dart';
import 'package:little_light/services/setup.dart';
import 'package:little_light/services/user_settings/little_light_persistent_page.dart';
import 'package:little_light/utils/platform_capabilities.dart';
Expand All @@ -16,7 +18,7 @@ setupAnalyticsService() async {
}
}

class AnalyticsService {
class AnalyticsService with AuthConsumer {
FirebaseAnalytics _analytics = FirebaseAnalytics();

AnalyticsService._internal();
Expand Down Expand Up @@ -49,4 +51,30 @@ class AnalyticsService {
}
FirebaseCrashlytics.instance.recordFlutterError(e);
}

void updateCurrentUser() async {
final membershipData = await auth.getMembershipData();
final currentMembership =
membershipData?.destinyMemberships?.firstWhereOrNull((m) => m.membershipId == auth.currentMembershipID);
final membershipID = auth.currentMembershipID;
final accountID = auth.currentAccountID;
final membershipDisplayName = currentMembership?.displayName;
final accountUniqueName = membershipData?.bungieNetUser?.uniqueName;
final userIdentifier = accountUniqueName ?? membershipDisplayName ?? membershipID;
if (userIdentifier != null) {
FirebaseCrashlytics.instance.setUserIdentifier(userIdentifier);
}
if (membershipID != null) {
FirebaseCrashlytics.instance.setCustomKey("membershipID", membershipID);
}
if (accountID != null) {
FirebaseCrashlytics.instance.setCustomKey("accountID", accountID);
}
if (membershipDisplayName != null) {
FirebaseCrashlytics.instance.setCustomKey("membershipDisplayName", membershipDisplayName);
}
if (accountUniqueName != null) {
FirebaseCrashlytics.instance.setCustomKey("accountUniqueName", accountUniqueName);
}
}
}
3 changes: 3 additions & 0 deletions lib/services/setup.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@dart=2.12
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:little_light/services/analytics/analytics.consumer.dart';
import 'package:little_light/services/analytics/analytics.service.dart';
import 'package:little_light/services/app_config/app_config.consumer.dart';
import 'package:little_light/services/app_config/app_config.dart';
Expand Down Expand Up @@ -89,4 +90,6 @@ initPostLoadingServices(BuildContext context) async {
await destinySettings.init();
final profile = getInjectedProfileService();
await profile.init();
final analytics = getInjectedAnalyticsService();
analytics.updateCurrentUser();
}
21 changes: 15 additions & 6 deletions lib/services/storage/storage.base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:get_it/get_it.dart';
import 'package:little_light/services/analytics/analytics.consumer.dart';
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sqflite/sqflite.dart';
Expand All @@ -14,7 +15,7 @@ extension on StoredFileExtensions {
String get extension => this.toString().split(".").last.toLowerCase();
}

abstract class StorageBase<T> {
abstract class StorageBase<T> with AnalyticsConsumer {
SharedPreferences get _prefs => GetIt.I<SharedPreferences>();
final String _path;
static String? _fileRoot;
Expand Down Expand Up @@ -42,14 +43,23 @@ abstract class StorageBase<T> {
}

Future<String?> _getFileRoot() async {
dynamic error;
StackTrace? stack;
try {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
} catch (e) {}
} catch (e, stackTrace) {
error = e;
stack = stackTrace;
}
try {
final directory = await getApplicationSupportDirectory();
return directory.path;
} catch (e) {}
} catch (e, stackTrace) {
error = e;
stack = stackTrace;
}
analytics.registerNonFatal(error, stack, additionalInfo: {"reason": "Coudn't find file root"});
return null;
}
}
Expand Down Expand Up @@ -117,9 +127,8 @@ extension StorageOperations<T> on StorageBase<T> {
try {
String contents = await cached.readAsString();
return contents;
} catch (e) {
print('error reading file');
print(e);
} catch (e, stackTrace) {
analytics.registerNonFatal(e, stackTrace, additionalInfo: {"reason": "Couldn't read file"});
}
}
return null;
Expand Down

0 comments on commit 85149fa

Please sign in to comment.