Automatically switch to initial tab when coming from the share menu

This commit is contained in:
Varakh 2021-04-20 00:50:46 +02:00
parent c0a2e8d569
commit 9b440ee63c
5 changed files with 43 additions and 12 deletions

View file

@ -1,5 +1,8 @@
# CHANGELOG # CHANGELOG
## 1.3.3+12 - UNRELEASED
* Automatically switch to initial tab when coming from the share menu
## 1.3.2+11 ## 1.3.2+11
* Add a slash to copied URLs * Add a slash to copied URLs
* Expand item when pressing on the card's title in history view * Expand item when pressing on the card's title in history view

View file

@ -1 +1 @@
enum SwipeEvent { Left, Right } enum SwipeEvent { Start, Left, Right, End }

View file

@ -12,6 +12,7 @@ import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import '../../locator.dart'; import '../../locator.dart';
import '../enums/error_code.dart'; import '../enums/error_code.dart';
import '../enums/refresh_event.dart'; import '../enums/refresh_event.dart';
import '../enums/swipe_event.dart';
import '../enums/viewstate.dart'; import '../enums/viewstate.dart';
import '../error/rest_service_exception.dart'; import '../error/rest_service_exception.dart';
import '../error/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/file_service.dart';
import '../services/link_service.dart'; import '../services/link_service.dart';
import '../services/refresh_service.dart'; import '../services/refresh_service.dart';
import '../services/swipe_service.dart';
import '../util/logger.dart'; import '../util/logger.dart';
import '../util/paste_util.dart'; import '../util/paste_util.dart';
import 'base_model.dart'; import 'base_model.dart';
@ -30,6 +32,7 @@ class UploadModel extends BaseModel {
final FileService _fileService = locator<FileService>(); final FileService _fileService = locator<FileService>();
final LinkService _linkService = locator<LinkService>(); final LinkService _linkService = locator<LinkService>();
final RefreshService _refreshService = locator<RefreshService>(); final RefreshService _refreshService = locator<RefreshService>();
final SwipeService _swipeService = locator<SwipeService>();
TextEditingController _pasteTextController = TextEditingController(); TextEditingController _pasteTextController = TextEditingController();
bool pasteTextTouched = false; bool pasteTextTouched = false;
@ -64,12 +67,12 @@ class UploadModel extends BaseModel {
}); });
}).toList(); }).toList();
setStateView(ViewState.Idle); setStateView(ViewState.Idle);
if (paths.isNotEmpty && paths.length > 0) {
_swipeService.addEvent(SwipeEvent.Start);
}
} }
}, onError: (err) { }, onError: (err) {
setStateView(ViewState.Busy); _errorIntentHandle(err);
errorMessage = translate('upload.retrieval_intent');
_logger.e('Error while retrieving shared data: $err');
setStateView(ViewState.Idle);
}); });
// For sharing images coming from outside the app while the app is closed // For sharing images coming from outside the app while the app is closed
@ -85,7 +88,12 @@ class UploadModel extends BaseModel {
}); });
}).toList(); }).toList();
setStateView(ViewState.Idle); 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 // 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); setStateView(ViewState.Busy);
pasteTextController.text = value; pasteTextController.text = value;
setStateView(ViewState.Idle); setStateView(ViewState.Idle);
_swipeService.addEvent(SwipeEvent.Start);
} }
}, onError: (err) { }, onError: (err) {
setStateView(ViewState.Busy); _errorIntentHandle(err);
errorMessage = translate('upload.retrieval_intent');
_logger.e('Error while retrieving shared data: $err');
setStateView(ViewState.Idle);
}); });
// For sharing or opening urls/text coming from outside the app while the app is closed // 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); setStateView(ViewState.Busy);
pasteTextController.text = value; pasteTextController.text = value;
setStateView(ViewState.Idle); 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<String, bool> uploads, String url) { String generatePasteLinks(Map<String, bool> uploads, String url) {
if (uploads != null && uploads.length > 0) { if (uploads != null && uploads.length > 0) {
var links = ''; var links = '';

View file

@ -52,7 +52,7 @@ class AuthenticatedTabBarState extends State<AuthenticatedTabBarView> with Singl
}); });
_swipeEventSubscription = _swipeService.swipeEventController.stream.listen((SwipeEvent event) { _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; int targetIndex = _currentTabIndex;
if (SwipeEvent.Left == event) { if (SwipeEvent.Left == event) {
@ -63,7 +63,15 @@ class AuthenticatedTabBarState extends State<AuthenticatedTabBarView> with Singl
targetIndex = max(_currentTabIndex - 1, 0); 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); _tabController.animateTo(targetIndex);
}); });
} }

View file

@ -11,7 +11,7 @@ description: A mobile client for FileBin.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.3.2+11 version: 1.3.3+12
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"