mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 15:30:40 +00:00
[mob] Refactor groupHeader to use groupType
This commit is contained in:
parent
da329c498c
commit
e75be714d9
@ -1,16 +1,15 @@
|
|||||||
import "package:flutter/cupertino.dart";
|
import "package:flutter/cupertino.dart";
|
||||||
import "package:intl/intl.dart";
|
|
||||||
import 'package:photos/core/constants.dart';
|
import 'package:photos/core/constants.dart';
|
||||||
import "package:photos/generated/l10n.dart";
|
import "package:photos/generated/l10n.dart";
|
||||||
import "package:photos/theme/ente_theme.dart";
|
import "package:photos/theme/ente_theme.dart";
|
||||||
|
|
||||||
class GroupHeaderWidget extends StatelessWidget {
|
class GroupHeaderWidget extends StatelessWidget {
|
||||||
final int timestamp;
|
final String title;
|
||||||
final int gridSize;
|
final int gridSize;
|
||||||
|
|
||||||
const GroupHeaderWidget({
|
const GroupHeaderWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.timestamp,
|
required this.title,
|
||||||
required this.gridSize,
|
required this.gridSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ class GroupHeaderWidget extends StatelessWidget {
|
|||||||
gridSize < photoGridSizeMax ? textTheme.body : textTheme.small;
|
gridSize < photoGridSizeMax ? textTheme.body : textTheme.small;
|
||||||
final double horizontalPadding = gridSize < photoGridSizeMax ? 12.0 : 8.0;
|
final double horizontalPadding = gridSize < photoGridSizeMax ? 12.0 : 8.0;
|
||||||
final double verticalPadding = gridSize < photoGridSizeMax ? 12.0 : 14.0;
|
final double verticalPadding = gridSize < photoGridSizeMax ? 12.0 : 14.0;
|
||||||
final String dayTitle = _getDayTitle(context, timestamp);
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
horizontal: horizontalPadding,
|
horizontal: horizontalPadding,
|
||||||
@ -31,33 +30,12 @@ class GroupHeaderWidget extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: Text(
|
child: Text(
|
||||||
dayTitle,
|
title,
|
||||||
style: (dayTitle == S.of(context).dayToday)
|
style: (title == S.of(context).dayToday)
|
||||||
? textStyle
|
? textStyle
|
||||||
: textStyle.copyWith(color: colorScheme.textMuted),
|
: 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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/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_gallery.dart";
|
||||||
import "package:photos/ui/viewer/gallery/component/group/group_header_widget.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/gallery.dart';
|
||||||
import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
|
import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
|
||||||
|
|
||||||
@ -178,6 +179,7 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
|
|||||||
if (_filesInGroup.isEmpty) {
|
if (_filesInGroup.isEmpty) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
final groupType = GalleryContextState.of(context)!.type;
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
@ -185,7 +187,7 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
|
|||||||
children: [
|
children: [
|
||||||
if (widget.enableFileGrouping)
|
if (widget.enableFileGrouping)
|
||||||
GroupHeaderWidget(
|
GroupHeaderWidget(
|
||||||
timestamp: _filesInGroup[0].creationTime!,
|
title: groupType.getTitle(context, _filesInGroup[0]),
|
||||||
gridSize: widget.photoGridSize,
|
gridSize: widget.photoGridSize,
|
||||||
),
|
),
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user