mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Implemented load new image when navigating back from backup page (#9)
This commit is contained in:
parent
1d3ee2008c
commit
c24fb403c5
12 changed files with 133 additions and 38 deletions
|
|
@ -1,15 +1,19 @@
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/modules/home/models/get_all_asset_respose.model.dart';
|
||||
import 'package:immich_mobile/modules/home/services/asset.service.dart';
|
||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class AssetNotifier extends StateNotifier<List<ImmichAssetGroupByDate>> {
|
||||
final imagePerPage = 100;
|
||||
final AssetService _assetService = AssetService();
|
||||
|
||||
AssetNotifier() : super([]);
|
||||
|
||||
late String? nextPageKey = "";
|
||||
bool isFetching = false;
|
||||
|
||||
// Get All assets
|
||||
getImmichAssets() async {
|
||||
GetAllAssetResponse? res = await _assetService.getAllAsset();
|
||||
nextPageKey = res?.nextPageKey;
|
||||
|
|
@ -21,10 +25,11 @@ class AssetNotifier extends StateNotifier<List<ImmichAssetGroupByDate>> {
|
|||
}
|
||||
}
|
||||
|
||||
getMoreAsset() async {
|
||||
// Get Asset From The Past
|
||||
getOlderAsset() async {
|
||||
if (nextPageKey != null && !isFetching) {
|
||||
isFetching = true;
|
||||
GetAllAssetResponse? res = await _assetService.getMoreAsset(nextPageKey);
|
||||
GetAllAssetResponse? res = await _assetService.getOlderAsset(nextPageKey);
|
||||
|
||||
if (res != null) {
|
||||
nextPageKey = res.nextPageKey;
|
||||
|
|
@ -48,6 +53,40 @@ class AssetNotifier extends StateNotifier<List<ImmichAssetGroupByDate>> {
|
|||
}
|
||||
}
|
||||
|
||||
// Get newer asset from the current time
|
||||
getNewAsset() async {
|
||||
if (state.isNotEmpty) {
|
||||
var latestGroup = state.first;
|
||||
|
||||
// Sort the last asset group and put the lastest asset in front.
|
||||
latestGroup.assets.sortByCompare<DateTime>((e) => DateTime.parse(e.createdAt), (a, b) => b.compareTo(a));
|
||||
var latestAsset = latestGroup.assets.first;
|
||||
var formatDateTemplate = 'y-MM-dd';
|
||||
var latestAssetDateText = DateFormat(formatDateTemplate).format(DateTime.parse(latestAsset.createdAt));
|
||||
|
||||
List<ImmichAsset> newAssets = await _assetService.getNewAsset(latestAsset.createdAt);
|
||||
|
||||
if (newAssets.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Grouping by data
|
||||
var groupByDateList = groupBy<ImmichAsset, String>(
|
||||
newAssets, (asset) => DateFormat(formatDateTemplate).format(DateTime.parse(asset.createdAt)));
|
||||
|
||||
groupByDateList.forEach((groupDateInFormattedText, assets) {
|
||||
if (groupDateInFormattedText != latestAssetDateText) {
|
||||
ImmichAssetGroupByDate newGroup = ImmichAssetGroupByDate(assets: assets, date: groupDateInFormattedText);
|
||||
state = [newGroup, ...state];
|
||||
} else {
|
||||
latestGroup.assets.insertAll(0, assets);
|
||||
|
||||
state = [latestGroup, ...state.sublist(1)];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
clearAllAsset() {
|
||||
state = [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue