[mob] Refactor groupHeader to use groupType

This commit is contained in:
Neeraj Gupta 2024-05-04 12:07:58 +05:30
parent da329c498c
commit e75be714d9
2 changed files with 8 additions and 28 deletions

View file

@ -1,16 +1,15 @@
import "package:flutter/cupertino.dart";
import "package:intl/intl.dart";
import 'package:photos/core/constants.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/theme/ente_theme.dart";
class GroupHeaderWidget extends StatelessWidget {
final int timestamp;
final String title;
final int gridSize;
const GroupHeaderWidget({
super.key,
required this.timestamp,
required this.title,
required this.gridSize,
});
@ -22,7 +21,7 @@ class GroupHeaderWidget extends StatelessWidget {
gridSize < photoGridSizeMax ? textTheme.body : textTheme.small;
final double horizontalPadding = gridSize < photoGridSizeMax ? 12.0 : 8.0;
final double verticalPadding = gridSize < photoGridSizeMax ? 12.0 : 14.0;
final String dayTitle = _getDayTitle(context, timestamp);
return Padding(
padding: EdgeInsets.symmetric(
horizontal: horizontalPadding,
@ -31,33 +30,12 @@ class GroupHeaderWidget extends StatelessWidget {
child: Container(
alignment: Alignment.centerLeft,
child: Text(
dayTitle,
style: (dayTitle == S.of(context).dayToday)
title,
style: (title == S.of(context).dayToday)
? textStyle
: textStyle.copyWith(color: colorScheme.textMuted),
),
),
);
}
String _getDayTitle(BuildContext context, int timestamp) {
final date = DateTime.fromMicrosecondsSinceEpoch(timestamp);
final now = DateTime.now();
if (date.year == now.year && date.month == now.month) {
if (date.day == now.day) {
return S.of(context).dayToday;
} else if (date.day == now.day - 1) {
return S.of(context).dayYesterday;
}
}
if (date.year != DateTime.now().year) {
return DateFormat.yMMMEd(Localizations.localeOf(context).languageCode)
.format(date);
} else {
return DateFormat.MMMEd(Localizations.localeOf(context).languageCode)
.format(date);
}
}
}

View file

@ -11,6 +11,7 @@ import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/viewer/gallery/component/grid/place_holder_grid_view_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/group_gallery.dart";
import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
import 'package:photos/ui/viewer/gallery/gallery.dart';
import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
@ -178,6 +179,7 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
if (_filesInGroup.isEmpty) {
return const SizedBox.shrink();
}
final groupType = GalleryContextState.of(context)!.type;
return Column(
children: [
Row(
@ -185,7 +187,7 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
children: [
if (widget.enableFileGrouping)
GroupHeaderWidget(
timestamp: _filesInGroup[0].creationTime!,
title: groupType.getTitle(context, _filesInGroup[0]),
gridSize: widget.photoGridSize,
),
Expanded(child: Container()),