2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/startup/plugin/plugin.dart';
|
2023-06-14 14:16:33 +00:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
|
|
|
import 'package:appflowy/workspace/application/view/view_ext.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/workspace/application/view/view_listener.dart';
|
2022-09-26 08:59:58 +00:00
|
|
|
import 'package:dartz/dartz.dart';
|
2023-01-08 04:10:53 +00:00
|
|
|
import 'package:appflowy_backend/log.dart';
|
2023-04-04 00:41:16 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
2022-09-22 05:08:48 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
import '../workspace/presentation/home/home_stack.dart';
|
|
|
|
|
2022-09-26 08:59:58 +00:00
|
|
|
class ViewPluginNotifier extends PluginNotifier<Option<DeletedViewPB>> {
|
2022-09-22 05:08:48 +00:00
|
|
|
final ViewListener? _viewListener;
|
|
|
|
ViewPB view;
|
|
|
|
|
|
|
|
@override
|
2022-09-26 08:59:58 +00:00
|
|
|
final ValueNotifier<Option<DeletedViewPB>> isDeleted = ValueNotifier(none());
|
2022-09-22 05:08:48 +00:00
|
|
|
|
|
|
|
ViewPluginNotifier({
|
|
|
|
required this.view,
|
2023-06-14 14:16:33 +00:00
|
|
|
required bool listenOnViewChanged,
|
|
|
|
}) : _viewListener = ViewListener(viewId: view.id) {
|
|
|
|
if (listenOnViewChanged) {
|
|
|
|
_viewListener?.start(
|
|
|
|
onViewUpdated: (updatedView) {
|
|
|
|
// If the layout is changed, we need to create a new plugin for it.
|
|
|
|
if (view.layout != updatedView.layout) {
|
|
|
|
getIt<HomeStackManager>().setPlugin(
|
|
|
|
updatedView.plugin(
|
|
|
|
listenOnViewChanged: listenOnViewChanged,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
2023-04-10 07:10:42 +00:00
|
|
|
view = updatedView;
|
2023-06-14 14:16:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onViewMoveToTrash: (result) {
|
|
|
|
result.fold(
|
|
|
|
(deletedView) => isDeleted.value = some(deletedView),
|
|
|
|
(err) => Log.error(err),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-09-22 05:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
isDeleted.dispose();
|
|
|
|
_viewListener?.stop();
|
|
|
|
}
|
|
|
|
}
|