backup_settings_screen.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/core/configuration.dart';
  4. import 'package:photos/theme/ente_theme.dart';
  5. import 'package:photos/ui/common/dialogs.dart';
  6. import 'package:photos/ui/components/captioned_text_widget.dart';
  7. import 'package:photos/ui/components/icon_button_widget.dart';
  8. import 'package:photos/ui/components/menu_item_widget.dart';
  9. import 'package:photos/ui/components/menu_section_description_widget.dart';
  10. import 'package:photos/ui/components/title_bar_title_widget.dart';
  11. import 'package:photos/ui/components/title_bar_widget.dart';
  12. import 'package:photos/ui/components/toggle_switch_widget.dart';
  13. class BackupSettingsScreen extends StatefulWidget {
  14. const BackupSettingsScreen({super.key});
  15. @override
  16. State<BackupSettingsScreen> createState() => _BackupSettingsScreenState();
  17. }
  18. class _BackupSettingsScreenState extends State<BackupSettingsScreen> {
  19. @override
  20. Widget build(BuildContext context) {
  21. final colorScheme = getEnteColorScheme(context);
  22. return Scaffold(
  23. body: CustomScrollView(
  24. slivers: <Widget>[
  25. const TitleBarWidget(
  26. flexibleSpaceTitle: TitleBarTitleWidget(
  27. title: "Backup settings",
  28. ),
  29. actionIcons: [
  30. IconButtonWidget(
  31. icon: Icons.close_outlined,
  32. isSecondary: true,
  33. ),
  34. ],
  35. ),
  36. SliverList(
  37. delegate: SliverChildBuilderDelegate(
  38. (context, index) {
  39. return Padding(
  40. padding: const EdgeInsets.symmetric(horizontal: 16),
  41. child: Padding(
  42. padding: const EdgeInsets.symmetric(vertical: 20),
  43. child: Column(
  44. mainAxisSize: MainAxisSize.min,
  45. children: [
  46. Column(
  47. children: [
  48. MenuItemWidget(
  49. captionedTextWidget: const CaptionedTextWidget(
  50. title: "Backup over mobile data",
  51. ),
  52. menuItemColor: colorScheme.fillFaint,
  53. trailingSwitch: ToggleSwitchWidget(
  54. value: Configuration.instance
  55. .shouldBackupOverMobileData(),
  56. onChanged: (value) async {
  57. Configuration.instance
  58. .setBackupOverMobileData(value);
  59. setState(() {});
  60. },
  61. ),
  62. borderRadius: 8,
  63. alignCaptionedTextToLeft: true,
  64. isBottomBorderRadiusRemoved: true,
  65. isGestureDetectorDisabled: true,
  66. ),
  67. const SizedBox(height: 1),
  68. MenuItemWidget(
  69. captionedTextWidget: const CaptionedTextWidget(
  70. title: "Backup videos",
  71. ),
  72. menuItemColor: colorScheme.fillFaint,
  73. trailingSwitch: ToggleSwitchWidget(
  74. value:
  75. Configuration.instance.shouldBackupVideos(),
  76. onChanged: (value) async {
  77. Configuration.instance
  78. .setShouldBackupVideos(value);
  79. setState(() {});
  80. },
  81. ),
  82. borderRadius: 8,
  83. alignCaptionedTextToLeft: true,
  84. isTopBorderRadiusRemoved: true,
  85. isGestureDetectorDisabled: true,
  86. ),
  87. ],
  88. ),
  89. const SizedBox(height: 24),
  90. Platform.isIOS
  91. ? Column(
  92. children: [
  93. MenuItemWidget(
  94. captionedTextWidget:
  95. const CaptionedTextWidget(
  96. title: "Disable auto lock",
  97. ),
  98. menuItemColor: colorScheme.fillFaint,
  99. trailingSwitch: ToggleSwitchWidget(
  100. value: Configuration.instance
  101. .shouldKeepDeviceAwake(),
  102. onChanged: _autoLockOnChanged,
  103. ),
  104. borderRadius: 8,
  105. alignCaptionedTextToLeft: true,
  106. isGestureDetectorDisabled: true,
  107. ),
  108. const MenuSectionDescriptionWidget(
  109. content:
  110. "Disable the device screen lock when ente is in the foreground and there is a backup in progress. This is normally not needed, but may help big uploads and initial imports of large libraries complete faster.",
  111. )
  112. ],
  113. )
  114. : const SizedBox.shrink(),
  115. ],
  116. ),
  117. ),
  118. );
  119. },
  120. childCount: 1,
  121. ),
  122. ),
  123. ],
  124. ),
  125. );
  126. }
  127. void _autoLockOnChanged(value) async {
  128. if (value) {
  129. final choice = await showChoiceDialog(
  130. context,
  131. "Disable automatic screen lock when ente is running?",
  132. "This will ensure faster uploads by ensuring your device does not sleep when uploads are in progress.",
  133. firstAction: "No",
  134. secondAction: "Yes",
  135. );
  136. if (choice != DialogUserChoice.secondChoice) {
  137. return;
  138. }
  139. }
  140. await Configuration.instance.setShouldKeepDeviceAwake(value);
  141. setState(() {});
  142. }
  143. }