2022-11-30 18:58:07 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2024-01-15 18:50:33 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-11-06 03:21:55 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-11-06 03:21:55 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
2023-01-27 23:05:08 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
2022-10-14 22:37:15 +02:00
|
|
|
import 'package:immich_mobile/modules/home/providers/multiselect.provider.dart';
|
2023-12-10 04:32:20 +02:00
|
|
|
import 'package:immich_mobile/modules/memories/ui/memory_lane.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-03-22 08:22:04 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/user.provider.dart';
|
2022-02-14 18:40:41 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
2023-12-07 17:38:22 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/asset_grid/multiselect_grid.dart';
|
2023-10-30 19:17:34 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_app_bar.dart';
|
2022-11-30 18:58:07 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
2022-02-03 18:06:44 +02:00
|
|
|
|
2024-01-15 18:50:33 +02:00
|
|
|
@RoutePage()
|
2022-02-03 18:06:44 +02:00
|
|
|
class HomePage extends HookConsumerWidget {
|
2024-01-27 18:14:32 +02:00
|
|
|
const HomePage({super.key});
|
2022-02-03 18:06:44 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-05-25 05:52:43 +02:00
|
|
|
final currentUser = ref.watch(currentUserProvider);
|
2023-11-13 17:54:41 +02:00
|
|
|
final timelineUsers = ref.watch(timelineUsersIdsProvider);
|
2022-11-30 18:58:07 +02:00
|
|
|
final tipOneOpacity = useState(0.0);
|
2023-03-27 04:35:52 +02:00
|
|
|
final refreshCount = useState(0);
|
2022-11-30 18:58:07 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
2023-06-10 20:13:59 +02:00
|
|
|
ref.read(websocketProvider.notifier).connect();
|
|
|
|
Future(() => ref.read(assetProvider.notifier).getAllAsset());
|
2023-11-13 17:54:41 +02:00
|
|
|
ref.read(assetProvider.notifier).getPartnerAssets();
|
2023-06-10 20:13:59 +02:00
|
|
|
ref.read(albumProvider.notifier).getAllAlbums();
|
|
|
|
ref.read(sharedAlbumProvider.notifier).getAllSharedAlbums();
|
2023-09-28 05:26:48 +02:00
|
|
|
ref.read(serverInfoProvider.notifier).getServerInfo();
|
2023-12-07 17:38:22 +02:00
|
|
|
return;
|
2022-07-13 14:23:48 +02:00
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2023-12-07 17:38:22 +02:00
|
|
|
Widget buildLoadingIndicator() {
|
|
|
|
Timer(const Duration(seconds: 2), () => tipOneOpacity.value = 1);
|
2022-02-04 05:01:14 +02:00
|
|
|
|
2023-12-07 17:38:22 +02:00
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const ImmichLoadingIndicator(),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 16.0),
|
|
|
|
child: Text(
|
|
|
|
'home_page_building_timeline',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
fontSize: 16,
|
|
|
|
color: context.primaryColor,
|
2023-05-17 19:36:02 +02:00
|
|
|
),
|
2023-12-07 17:38:22 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 500),
|
|
|
|
opacity: tipOneOpacity.value,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 250,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: const Text(
|
|
|
|
'home_page_first_time_notice',
|
|
|
|
textAlign: TextAlign.justify,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
).tr(),
|
2023-05-17 19:36:02 +02:00
|
|
|
),
|
2023-12-07 17:38:22 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-12-05 21:34:37 +02:00
|
|
|
|
2023-12-07 17:38:22 +02:00
|
|
|
Future<void> refreshAssets() async {
|
|
|
|
final fullRefresh = refreshCount.value > 0;
|
|
|
|
await ref.read(assetProvider.notifier).getAllAsset(clear: fullRefresh);
|
|
|
|
if (timelineUsers.length > 1) {
|
|
|
|
await ref.read(assetProvider.notifier).getPartnerAssets();
|
2023-03-27 04:35:52 +02:00
|
|
|
}
|
2023-12-07 17:38:22 +02:00
|
|
|
if (fullRefresh) {
|
|
|
|
// refresh was forced: user requested another refresh within 2 seconds
|
|
|
|
refreshCount.value = 0;
|
|
|
|
} else {
|
|
|
|
refreshCount.value++;
|
|
|
|
// set counter back to 0 if user does not request refresh again
|
|
|
|
Timer(const Duration(seconds: 4), () => refreshCount.value = 0);
|
2022-11-30 18:58:07 +02:00
|
|
|
}
|
2023-12-07 17:38:22 +02:00
|
|
|
}
|
2022-11-30 18:58:07 +02:00
|
|
|
|
2023-12-10 04:32:20 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: ref.watch(multiselectProvider) ? null : const ImmichAppBar(),
|
|
|
|
body: MultiselectGrid(
|
|
|
|
topWidget: (currentUser != null && currentUser.memoryEnabled)
|
|
|
|
? const MemoryLane()
|
|
|
|
: const SizedBox(),
|
2023-12-07 17:38:22 +02:00
|
|
|
renderListProvider: timelineUsers.length > 1
|
|
|
|
? multiUserAssetsProvider(timelineUsers)
|
|
|
|
: assetsProvider(currentUser?.isarId),
|
|
|
|
buildLoadingIndicator: buildLoadingIndicator,
|
|
|
|
onRefresh: refreshAssets,
|
|
|
|
stackEnabled: true,
|
|
|
|
archiveEnabled: true,
|
|
|
|
editEnabled: true,
|
2023-12-10 04:32:20 +02:00
|
|
|
),
|
2022-02-04 06:08:22 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|