ente/lib/ui/home/preserve_footer_widget.dart

74 lines
2.5 KiB
Dart
Raw Normal View History

import 'dart:async';
2023-08-29 09:05:17 +00:00
import "dart:io";
2021-05-12 21:12:18 +00:00
import 'package:flutter/material.dart';
2023-08-29 09:05:17 +00:00
import "package:logging/logging.dart";
import 'package:photo_manager/photo_manager.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/services/local_sync_service.dart';
2022-07-03 10:09:01 +00:00
import 'package:photos/ui/common/gradient_button.dart';
2023-06-06 09:57:17 +00:00
import 'package:photos/ui/settings/backup/backup_folder_selection_page.dart';
2023-08-29 09:05:17 +00:00
import "package:photos/utils/dialog_util.dart";
2021-07-11 18:35:16 +00:00
import 'package:photos/utils/navigation_util.dart';
2021-05-12 21:12:18 +00:00
2022-10-20 09:10:17 +00:00
class PreserveFooterWidget extends StatelessWidget {
const PreserveFooterWidget({Key? key}) : super(key: key);
2021-05-12 21:12:18 +00:00
@override
Widget build(BuildContext context) {
return Padding(
2022-06-06 16:33:50 +00:00
padding: const EdgeInsets.fromLTRB(20, 24, 20, 100),
child: GradientButton(
onTap: () async {
2023-08-29 09:05:17 +00:00
try {
final PermissionState state =
await PhotoManager.requestPermissionExtend();
await LocalSyncService.instance.onUpdatePermission(state);
} on Exception catch (e) {
Logger("PreserveFooterWidget").severe(
"Failed to request permission: ${e.toString()}",
e,
);
}
if (!LocalSyncService.instance.hasGrantedFullPermission()) {
if (Platform.isAndroid) {
await PhotoManager.openSetting();
} else {
final bool hasGrantedLimit =
LocalSyncService.instance.hasGrantedLimitedPermissions();
showChoiceActionSheet(
context,
title: S.of(context).preserveMore,
body: S.of(context).grantFullAccessPrompt,
firstButtonLabel: S.of(context).openSettings,
firstButtonOnTap: () async {
await PhotoManager.openSetting();
},
secondButtonLabel: hasGrantedLimit
? S.of(context).selectMorePhotos
: S.of(context).cancel,
secondButtonOnTap: () async {
if (hasGrantedLimit) {
await PhotoManager.presentLimited();
}
},
);
}
} else {
unawaited(
routeToPage(
context,
2023-08-29 09:05:17 +00:00
BackupFolderSelectionPage(
buttonText: S.of(context).backup,
),
),
);
}
},
text: S.of(context).preserveMore,
2022-07-04 04:45:32 +00:00
iconData: Icons.cloud_upload_outlined,
),
2021-05-12 21:12:18 +00:00
);
}
}