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