2022-08-08 17:46:12 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/models/home_page_state.model.dart';
|
2022-08-08 17:46:12 +02:00
|
|
|
import 'package:immich_mobile/shared/services/share.service.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/share_dialog.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
|
|
|
|
class HomePageStateNotifier extends StateNotifier<HomePageState> {
|
2022-08-08 17:46:12 +02:00
|
|
|
|
|
|
|
final ShareService _shareService;
|
|
|
|
|
|
|
|
HomePageStateNotifier(this._shareService)
|
2022-02-08 19:24:49 +02:00
|
|
|
: super(
|
|
|
|
HomePageState(
|
|
|
|
isMultiSelectEnable: false,
|
|
|
|
selectedItems: {},
|
|
|
|
selectedDateGroup: {},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
void addSelectedDateGroup(String dateGroupTitle) {
|
2022-06-25 22:12:47 +02:00
|
|
|
state = state.copyWith(
|
2022-07-13 14:23:48 +02:00
|
|
|
selectedDateGroup: {...state.selectedDateGroup, dateGroupTitle},
|
|
|
|
);
|
2022-02-08 19:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void removeSelectedDateGroup(String dateGroupTitle) {
|
|
|
|
var currentDateGroup = state.selectedDateGroup;
|
|
|
|
|
|
|
|
currentDateGroup.removeWhere((e) => e == dateGroupTitle);
|
|
|
|
|
|
|
|
state = state.copyWith(selectedDateGroup: currentDateGroup);
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
void enableMultiSelect(Set<AssetResponseDto> selectedItems) {
|
2022-06-25 22:12:47 +02:00
|
|
|
state =
|
|
|
|
state.copyWith(isMultiSelectEnable: true, selectedItems: selectedItems);
|
2022-02-08 19:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void disableMultiSelect() {
|
2022-06-25 22:12:47 +02:00
|
|
|
state = state.copyWith(
|
2022-07-13 14:23:48 +02:00
|
|
|
isMultiSelectEnable: false,
|
|
|
|
selectedItems: {},
|
|
|
|
selectedDateGroup: {},
|
|
|
|
);
|
2022-02-08 19:24:49 +02:00
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
void addSingleSelectedItem(AssetResponseDto asset) {
|
2022-02-08 19:24:49 +02:00
|
|
|
state = state.copyWith(selectedItems: {...state.selectedItems, asset});
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
void addMultipleSelectedItems(List<AssetResponseDto> assets) {
|
2022-02-08 19:24:49 +02:00
|
|
|
state = state.copyWith(selectedItems: {...state.selectedItems, ...assets});
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
void removeSingleSelectedItem(AssetResponseDto asset) {
|
|
|
|
Set<AssetResponseDto> currentList = state.selectedItems;
|
2022-02-08 19:24:49 +02:00
|
|
|
|
|
|
|
currentList.removeWhere((e) => e.id == asset.id);
|
|
|
|
|
|
|
|
state = state.copyWith(selectedItems: currentList);
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
void removeMultipleSelectedItem(List<AssetResponseDto> assets) {
|
|
|
|
Set<AssetResponseDto> currentList = state.selectedItems;
|
2022-02-08 19:24:49 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
for (AssetResponseDto asset in assets) {
|
2022-02-08 19:24:49 +02:00
|
|
|
currentList.removeWhere((e) => e.id == asset.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
state = state.copyWith(selectedItems: currentList);
|
|
|
|
}
|
2022-08-08 17:46:12 +02:00
|
|
|
|
|
|
|
void shareAssets(List<AssetResponseDto> assets, BuildContext context) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext buildContext) {
|
|
|
|
_shareService
|
|
|
|
.shareAssets(assets)
|
|
|
|
.then((_) => Navigator.of(buildContext).pop());
|
|
|
|
return const ShareDialog();
|
|
|
|
},
|
|
|
|
barrierDismissible: false,
|
|
|
|
);
|
|
|
|
}
|
2022-02-08 19:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
final homePageStateProvider =
|
2022-06-25 22:12:47 +02:00
|
|
|
StateNotifierProvider<HomePageStateNotifier, HomePageState>(
|
2022-08-08 17:46:12 +02:00
|
|
|
((ref) => HomePageStateNotifier(ref.watch(shareServiceProvider))),
|
2022-07-13 14:23:48 +02:00
|
|
|
);
|