Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

✨ "Media is loading" indicator in create post modal #529

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions lib/pages/home/home.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import 'dart:async';
import 'dart:io';

import 'package:Okuna/models/push_notification.dart';
import 'package:Okuna/pages/home/lib/poppable_page_controller.dart';
import 'package:Okuna/services/intercom.dart';
import 'package:Okuna/services/media/media.dart';
import 'package:Okuna/services/push_notifications/push_notifications.dart';
import 'package:Okuna/models/user.dart';
import 'package:Okuna/pages/home/lib/poppable_page_controller.dart';
import 'package:Okuna/pages/home/modals/save_post/create_post.dart';
import 'package:Okuna/pages/home/pages/communities/communities.dart';
import 'package:Okuna/pages/home/pages/menu/menu.dart';
import 'package:Okuna/pages/home/pages/notifications/notifications.dart';
import 'package:Okuna/pages/home/pages/own_profile.dart';
import 'package:Okuna/pages/home/pages/timeline/timeline.dart';
import 'package:Okuna/pages/home/pages/menu/menu.dart';
import 'package:Okuna/pages/home/pages/search/search.dart';
import 'package:Okuna/pages/home/pages/timeline/timeline.dart';
import 'package:Okuna/pages/home/widgets/bottom-tab-bar.dart';
import 'package:Okuna/pages/home/widgets/own_profile_active_icon.dart';
import 'package:Okuna/pages/home/widgets/tab-scaffold.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/services/event/event.dart';
import 'package:Okuna/services/event/models/subscription.dart';
import 'package:Okuna/services/httpie.dart';
import 'package:Okuna/services/intercom.dart';
import 'package:Okuna/services/modal_service.dart';
import 'package:Okuna/services/share.dart';
import 'package:Okuna/services/push_notifications/push_notifications.dart';
import 'package:Okuna/services/share/models/share_event.dart';
import 'package:Okuna/services/toast.dart';
import 'package:Okuna/services/user.dart';
import 'package:Okuna/services/user_preferences.dart';
Expand Down Expand Up @@ -47,8 +48,7 @@ class OBHomePageState extends State<OBHomePage>
IntercomService _intercomService;
ModalService _modalService;
UserPreferencesService _userPreferencesService;
ShareService _shareService;
MediaService _mediaService;
EventService _eventService;

int _currentIndex;
int _lastIndex;
Expand All @@ -66,6 +66,9 @@ class OBHomePageState extends State<OBHomePage>
OBCommunitiesPageController _communitiesPageController;
OBNotificationsPageController _notificationsPageController;

Completer _postModalCompleter;
EventSubscription _postModalEventSubscription;

int _loggedInUserUnreadNotifications;
String _loggedInUserAvatarUrl;

Expand Down Expand Up @@ -112,8 +115,7 @@ class OBHomePageState extends State<OBHomePage>
_toastService = openbookProvider.toastService;
_modalService = openbookProvider.modalService;
_userPreferencesService = openbookProvider.userPreferencesService;
_shareService = openbookProvider.shareService;
_mediaService = openbookProvider.mediaService;
_eventService = openbookProvider.eventService;
_bootstrap();
_needsBootstrap = false;
}
Expand Down Expand Up @@ -331,7 +333,7 @@ class OBHomePageState extends State<OBHomePage>
}
}

_shareService.subscribe(_onShare);
_eventService.subscribe(_onShareEvent);
}

Future _logout({unsubscribePushNotifications = false}) async {
Expand Down Expand Up @@ -433,16 +435,36 @@ class OBHomePageState extends State<OBHomePage>
//_navigateToTab(OBHomePageTabs.notifications);
}

Future<bool> _onShare({String text, File image, File video}) async {
bool postCreated = await _timelinePageController.createPost(
text: text, image: image, video: video);
Future<void> _onShareEvent(ShareEvent event) async {
if (event.status == ShareStatus.received) {
event.consume();

_postModalCompleter = new Completer();

if (postCreated) {
// Subscribe to post modal events so we know when the post modal is opened
// and closed.
_postModalEventSubscription = _eventService.subscribe(_onPostModalEvent);
_timelinePageController.createPost();

// Wait for the post modal to open before returning to ensure it has
// registered its event listeners before the share is processed further.
await _postModalCompleter.future;
_postModalCompleter = null;
}
}

Future<void> _onPostModalEvent(SavePostModalEvent event) async {
if (event.state == PostModalState.opened) {
if (!_postModalCompleter.isCompleted) {
_postModalCompleter?.complete();
}
} else if (event.state == PostModalState.published) {
_timelinePageController.popUntilFirstRoute();
_navigateToTab(OBHomePageTabs.timeline);
_postModalEventSubscription.cancel();
} else if (event.state == PostModalState.cancelled) {
_postModalEventSubscription.cancel();
}

return true;
}

void _navigateToTab(OBHomePageTabs tab) {
Expand Down
Loading