From 2edbf64e69b90742a28a7470ec23684f9b9f4b5f Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 11 Dec 2022 14:49:03 -0600 Subject: [PATCH] fix(mobile) invalid date in exif cause timeline to crash (#1095) --- .../asset_grid/asset_grid_data_structure.dart | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart b/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart index 96264cf21f..c852f89d22 100644 --- a/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart +++ b/mobile/lib/modules/home/ui/asset_grid/asset_grid_data_structure.dart @@ -1,6 +1,9 @@ import 'dart:math'; import 'package:immich_mobile/shared/models/asset.dart'; +import 'package:logging/logging.dart'; + +final log = Logger('AssetGridDataStructure'); enum RenderAssetGridElementType { assetRow, @@ -64,46 +67,50 @@ List assetGroupsToRenderList( DateTime? lastDate; assetGroups.forEach((groupName, assets) { - final date = DateTime.parse(groupName); + try { + final date = DateTime.parse(groupName); - if (lastDate == null || lastDate!.month != date.month) { + if (lastDate == null || lastDate!.month != date.month) { + elements.add( + RenderAssetGridElement( + RenderAssetGridElementType.monthTitle, + title: groupName, + date: date, + ), + ); + } + + // Add group title elements.add( RenderAssetGridElement( - RenderAssetGridElementType.monthTitle, + RenderAssetGridElementType.dayTitle, title: groupName, date: date, - ), - ); - } - - // Add group title - elements.add( - RenderAssetGridElement( - RenderAssetGridElementType.dayTitle, - title: groupName, - date: date, - relatedAssetList: assets, - ), - ); - - // Add rows - int cursor = 0; - while (cursor < assets.length) { - int rowElements = min(assets.length - cursor, assetsPerRow); - - final rowElement = RenderAssetGridElement( - RenderAssetGridElementType.assetRow, - date: date, - assetRow: RenderAssetGridRow( - assets.sublist(cursor, cursor + rowElements), + relatedAssetList: assets, ), ); - elements.add(rowElement); - cursor += rowElements; - } + // Add rows + int cursor = 0; + while (cursor < assets.length) { + int rowElements = min(assets.length - cursor, assetsPerRow); - lastDate = date; + final rowElement = RenderAssetGridElement( + RenderAssetGridElementType.assetRow, + date: date, + assetRow: RenderAssetGridRow( + assets.sublist(cursor, cursor + rowElements), + ), + ); + + elements.add(rowElement); + cursor += rowElements; + } + + lastDate = date; + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } }); return elements;