mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(mobile): Home screen customization options (#1563)
* Try staggered layout for home page * Introduce setting for dynamic layout * Fix some provider related bugs * Make asset grouping configurable * Add translation keys, refactor group title * Rename enum values * Fix enum names * Reformat long if statement * Fix timezone related bug * Minor clean up * Fix unit test * Add second assets check back to home screen
This commit is contained in:
parent
911c35a7f1
commit
fd13265131
13 changed files with 298 additions and 125 deletions
|
|
@ -25,11 +25,15 @@ class AssetsState {
|
|||
|
||||
AssetsState(this.allAssets, {this.renderList});
|
||||
|
||||
Future<AssetsState> withRenderDataStructure(int groupSize) async {
|
||||
Future<AssetsState> withRenderDataStructure(
|
||||
AssetGridLayoutParameters layout,
|
||||
) async {
|
||||
return AssetsState(
|
||||
allAssets,
|
||||
renderList:
|
||||
await RenderList.fromAssetGroups(await _groupByDate(), groupSize),
|
||||
renderList: await RenderList.fromAssets(
|
||||
allAssets,
|
||||
layout,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -37,20 +41,6 @@ class AssetsState {
|
|||
return AssetsState([...allAssets, ...toAdd]);
|
||||
}
|
||||
|
||||
Future<Map<String, List<Asset>>> _groupByDate() async {
|
||||
sortCompare(List<Asset> assets) {
|
||||
assets.sortByCompare<DateTime>(
|
||||
(e) => e.createdAt,
|
||||
(a, b) => b.compareTo(a),
|
||||
);
|
||||
return assets.groupListsBy(
|
||||
(element) => DateFormat('y-MM-dd').format(element.createdAt.toLocal()),
|
||||
);
|
||||
}
|
||||
|
||||
return await compute(sortCompare, allAssets.toList());
|
||||
}
|
||||
|
||||
static AssetsState fromAssetList(List<Asset> assets) {
|
||||
return AssetsState(assets);
|
||||
}
|
||||
|
|
@ -91,10 +81,19 @@ class AssetNotifier extends StateNotifier<AssetsState> {
|
|||
_assetCacheService.put(newAssetList);
|
||||
}
|
||||
|
||||
state =
|
||||
await AssetsState.fromAssetList(newAssetList).withRenderDataStructure(
|
||||
final layout = AssetGridLayoutParameters(
|
||||
_settingsService.getSetting(AppSettingsEnum.tilesPerRow),
|
||||
_settingsService.getSetting(AppSettingsEnum.dynamicLayout),
|
||||
GroupAssetsBy.values[_settingsService.getSetting(AppSettingsEnum.groupAssetsBy)],
|
||||
);
|
||||
|
||||
state = await AssetsState.fromAssetList(newAssetList)
|
||||
.withRenderDataStructure(layout);
|
||||
}
|
||||
|
||||
// Just a little helper to trigger a rebuild of the state object
|
||||
Future<void> rebuildAssetGridDataStructure() async {
|
||||
await _updateAssetsState(state.allAssets, cache: false);
|
||||
}
|
||||
|
||||
getAllAsset() async {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue