backup_settings_screen.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. primary: false,
  25. slivers: <Widget>[
  26. TitleBarWidget(
  27. flexibleSpaceTitle: const TitleBarTitleWidget(
  28. title: "Backup settings",
  29. ),
  30. actionIcons: [
  31. IconButtonWidget(
  32. icon: Icons.close_outlined,
  33. isSecondary: true,
  34. onTap: () {
  35. Navigator.pop(context);
  36. },
  37. ),
  38. ],
  39. ),
  40. SliverFixedExtentList(
  41. itemExtent: 269,
  42. delegate: SliverChildBuilderDelegate(
  43. (context, index) {
  44. return Padding(
  45. padding: const EdgeInsets.symmetric(horizontal: 16),
  46. child: Padding(
  47. padding: const EdgeInsets.symmetric(vertical: 20),
  48. child: Column(
  49. mainAxisSize: MainAxisSize.min,
  50. children: [
  51. Column(
  52. children: [
  53. MenuItemWidget(
  54. captionedTextWidget: const CaptionedTextWidget(
  55. title: "Backup over mobile data",
  56. ),
  57. menuItemColor: colorScheme.fillFaint,
  58. trailingSwitch: ToggleSwitchWidget(
  59. value: Configuration.instance
  60. .shouldBackupOverMobileData(),
  61. onChanged: (value) async {
  62. Configuration.instance
  63. .setBackupOverMobileData(value);
  64. setState(() {});
  65. },
  66. ),
  67. borderRadius: 8,
  68. alignCaptionedTextToLeft: true,
  69. isBottomBorderRadiusRemoved: true,
  70. isGestureDetectorDisabled: true,
  71. ),
  72. const SizedBox(height: 1),
  73. MenuItemWidget(
  74. captionedTextWidget: const CaptionedTextWidget(
  75. title: "Backup videos",
  76. ),
  77. menuItemColor: colorScheme.fillFaint,
  78. trailingSwitch: ToggleSwitchWidget(
  79. value:
  80. Configuration.instance.shouldBackupVideos(),
  81. onChanged: (value) async {
  82. Configuration.instance
  83. .setShouldBackupVideos(value);
  84. setState(() {});
  85. },
  86. ),
  87. borderRadius: 8,
  88. alignCaptionedTextToLeft: true,
  89. isTopBorderRadiusRemoved: true,
  90. isGestureDetectorDisabled: true,
  91. ),
  92. ],
  93. ),
  94. const SizedBox(height: 24),
  95. Platform.isIOS
  96. ? Column(
  97. children: [
  98. MenuItemWidget(
  99. captionedTextWidget:
  100. const CaptionedTextWidget(
  101. title: "Disable auto lock",
  102. ),
  103. menuItemColor: colorScheme.fillFaint,
  104. trailingSwitch: ToggleSwitchWidget(
  105. value: Configuration.instance
  106. .shouldKeepDeviceAwake(),
  107. onChanged: _autoLockOnChanged,
  108. ),
  109. borderRadius: 8,
  110. alignCaptionedTextToLeft: true,
  111. isGestureDetectorDisabled: true,
  112. ),
  113. const MenuSectionDescriptionWidget(
  114. content:
  115. "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.",
  116. )
  117. ],
  118. )
  119. : const SizedBox.shrink(),
  120. ],
  121. ),
  122. ),
  123. );
  124. },
  125. childCount: 1,
  126. ),
  127. ),
  128. ],
  129. ),
  130. );
  131. }
  132. void _autoLockOnChanged(value) async {
  133. if (value) {
  134. final choice = await showChoiceDialog(
  135. context,
  136. "Disable automatic screen lock when ente is running?",
  137. "This will ensure faster uploads by ensuring your device does not sleep when uploads are in progress.",
  138. firstAction: "No",
  139. secondAction: "Yes",
  140. );
  141. if (choice != DialogUserChoice.secondChoice) {
  142. return;
  143. }
  144. }
  145. await Configuration.instance.setShouldKeepDeviceAwake(value);
  146. setState(() {});
  147. }
  148. }