2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/startup/plugin/plugin.dart';
|
|
|
|
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';
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
2022-09-22 05:08:48 +00:00
|
|
|
import 'package:flutter/material.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
|
|
|
|
|
|
|
@override
|
|
|
|
final ValueNotifier<int> isDisplayChanged = ValueNotifier(0);
|
|
|
|
|
|
|
|
ViewPluginNotifier({
|
|
|
|
required this.view,
|
|
|
|
}) : _viewListener = ViewListener(view: view) {
|
2023-04-10 07:10:42 +00:00
|
|
|
_viewListener?.start(
|
|
|
|
onViewUpdated: (result) {
|
|
|
|
result.fold(
|
|
|
|
(updatedView) {
|
|
|
|
view = updatedView;
|
|
|
|
isDisplayChanged.value = updatedView.hashCode;
|
|
|
|
},
|
|
|
|
(err) => Log.error(err),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
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();
|
|
|
|
isDisplayChanged.dispose();
|
|
|
|
_viewListener?.stop();
|
|
|
|
}
|
|
|
|
}
|