2022-11-06 10:16:14 +00:00
|
|
|
import 'dart:async';
|
2023-08-29 09:05:17 +00:00
|
|
|
import "dart:io";
|
2022-11-06 10:16:14 +00:00
|
|
|
|
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";
|
2021-07-01 07:59:46 +00:00
|
|
|
import 'package:photo_manager/photo_manager.dart';
|
2023-04-06 08:42:17 +00:00
|
|
|
import "package:photos/generated/l10n.dart";
|
2021-07-01 07:59:46 +00:00
|
|
|
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) {
|
2022-04-20 13:20:35 +00:00
|
|
|
return Padding(
|
2022-06-06 16:33:50 +00:00
|
|
|
padding: const EdgeInsets.fromLTRB(20, 24, 20, 100),
|
2022-04-20 13:20:35 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-04-20 13:20:35 +00:00
|
|
|
} else {
|
2022-11-06 10:16:14 +00:00
|
|
|
unawaited(
|
|
|
|
routeToPage(
|
|
|
|
context,
|
2023-08-29 09:05:17 +00:00
|
|
|
BackupFolderSelectionPage(
|
|
|
|
buttonText: S.of(context).backup,
|
2022-11-06 10:16:14 +00:00
|
|
|
),
|
2022-04-20 13:20:35 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-04-06 08:42:17 +00:00
|
|
|
text: S.of(context).preserveMore,
|
2022-07-04 04:45:32 +00:00
|
|
|
iconData: Icons.cloud_upload_outlined,
|
2022-04-20 13:20:35 +00:00
|
|
|
),
|
2021-05-12 21:12:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|