Last active
May 2, 2019 06:48
-
-
Save escamoteur/7096002923fb3953f019bfc1776fd313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RxCommandListener<ImageStorageRequest, ImageLocation> selectImageListener; | |
RxCommandListener<ChatEntry, void> deleteChatEntryListener; | |
@override | |
void initState() { | |
super.initState(); | |
selectImageListener = RxCommandListener( | |
command: sl.get<ImageManager>().selectAndUploadImageCommand, | |
onValue: (imageLocation) async { | |
if (imageLocation == null) return; | |
sl.get<EventManager>().createChatEntryCommand(new ChatEntry( | |
event: widget.event, | |
isImage: true, | |
content: imageLocation.downloadUrl, | |
)); | |
}, | |
onIsBusy: () => JoCLoader.show(context), | |
onNotBusy: JoCLoader.hide, | |
onError: (ex) => showMessageDialog(context, 'Upload problem', | |
"We cannot upload your selected image at the moment. Please check your internet connection")); | |
deleteChatEntryListener = RxCommandListener( | |
command: sl.get<EventManager>().deleteChatEntryCommand, | |
onValue: (_) => setState(() => {}), | |
); | |
void dispose() { | |
selectImageListener?.dispose(); | |
deleteChatEntryListener?.dispose(); | |
} | |
//////////////////////////////////////////////////////// | |
//compared to: | |
/////////////////////////////////////////////////////// | |
StreamSubscription deleteChatEntrySubscription; | |
StreamSubscription _selectImageIsExecutingSubscription; | |
StreamSubscription _selectImageCommandSubscription; | |
StreamSubscription _selectImageErrorSubscription; | |
@override | |
void initState() { | |
super.initState(); | |
_selectImageCommandSubscription = sl | |
.get<ImageManager>() | |
.selectAndUploadImageCommand | |
.listen((imageLocation) async { | |
if (imageLocation == null) return; | |
sl.get<EventManager>().createChatEntryCommand(new ChatEntry( | |
event: widget.event, | |
isImage: true, | |
content: imageLocation.downloadUrl, | |
)); | |
}); | |
_selectImageIsExecutingSubscription = sl | |
.get<ImageManager>() | |
.selectAndUploadImageCommand | |
.isExecuting | |
.listen((busy) { | |
if (busy) { | |
JoCLoader.show(context); | |
} else { | |
JoCLoader.hide(); | |
} | |
}); | |
_selectImageErrorSubscription = sl | |
.get<ImageManager>() | |
.selectAndUploadImageCommand | |
.thrownExceptions | |
.listen((ex) => showMessageDialog(context, 'Upload problem', | |
"We cannot upload your selected image at the moment. Please check your internet connection")); | |
deleteChatEntrySubscription = sl | |
.get<EventManager>() | |
.deleteChatEntryCommand | |
.listen((_) => setState(() => {})); | |
} | |
void dispose() { | |
_selectImageIsExecutingSubscription?.cancel(); | |
_selectImageCommandSubscription?.cancel(); | |
_selectImageErrorSubscription?.cancel(); | |
deleteChatEntrySubscription?.cancel(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the definition of an RxCommandListener