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-09-28 09:30:38 -07:00
|
|
|
import 'package:immich_mobile/modules/home/providers/home_page_render_list_provider.dart';
|
2022-10-14 13:37:15 -07:00
|
|
|
import 'package:immich_mobile/modules/home/providers/multiselect.provider.dart';
|
2022-10-01 01:33:06 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/immich_asset_grid.dart';
|
2022-02-09 11:41:02 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/control_bottom_app_bar.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/immich_sliver_appbar.dart';
|
2022-08-13 13:51:09 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/profile_drawer/profile_drawer.dart';
|
2022-08-20 14:19:40 -07:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
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-10-06 13:41:56 -07:00
|
|
|
import 'package:immich_mobile/shared/services/share.service.dart';
|
|
|
|
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-08-20 14:19:40 -07:00
|
|
|
final appSettingService = ref.watch(appSettingsServiceProvider);
|
2022-09-28 09:30:38 -07:00
|
|
|
var renderList = ref.watch(renderListProvider);
|
2022-10-14 13:37:15 -07:00
|
|
|
final multiselectEnabled = ref.watch(multiselectProvider.notifier);
|
2022-10-06 13:41:56 -07:00
|
|
|
final selection = useState(<AssetResponseDto>{});
|
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-10-01 01:33:06 -07:00
|
|
|
Widget buildBody() {
|
2022-10-06 13:41:56 -07:00
|
|
|
void selectionListener(
|
2022-10-14 13:37:15 -07:00
|
|
|
bool multiselect,
|
|
|
|
Set<AssetResponseDto> selectedAssets,
|
|
|
|
) {
|
|
|
|
multiselectEnabled.state = multiselect;
|
2022-10-06 13:41:56 -07:00
|
|
|
selection.value = selectedAssets;
|
2022-04-30 08:55:27 -07:00
|
|
|
}
|
|
|
|
|
2022-10-06 13:41:56 -07:00
|
|
|
void onShareAssets() {
|
|
|
|
ref.watch(shareServiceProvider).shareAssets(selection.value.toList());
|
2022-10-14 13:37:15 -07:00
|
|
|
multiselectEnabled.state = false;
|
2022-10-06 13:41:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDelete() {
|
|
|
|
ref.watch(assetProvider.notifier).deleteAssets(selection.value);
|
2022-10-14 13:37:15 -07:00
|
|
|
multiselectEnabled.state = false;
|
2022-10-01 10:19:40 -07:00
|
|
|
}
|
|
|
|
|
2022-02-03 21:18:21 -07:00
|
|
|
return SafeArea(
|
2022-10-14 13:37:15 -07:00
|
|
|
bottom: !multiselectEnabled.state,
|
|
|
|
top: !multiselectEnabled.state,
|
2022-02-09 11:41:02 -07:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
2022-04-30 15:03:45 -07:00
|
|
|
CustomScrollView(
|
|
|
|
slivers: [
|
2022-10-14 13:37:15 -07:00
|
|
|
multiselectEnabled.state
|
2022-10-06 13:41:56 -07:00
|
|
|
? const SliverToBoxAdapter(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 70,
|
|
|
|
child: null,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: ImmichSliverAppBar(
|
|
|
|
onPopBack: reloadAllAsset,
|
|
|
|
),
|
2022-04-30 15:03:45 -07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
2022-08-15 21:11:54 -07:00
|
|
|
padding: const EdgeInsets.only(top: 60.0, bottom: 0.0),
|
2022-10-01 01:33:06 -07:00
|
|
|
child: ImmichAssetGrid(
|
|
|
|
renderList: renderList,
|
|
|
|
assetsPerRow:
|
|
|
|
appSettingService.getSetting(AppSettingsEnum.tilesPerRow),
|
|
|
|
showStorageIndicator: appSettingService
|
|
|
|
.getSetting(AppSettingsEnum.storageIndicator),
|
2022-10-01 10:19:40 -07:00
|
|
|
listener: selectionListener,
|
2022-10-14 13:37:15 -07:00
|
|
|
selectionActive: multiselectEnabled.state,
|
2022-10-01 01:33:06 -07:00
|
|
|
),
|
2022-02-09 11:41:02 -07:00
|
|
|
),
|
2022-10-14 13:37:15 -07:00
|
|
|
if (multiselectEnabled.state) ...[
|
2022-10-06 13:41:56 -07:00
|
|
|
ControlBottomAppBar(
|
|
|
|
onShare: onShareAssets,
|
|
|
|
onDelete: onDelete,
|
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
],
|
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(),
|
2022-10-01 01:33:06 -07:00
|
|
|
body: buildBody(),
|
2022-02-03 21:08:22 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|