[mob] Enable back up status & improve error handling (#3253)

## Description

## Tests
This commit is contained in:
Neeraj Gupta
2024-09-13 14:56:48 +05:30
committed by GitHub
7 changed files with 66 additions and 49 deletions

View File

@@ -1488,7 +1488,7 @@ class MessageLookup extends MessageLookupByLibrary {
"subWillBeCancelledOn": m62,
"subscribe": MessageLookupByLibrary.simpleMessage("Subscribe"),
"subscribeToEnableSharing": MessageLookupByLibrary.simpleMessage(
"Looks like your subscription has expired. Please subscribe to enable sharing."),
"You need an active paid subscription to enable sharing."),
"subscription": MessageLookupByLibrary.simpleMessage("Subscription"),
"success": MessageLookupByLibrary.simpleMessage("Success"),
"successfullyArchived":

View File

@@ -2452,10 +2452,10 @@ class S {
);
}
/// `Looks like your subscription has expired. Please subscribe to enable sharing.`
/// `You need an active paid subscription to enable sharing.`
String get subscribeToEnableSharing {
return Intl.message(
'Looks like your subscription has expired. Please subscribe to enable sharing.',
'You need an active paid subscription to enable sharing.',
name: 'subscribeToEnableSharing',
desc: '',
args: [],

View File

@@ -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?",

View File

@@ -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";
@@ -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);
@@ -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
@@ -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;
}
@@ -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);
@@ -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,
);
}
}

View File

@@ -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';
@@ -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(

View File

@@ -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();

View File

@@ -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: