Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: metric database #2066

Merged
merged 12 commits into from
Sep 13, 2024
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@ Podfile.lock
.pub-cache/
.pub/
/build/
ios/build/
node_modules/

# Web related
lib/generated_plugin_registrant.dart
6 changes: 2 additions & 4 deletions lib/common/injector.dart
Original file line number Diff line number Diff line change
@@ -63,7 +63,6 @@ import 'package:autonomy_flutter/service/iap_service.dart';
import 'package:autonomy_flutter/service/keychain_service.dart';
import 'package:autonomy_flutter/service/merchandise_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/mix_panel_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/network_issue_manager.dart';
import 'package:autonomy_flutter/service/network_service.dart';
@@ -174,6 +173,7 @@ Future<void> setup() async {
authenticatedDio.interceptors.add(AutonomyAuthInterceptor());
authenticatedDio.interceptors.add(LoggingInterceptor());
authenticatedDio.interceptors.add(ConnectingExceptionInterceptor());
authenticatedDio.interceptors.add(MetricsInterceptor());
(authenticatedDio.transformer as SyncTransformer).jsonDecodeCallback =
parseJson;
authenticatedDio.addSentry();
@@ -188,8 +188,6 @@ Future<void> setup() async {
injector.registerLazySingleton(() => http.Client());
injector
.registerLazySingleton<MetricClientService>(() => MetricClientService());
injector.registerLazySingleton<MixPanelClientService>(
() => MixPanelClientService(injector(), injector(), injector()));
injector.registerLazySingleton<CacheManager>(() => AUImageCacheManage());
injector.registerLazySingleton<AccountService>(() => AccountServiceImpl(
cloudDB,
@@ -419,5 +417,5 @@ Future<void> setup() async {
() => AnnouncementServiceImpl(injector(), injector(), injector()));

injector.registerLazySingleton<UpgradesBloc>(
() => UpgradesBloc(injector(), injector()));
() => UpgradesBloc(injector(), injector(), injector()));
}
6 changes: 5 additions & 1 deletion lib/gateway/iap_api.dart
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import 'dart:io';

import 'package:autonomy_flutter/model/announcement/announcement.dart';
import 'package:autonomy_flutter/model/announcement/announcement_request.dart';
import 'package:autonomy_flutter/model/backup_versions.dart';
import 'package:autonomy_flutter/model/jwt.dart';
import 'package:autonomy_flutter/model/ok_response.dart';
import 'package:dio/dio.dart';
@@ -65,4 +64,9 @@ abstract class IAPApi {
Future<OkResponse> redeemGiftCode(
@Path('id') String id,
);

@PATCH('/apis/metric-devices/{id}')
Future<void> updateMetrics(
@Path('id') String deviceId,
);
}
24 changes: 24 additions & 0 deletions lib/gateway/iap_api.g.dart

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

26 changes: 23 additions & 3 deletions lib/model/jwt.dart
Original file line number Diff line number Diff line change
@@ -24,6 +24,15 @@ enum MembershipType {
}
}

String get mixpanelName {
switch (this) {
case MembershipType.free:
return 'Free';
case MembershipType.premium:
return 'Premium';
}
}

static MembershipType fromString(String name) {
switch (name) {
case 'premium':
@@ -117,7 +126,18 @@ enum MembershipSource {
}
}

static MembershipSource fromString(String name) {
String get mixpanelName {
switch (this) {
case MembershipSource.purchase:
return 'Purchase';
case MembershipSource.giftCode:
return 'Gift Code';
case MembershipSource.preset:
return 'Preset';
}
}

static MembershipSource? fromString(String name) {
switch (name) {
case 'purchase':
return MembershipSource.purchase;
@@ -126,15 +146,15 @@ enum MembershipSource {
case 'preset':
return MembershipSource.preset;
default:
return MembershipSource.purchase;
return null;
}
}
}

class SubscriptionStatus {
final MembershipType membership;
final bool isTrial;
final MembershipSource source;
final MembershipSource? source;
final DateTime? expireDate;

SubscriptionStatus(
6 changes: 5 additions & 1 deletion lib/screen/app_router.dart
Original file line number Diff line number Diff line change
@@ -1024,7 +1024,11 @@ class AppRouter {
settings: settings,
builder: (context) => MultiBlocProvider(providers: [
BlocProvider(
create: (_) => UpgradesBloc(injector(), injector()),
create: (_) => UpgradesBloc(
injector(),
injector(),
injector(),
),
),
], child: const SubscriptionPage()));

8 changes: 1 addition & 7 deletions lib/screen/detail/artwork_detail_page.dart
Original file line number Diff line number Diff line change
@@ -262,13 +262,7 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
currentAsset?.medium == 'other' ||
currentAsset?.medium == null;
return BlocConsumer<ArtworkDetailBloc, ArtworkDetailState>(
listenWhen: (previous, current) {
if (previous.assetToken != current.assetToken &&
current.assetToken != null) {
unawaited(current.assetToken?.sendViewArtworkEvent());
}
return true;
}, listener: (context, state) {
listener: (context, state) {
final identitiesList = state.provenances.map((e) => e.owner).toList();
if (state.assetToken?.artistName != null &&
state.assetToken!.artistName!.length > 20) {
13 changes: 1 addition & 12 deletions lib/screen/exhibition_details/exhibition_detail_page.dart
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ import 'package:autonomy_flutter/model/pair.dart';
import 'package:autonomy_flutter/screen/detail/preview/canvas_device_bloc.dart';
import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_bloc.dart';
import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_state.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/series_ext.dart';
@@ -41,7 +39,6 @@ class _ExhibitionDetailPageState extends State<ExhibitionDetailPage>
with AfterLayoutMixin {
late final ExhibitionDetailBloc _exBloc;

final _metricClientService = injector<MetricClientService>();
final _canvasDeviceBloc = injector<CanvasDeviceBloc>();

late final PageController _controller;
@@ -280,15 +277,7 @@ class _ExhibitionDetailPageState extends State<ExhibitionDetailPage>
}

@override
FutureOr<void> afterFirstLayout(BuildContext context) {
_metricClientService.addEvent(
MixpanelEvent.viewExhibition,
data: {
MixpanelProp.exhibitionId:
widget.payload.exhibitions[widget.payload.index].id,
},
);
}
FutureOr<void> afterFirstLayout(BuildContext context) {}
}

class ExhibitionDetailPayload {
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@ import 'package:autonomy_flutter/model/ff_artwork.dart';
import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/screen/detail/preview/canvas_device_bloc.dart';
import 'package:autonomy_flutter/screen/detail/preview/keyboard_control_page.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';
import 'package:autonomy_flutter/util/john_gerrard_helper.dart';
import 'package:autonomy_flutter/util/series_ext.dart';
@@ -50,7 +48,6 @@ class _FeralFileArtworkPreviewPageState
with
AfterLayoutMixin<FeralFileArtworkPreviewPage>,
SingleTickerProviderStateMixin {
final _metricClient = injector.get<MetricClientService>();
final _canvasDeviceBloc = injector.get<CanvasDeviceBloc>();
late bool isCrystallineWork;

@@ -69,13 +66,6 @@ class _FeralFileArtworkPreviewPageState
ScrollController? _scrollController;
late AnimationController _animationController;

void _sendViewArtworkEvent(Artwork artwork) {
final data = {
MixpanelProp.tokenId: artwork.metricTokenId,
};
_metricClient.addEvent(MixpanelEvent.viewArtwork, data: data);
}

@override
void initState() {
isCrystallineWork = widget.payload.artwork.series?.exhibitionID ==
@@ -94,7 +84,6 @@ class _FeralFileArtworkPreviewPageState
@override
void afterFirstLayout(BuildContext context) {
_appBarBottomDy ??= MediaQuery.of(context).padding.top + kToolbarHeight;
_sendViewArtworkEvent(widget.payload.artwork);
_detector = ShakeDetector.autoStart(
onPhoneShake: () async {
await _exitFullScreen();
47 changes: 28 additions & 19 deletions lib/screen/feralfile_home/featured_work_view.dart
Original file line number Diff line number Diff line change
@@ -282,28 +282,37 @@ class FeaturedWorkViewState extends State<FeaturedWorkView> {
..add(token.artistName ?? '');
}
bloc.add(GetIdentityEvent(addresses));
await Future.wait(tokens.map((token) async {
final uri = Uri.tryParse(token.thumbnailURL ?? '');
if (uri != null) {
final response = await http.get(uri);
await Future.wait(
tokens.map(
(token) async {
try {
final uri = Uri.tryParse(token.thumbnailURL ?? '');
if (uri != null) {
final response = await http.get(uri);

if (response.statusCode == 200) {
final bytes = response.bodyBytes;
if (response.statusCode == 200) {
final bytes = response.bodyBytes;

// Decode the image
final image = await decodeImageFromList(bytes);
// Decode the image
final image = await decodeImageFromList(bytes);

// Get width and height
final width = image.width;
final height = image.height;
_imageSize.addEntries([
MapEntry(token.thumbnailURL ?? '', Size(width * 1.0, height * 1.0))
]);
} else {
log.info('Failed to load image at ${token.thumbnailURL}');
}
}
}));
// Get width and height
final width = image.width;
final height = image.height;
_imageSize.addEntries([
MapEntry(
token.thumbnailURL ?? '', Size(width * 1.0, height * 1.0))
]);
} else {
log.info('Failed to load image at ${token.thumbnailURL}');
}
}
} catch (e) {
log.info('Failed to load image at ${token.thumbnailURL}');
}
},
),
);
return tokens;
}

1 change: 0 additions & 1 deletion lib/screen/home/collection_home_page.dart
Original file line number Diff line number Diff line change
@@ -485,7 +485,6 @@ class CollectionHomePageState extends State<CollectionHomePage>
}

void _handleBackground() {
unawaited(_metricClient.sendAndClearMetrics());
unawaited(FileLogger.shrinkLogFileIfNeeded());
}

Loading