Skip to content

Commit

Permalink
[mob] Enable back up status & improve error handling (#3253)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
ua741 authored Sep 13, 2024
2 parents 864d150 + 34a8dc2 commit 6ba88d5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 49 deletions.
2 changes: 1 addition & 1 deletion mobile/lib/generated/intl/messages_en.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mobile/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mobile/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
"removingFromFavorites": "Removing from favorites...",
"sorryCouldNotAddToFavorites": "Sorry, could not add to favorites!",
"sorryCouldNotRemoveFromFavorites": "Sorry, could not remove from favorites!",
"subscribeToEnableSharing": "Looks like your subscription has expired. Please subscribe to enable sharing.",
"subscribeToEnableSharing": "You need an active paid subscription to enable sharing.",
"subscribe": "Subscribe",
"canOnlyRemoveFilesOwnedByYou": "Can only remove files owned by you",
"deleteSharedAlbum": "Delete shared album?",
Expand Down
71 changes: 43 additions & 28 deletions mobile/lib/ui/actions/collection/collection_sharing_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import "package:photos/core/errors.dart";
import 'package:photos/db/files_db.dart';
import 'package:photos/ente_theme_data.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/models/api/collection/create_request.dart';
import "package:photos/models/api/collection/user.dart";
Expand Down Expand Up @@ -51,7 +50,7 @@ class CollectionActions {
return true;
} catch (e) {
if (e is SharingNotPermittedForFreeAccountsError) {
_showUnSupportedAlert(context);
await _showUnSupportedAlert(context);
} else {
logger.severe("Failed to update shareUrl collection", e);
await showGenericErrorDialog(context: context, error: e);
Expand Down Expand Up @@ -110,6 +109,7 @@ class CollectionActions {
BuildContext context,
List<EnteFile> files,
) async {
late final Collection newCollection;
try {
// create album with emptyName, use collectionCreationTime on UI to
// show name
Expand All @@ -133,14 +133,29 @@ class CollectionActions {
final collection = await collectionsService.createAndCacheCollection(
req,
);
newCollection = collection;
logger.finest("adding files to share to new album");
await collectionsService.addOrCopyToCollection(collection.id, files);
logger.finest("creating public link for the newly created album");
await CollectionsService.instance.createShareUrl(collection);
try {
await CollectionsService.instance.createShareUrl(collection);
} catch (e) {
if (e is SharingNotPermittedForFreeAccountsError) {
if (newCollection.isQuickLinkCollection() &&
!newCollection.hasSharees) {
await trashCollectionKeepingPhotos(newCollection, context);
}
rethrow;
}
}
return collection;
} catch (e, s) {
await showGenericErrorDialog(context: context, error: e);
logger.severe("Failing to create link for selected files", e, s);
if (e is SharingNotPermittedForFreeAccountsError) {
await _showUnSupportedAlert(context);
} else {
logger.severe("Failing to create link for selected files", e, s);
await showGenericErrorDialog(context: context, error: e);
}
}
return null;
}
Expand Down Expand Up @@ -327,7 +342,7 @@ class CollectionActions {
} catch (e) {
await dialog?.hide();
if (e is SharingNotPermittedForFreeAccountsError) {
_showUnSupportedAlert(context);
await _showUnSupportedAlert(context);
} else {
logger.severe("failed to share collection", e);
await showGenericErrorDialog(context: context, error: e);
Expand Down Expand Up @@ -641,50 +656,50 @@ class CollectionActions {
return true;
}

void _showUnSupportedAlert(BuildContext context) {
Future<void> _showUnSupportedAlert(BuildContext context) async {
final AlertDialog alert = AlertDialog(
title: Text(S.of(context).sorry),
content: Text(
S.of(context).subscribeToEnableSharing,
),
actions: [
TextButton(
child: Text(
S.of(context).subscribe,
style: TextStyle(
color: Theme.of(context).colorScheme.greenAlternative,
),
),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop();
Navigator.of(context).pushReplacement(
ButtonWidget(
buttonType: ButtonType.primary,
isInAlert: true,
shouldStickToDarkTheme: false,
buttonAction: ButtonAction.first,
shouldSurfaceExecutionStates: true,
labelText: S.of(context).subscribe,
onTap: () async {
// for quickLink collection, we need to trash the collection
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return getSubscriptionPage();
},
),
);
).ignore();
},
),
TextButton(
child: Text(
S.of(context).ok,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: ButtonWidget(
buttonType: ButtonType.secondary,
buttonAction: ButtonAction.cancel,
isInAlert: true,
shouldStickToDarkTheme: false,
labelText: S.of(context).ok,
),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop();
},
),
],
);

showDialog(
return showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
barrierDismissible: true,
);
}
}
30 changes: 14 additions & 16 deletions mobile/lib/ui/settings/backup/backup_section_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/service_locator.dart";
import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/components/captioned_text_widget.dart";
import 'package:photos/ui/components/expandable_menu_item_widget.dart';
Expand Down Expand Up @@ -48,22 +47,21 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
);
},
),
if (flagService.internalUser) sectionOptionSpacing,
if (flagService.internalUser)
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).backupStatus,
),
pressedColor: getEnteColorScheme(context).fillFaint,
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
await routeToPage(
context,
const BackupStatusScreen(),
);
},
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).backupStatus,
),
pressedColor: getEnteColorScheme(context).fillFaint,
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
await routeToPage(
context,
const BackupStatusScreen(),
);
},
),
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ class _FileSelectionActionsWidgetState
_cachedCollectionForSharedLink ??= await collectionActions
.createSharedCollectionLink(context, split.ownedByCurrentUser);

if (_cachedCollectionForSharedLink == null) {
await dialog.hide();
return;
}
final List<EnteFile> ownedSelectedFiles = split.ownedByCurrentUser;
placeholderBytes = await _createPlaceholder(ownedSelectedFiles);
await dialog.hide();
Expand Down
2 changes: 1 addition & 1 deletion mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: ente photos application
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 0.9.37+937
version: 0.9.38+938
publish_to: none

environment:
Expand Down

0 comments on commit 6ba88d5

Please sign in to comment.