Fix not grouping by month when zoomed out to the lowest level

This commit is contained in:
Ming Ming 2024-01-14 02:48:49 +08:00
parent feea195e60
commit 47348cf10a
4 changed files with 36 additions and 5 deletions

View file

@ -38,6 +38,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
on<_SetEnableMemoryCollection>(_onSetEnableMemoryCollection);
on<_SetSortByName>(_onSetSortByName);
on<_SetMemoriesRange>(_onSetMemoriesRange);
on<_UpdateDateTimeGroup>(_onUpdateDateTimeGroup);
on<_SetError>(_onSetError);
@ -236,18 +237,22 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
return;
}
final int newZoom;
final currZoom = state.zoom;
if (state.scale! >= 1.25) {
// scale up
newZoom = (state.zoom + 1).clamp(-1, 2);
newZoom = (currZoom + 1).clamp(-1, 2);
} else if (state.scale! <= 0.75) {
newZoom = (state.zoom - 1).clamp(-1, 2);
newZoom = (currZoom - 1).clamp(-1, 2);
} else {
newZoom = state.zoom;
newZoom = currZoom;
}
emit(state.copyWith(
zoom: newZoom,
scale: null,
));
if ((currZoom >= 0) != (newZoom >= 0)) {
add(const _UpdateDateTimeGroup());
}
unawaited(prefController.setHomePhotosZoomLevel(newZoom));
}
@ -272,6 +277,11 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
_transformItems(state.files);
}
void _onUpdateDateTimeGroup(_UpdateDateTimeGroup ev, Emitter<_State> emit) {
_log.info(ev);
_transformItems(state.files);
}
void _onSetError(_SetError ev, Emitter<_State> emit) {
_log.info(ev);
emit(state.copyWith(error: ExceptionEvent(ev.error, ev.stackTrace)));
@ -286,6 +296,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
sort: prefController.isPhotosTabSortByName.value
? _ItemSort.filename
: _ItemSort.dateTime,
isGroupByDay: prefController.homePhotosZoomLevel.value >= 0,
memoriesDayRange: prefController.memoriesRange.value,
locale: language_util.getSelectedLocale() ??
PlatformDispatcher.instance.locale,
@ -349,7 +360,7 @@ _ItemTransformerResult _buildItem(_ItemTransformerArgument arg) {
final sortedFiles =
arg.files.where((f) => f.fdIsArchived != true).sorted(sorter);
final dateHelper = arg.sort == _ItemSort.dateTime
? photo_list_util.DateGroupHelper(isMonthOnly: false)
? photo_list_util.DateGroupHelper(isMonthOnly: !arg.isGroupByDay)
: null;
final today = clock.now();
final memoryCollectionHelper = arg.sort == _ItemSort.dateTime
@ -369,7 +380,7 @@ _ItemTransformerResult _buildItem(_ItemTransformerArgument arg) {
}
final date = dateHelper?.onFile(file);
if (date != null) {
transformed.add(_DateItem(date: date));
transformed.add(_DateItem(date: date, isMonthOnly: !arg.isGroupByDay));
}
transformed.add(item);
memoryCollectionHelper?.addFile(file);

View file

@ -238,6 +238,14 @@ class _SetMemoriesRange implements _Event {
final int value;
}
@toString
class _UpdateDateTimeGroup implements _Event {
const _UpdateDateTimeGroup();
@override
String toString() => _$toString();
}
@toString
class _SetError implements _Event {
const _SetError(this.error, [this.stackTrace]);

View file

@ -76,6 +76,7 @@ class _VideoItem extends _FileItem {
class _DateItem extends _Item {
const _DateItem({
required this.date,
required this.isMonthOnly,
});
@override
@ -88,10 +89,12 @@ class _DateItem extends _Item {
Widget buildWidget(BuildContext context) {
return PhotoListDate(
date: date,
isMonthOnly: isMonthOnly,
);
}
final DateTime date;
final bool isMonthOnly;
}
enum _ItemSort { dateTime, filename }
@ -101,6 +104,7 @@ class _ItemTransformerArgument {
required this.account,
required this.files,
required this.sort,
required this.isGroupByDay,
required this.memoriesDayRange,
required this.locale,
});
@ -108,6 +112,7 @@ class _ItemTransformerArgument {
final Account account;
final List<FileDescriptor> files;
final _ItemSort sort;
final bool isGroupByDay;
final int memoriesDayRange;
final Locale locale;
}

View file

@ -273,6 +273,13 @@ extension _$_SetMemoriesRangeToString on _SetMemoriesRange {
}
}
extension _$_UpdateDateTimeGroupToString on _UpdateDateTimeGroup {
String _$toString() {
// ignore: unnecessary_string_interpolations
return "_UpdateDateTimeGroup {}";
}
}
extension _$_SetErrorToString on _SetError {
String _$toString() {
// ignore: unnecessary_string_interpolations