2022-02-03 09:06:44 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-02-09 11:41:02 -07:00
|
|
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/ui/control_bottom_app_bar.dart';
|
2022-02-08 10:24:49 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/daily_title_text.dart';
|
2022-02-09 11:41:02 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/disable_multi_select_button.dart';
|
2022-02-03 21:08:22 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/draggable_scrollbar.dart';
|
2022-02-05 23:07:56 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/image_grid.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/immich_sliver_appbar.dart';
|
2022-02-08 10:24:49 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/monthly_title_text.dart';
|
2022-08-13 13:51:09 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/profile_drawer/profile_drawer.dart';
|
2022-08-03 13:36:12 -07:00
|
|
|
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-03-21 23:22:04 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2022-02-14 09:40:41 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
2022-08-03 13:36:12 -07:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
|
|
|
|
class HomePage extends HookConsumerWidget {
|
|
|
|
const HomePage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-21 22:23:35 -07:00
|
|
|
ScrollController scrollController = useScrollController();
|
2022-02-13 14:10:42 -07:00
|
|
|
var assetGroupByDateTime = ref.watch(assetGroupByDateTimeProvider);
|
2022-06-21 22:23:35 -07:00
|
|
|
List<Widget> imageGridGroup = [];
|
|
|
|
var isMultiSelectEnable =
|
|
|
|
ref.watch(homePageStateProvider).isMultiSelectEnable;
|
2022-02-09 11:41:02 -07:00
|
|
|
var homePageState = ref.watch(homePageStateProvider);
|
2022-08-03 13:36:12 -07:00
|
|
|
List<AssetResponseDto> sortedAssetList = [];
|
|
|
|
// set sorted List
|
|
|
|
for (var group in assetGroupByDateTime.values) {
|
|
|
|
for (var value in group) {
|
|
|
|
sortedAssetList.add(value);
|
|
|
|
}
|
|
|
|
}
|
2022-02-03 21:08:22 -07:00
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
ref.read(websocketProvider.notifier).connect();
|
|
|
|
ref.read(assetProvider.notifier).getAllAsset();
|
|
|
|
ref.watch(serverInfoProvider.notifier).getServerVersion();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-02-03 20:01:14 -07:00
|
|
|
|
2022-04-03 10:31:45 -07:00
|
|
|
void reloadAllAsset() {
|
|
|
|
ref.read(assetProvider.notifier).getAllAsset();
|
|
|
|
}
|
|
|
|
|
2022-04-30 08:55:27 -07:00
|
|
|
_buildSelectedItemCountIndicator() {
|
2022-06-30 18:08:49 -07:00
|
|
|
return DisableMultiSelectButton(
|
|
|
|
onPressed: ref.watch(homePageStateProvider.notifier).disableMultiSelect,
|
|
|
|
selectedItemCount: homePageState.selectedItems.length,
|
|
|
|
);
|
2022-04-30 08:55:27 -07:00
|
|
|
}
|
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
Widget _buildBody() {
|
2022-02-13 14:10:42 -07:00
|
|
|
if (assetGroupByDateTime.isNotEmpty) {
|
|
|
|
int? lastMonth;
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-02-13 14:10:42 -07:00
|
|
|
assetGroupByDateTime.forEach((dateGroup, immichAssetList) {
|
|
|
|
DateTime parseDateGroup = DateTime.parse(dateGroup);
|
|
|
|
int currentMonth = parseDateGroup.month;
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-02-13 14:10:42 -07:00
|
|
|
if (lastMonth != null) {
|
|
|
|
if (currentMonth - lastMonth! != 0) {
|
2022-06-21 22:23:35 -07:00
|
|
|
imageGridGroup.add(
|
2022-02-13 14:10:42 -07:00
|
|
|
MonthlyTitleText(
|
|
|
|
isoDate: dateGroup,
|
|
|
|
),
|
2022-02-06 19:31:32 -07:00
|
|
|
);
|
|
|
|
}
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
imageGridGroup.add(
|
2022-02-09 11:41:02 -07:00
|
|
|
DailyTitleText(
|
2022-08-07 17:43:09 -07:00
|
|
|
key: Key('${dateGroup.toString()}title'),
|
2022-02-13 14:10:42 -07:00
|
|
|
isoDate: dateGroup,
|
|
|
|
assetGroup: immichAssetList,
|
2022-02-09 11:41:02 -07:00
|
|
|
),
|
2022-02-03 09:06:44 -07:00
|
|
|
);
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
imageGridGroup.add(
|
2022-08-03 13:36:12 -07:00
|
|
|
ImageGrid(
|
|
|
|
assetGroup: immichAssetList,
|
|
|
|
sortedAssetGroup: sortedAssetList,
|
|
|
|
),
|
2022-02-03 21:08:22 -07:00
|
|
|
);
|
2022-02-13 14:10:42 -07:00
|
|
|
|
|
|
|
lastMonth = currentMonth;
|
|
|
|
});
|
2022-02-03 20:01:14 -07:00
|
|
|
}
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-04-30 08:55:27 -07:00
|
|
|
_buildSliverAppBar() {
|
|
|
|
return isMultiSelectEnable
|
|
|
|
? const SliverToBoxAdapter(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 70,
|
|
|
|
child: null,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: ImmichSliverAppBar(
|
|
|
|
onPopBack: reloadAllAsset,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-03 21:18:21 -07:00
|
|
|
return SafeArea(
|
2022-02-09 11:41:02 -07:00
|
|
|
bottom: !isMultiSelectEnable,
|
|
|
|
top: !isMultiSelectEnable,
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
2022-04-30 15:03:45 -07:00
|
|
|
CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
_buildSliverAppBar(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
2022-08-15 21:11:54 -07:00
|
|
|
padding: const EdgeInsets.only(top: 60.0, bottom: 0.0),
|
2022-04-30 15:03:45 -07:00
|
|
|
child: DraggableScrollbar.semicircle(
|
2022-08-15 16:53:30 -07:00
|
|
|
backgroundColor: Theme.of(context).hintColor,
|
2022-06-21 22:23:35 -07:00
|
|
|
controller: scrollController,
|
2022-04-30 15:03:45 -07:00
|
|
|
heightScrollThumb: 48.0,
|
|
|
|
child: CustomScrollView(
|
2022-06-21 22:23:35 -07:00
|
|
|
controller: scrollController,
|
2022-04-30 15:03:45 -07:00
|
|
|
slivers: [
|
2022-06-21 22:23:35 -07:00
|
|
|
...imageGridGroup,
|
2022-04-30 15:03:45 -07:00
|
|
|
],
|
|
|
|
),
|
2022-02-06 19:31:32 -07:00
|
|
|
),
|
2022-02-09 11:41:02 -07:00
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
if (isMultiSelectEnable) ...[
|
|
|
|
_buildSelectedItemCountIndicator(),
|
|
|
|
const ControlBottomAppBar(),
|
|
|
|
],
|
2022-02-09 11:41:02 -07:00
|
|
|
],
|
2022-02-03 21:08:22 -07:00
|
|
|
),
|
2022-02-03 20:01:14 -07:00
|
|
|
);
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
drawer: const ProfileDrawer(),
|
|
|
|
body: _buildBody(),
|
2022-02-03 21:08:22 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|