diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b52e93..b2a6a3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 1.3.3+12 - UNRELEASED +* Automatically switch to initial tab when coming from the share menu + ## 1.3.2+11 * Add a slash to copied URLs * Expand item when pressing on the card's title in history view diff --git a/lib/core/enums/swipe_event.dart b/lib/core/enums/swipe_event.dart index 72e3ca5..20afbbb 100644 --- a/lib/core/enums/swipe_event.dart +++ b/lib/core/enums/swipe_event.dart @@ -1 +1 @@ -enum SwipeEvent { Left, Right } +enum SwipeEvent { Start, Left, Right, End } diff --git a/lib/core/viewmodels/upload_model.dart b/lib/core/viewmodels/upload_model.dart index 5244cb4..9d53d26 100644 --- a/lib/core/viewmodels/upload_model.dart +++ b/lib/core/viewmodels/upload_model.dart @@ -12,6 +12,7 @@ import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import '../../locator.dart'; import '../enums/error_code.dart'; import '../enums/refresh_event.dart'; +import '../enums/swipe_event.dart'; import '../enums/viewstate.dart'; import '../error/rest_service_exception.dart'; import '../error/service_exception.dart'; @@ -21,6 +22,7 @@ import '../models/rest/uploaded_response.dart'; import '../services/file_service.dart'; import '../services/link_service.dart'; import '../services/refresh_service.dart'; +import '../services/swipe_service.dart'; import '../util/logger.dart'; import '../util/paste_util.dart'; import 'base_model.dart'; @@ -30,6 +32,7 @@ class UploadModel extends BaseModel { final FileService _fileService = locator(); final LinkService _linkService = locator(); final RefreshService _refreshService = locator(); + final SwipeService _swipeService = locator(); TextEditingController _pasteTextController = TextEditingController(); bool pasteTextTouched = false; @@ -64,12 +67,12 @@ class UploadModel extends BaseModel { }); }).toList(); setStateView(ViewState.Idle); + if (paths.isNotEmpty && paths.length > 0) { + _swipeService.addEvent(SwipeEvent.Start); + } } }, onError: (err) { - setStateView(ViewState.Busy); - errorMessage = translate('upload.retrieval_intent'); - _logger.e('Error while retrieving shared data: $err'); - setStateView(ViewState.Idle); + _errorIntentHandle(err); }); // For sharing images coming from outside the app while the app is closed @@ -85,7 +88,12 @@ class UploadModel extends BaseModel { }); }).toList(); setStateView(ViewState.Idle); + if (paths.isNotEmpty && paths.length > 0) { + _swipeService.addEvent(SwipeEvent.Start); + } } + }, onError: (err) { + _errorIntentHandle(err); }); // For sharing or opening urls/text coming from outside the app while the app is in the memory @@ -94,12 +102,10 @@ class UploadModel extends BaseModel { setStateView(ViewState.Busy); pasteTextController.text = value; setStateView(ViewState.Idle); + _swipeService.addEvent(SwipeEvent.Start); } }, onError: (err) { - setStateView(ViewState.Busy); - errorMessage = translate('upload.retrieval_intent'); - _logger.e('Error while retrieving shared data: $err'); - setStateView(ViewState.Idle); + _errorIntentHandle(err); }); // For sharing or opening urls/text coming from outside the app while the app is closed @@ -108,10 +114,24 @@ class UploadModel extends BaseModel { setStateView(ViewState.Busy); pasteTextController.text = value; setStateView(ViewState.Idle); + if (paths.isNotEmpty && paths.length > 0) { + _swipeService.addEvent(SwipeEvent.Start); + } } + }, onError: (err) { + _errorIntentHandle(err); }); } + void _errorIntentHandle(err) { + setStateView(ViewState.Busy); + errorMessage = translate('upload.retrieval_intent'); + _logger.e('Error while retrieving shared data: $err'); + setStateView(ViewState.Idle); + + _swipeService.addEvent(SwipeEvent.Start); + } + String generatePasteLinks(Map uploads, String url) { if (uploads != null && uploads.length > 0) { var links = ''; diff --git a/lib/ui/views/tabbar_authenticated.dart b/lib/ui/views/tabbar_authenticated.dart index e15850c..3866312 100644 --- a/lib/ui/views/tabbar_authenticated.dart +++ b/lib/ui/views/tabbar_authenticated.dart @@ -52,7 +52,7 @@ class AuthenticatedTabBarState extends State with Singl }); _swipeEventSubscription = _swipeService.swipeEventController.stream.listen((SwipeEvent event) { - _logger.d('Received an swipe event for the authenticated tab bar: $event'); + _logger.d('Received a swipe event for the authenticated tab bar: $event'); int targetIndex = _currentTabIndex; if (SwipeEvent.Left == event) { @@ -63,7 +63,15 @@ class AuthenticatedTabBarState extends State with Singl targetIndex = max(_currentTabIndex - 1, 0); } - _logger.d("Changing to tab '$targetIndex' because of a swipe event"); + if (SwipeEvent.Start == event) { + targetIndex = 0; + } + + if (SwipeEvent.End == event) { + targetIndex = _tabPages.length - 1; + } + + _logger.d("Changing to tab '$targetIndex' because of a swipe event '$event'"); _tabController.animateTo(targetIndex); }); } diff --git a/pubspec.yaml b/pubspec.yaml index f580298..10f2148 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A mobile client for FileBin. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.3.2+11 +version: 1.3.3+12 environment: sdk: ">=2.7.0 <3.0.0"