2022-10-28 09:54:30 +00:00
import ' dart:io ' ;
2022-10-28 06:19:49 +00:00
import ' package:flutter/material.dart ' ;
2022-10-28 09:54:30 +00:00
import ' package:photos/core/configuration.dart ' ;
2022-10-28 06:19:49 +00:00
import ' package:photos/theme/ente_theme.dart ' ;
2022-10-28 09:54:30 +00:00
import ' package:photos/ui/common/dialogs.dart ' ;
2022-10-28 06:19:49 +00:00
import ' package:photos/ui/components/captioned_text_widget.dart ' ;
import ' package:photos/ui/components/icon_button_widget.dart ' ;
import ' package:photos/ui/components/menu_item_widget.dart ' ;
import ' package:photos/ui/components/menu_section_description_widget.dart ' ;
import ' package:photos/ui/components/title_bar_title_widget.dart ' ;
import ' package:photos/ui/components/title_bar_widget.dart ' ;
import ' package:photos/ui/components/toggle_switch_widget.dart ' ;
2022-10-28 14:31:12 +00:00
class BackupSettingsScreen extends StatelessWidget {
2022-10-28 06:19:49 +00:00
const BackupSettingsScreen ( { super . key } ) ;
@ override
Widget build ( BuildContext context ) {
final colorScheme = getEnteColorScheme ( context ) ;
return Scaffold (
body: CustomScrollView (
2022-10-28 10:17:25 +00:00
primary: false ,
2022-10-28 06:19:49 +00:00
slivers: < Widget > [
2022-10-28 10:05:48 +00:00
TitleBarWidget (
flexibleSpaceTitle: const TitleBarTitleWidget (
2022-10-28 06:19:49 +00:00
title: " Backup settings " ,
) ,
actionIcons: [
IconButtonWidget (
icon: Icons . close_outlined ,
isSecondary: true ,
2022-10-28 10:05:48 +00:00
onTap: ( ) {
Navigator . pop ( context ) ;
} ,
2022-10-28 06:19:49 +00:00
) ,
] ,
) ,
2022-10-29 00:30:38 +00:00
SliverList (
2022-10-28 06:19:49 +00:00
delegate: SliverChildBuilderDelegate (
( context , index ) {
return Padding (
padding: const EdgeInsets . symmetric ( horizontal: 16 ) ,
child: Padding (
padding: const EdgeInsets . symmetric ( vertical: 20 ) ,
child: Column (
mainAxisSize: MainAxisSize . min ,
children: [
Column (
children: [
MenuItemWidget (
captionedTextWidget: const CaptionedTextWidget (
title: " Backup over mobile data " ,
) ,
menuItemColor: colorScheme . fillFaint ,
trailingSwitch: ToggleSwitchWidget (
2022-10-28 14:31:12 +00:00
value: ( ) {
return Configuration . instance
. shouldBackupOverMobileData ( ) ;
} ,
onChanged: ( ) async {
await Configuration . instance
. setBackupOverMobileData (
! Configuration . instance
. shouldBackupOverMobileData ( ) ,
) ;
2022-10-28 09:54:30 +00:00
} ,
2022-10-28 06:19:49 +00:00
) ,
borderRadius: 8 ,
alignCaptionedTextToLeft: true ,
isBottomBorderRadiusRemoved: true ,
isGestureDetectorDisabled: true ,
) ,
const SizedBox ( height: 1 ) ,
MenuItemWidget (
captionedTextWidget: const CaptionedTextWidget (
title: " Backup videos " ,
) ,
menuItemColor: colorScheme . fillFaint ,
trailingSwitch: ToggleSwitchWidget (
2022-10-28 14:31:12 +00:00
value: ( ) = >
2022-10-28 09:54:30 +00:00
Configuration . instance . shouldBackupVideos ( ) ,
2022-10-28 14:31:12 +00:00
onChanged: ( ) = > Configuration . instance
. setShouldBackupVideos (
! Configuration . instance . shouldBackupVideos ( ) ,
) ,
2022-10-28 06:19:49 +00:00
) ,
borderRadius: 8 ,
alignCaptionedTextToLeft: true ,
isTopBorderRadiusRemoved: true ,
isGestureDetectorDisabled: true ,
) ,
] ,
) ,
const SizedBox ( height: 24 ) ,
2022-10-28 09:54:30 +00:00
Platform . isIOS
? Column (
children: [
MenuItemWidget (
captionedTextWidget:
const CaptionedTextWidget (
title: " Disable auto lock " ,
) ,
menuItemColor: colorScheme . fillFaint ,
trailingSwitch: ToggleSwitchWidget (
2022-10-28 14:31:12 +00:00
value: ( ) = > Configuration . instance
2022-10-28 09:54:30 +00:00
. shouldKeepDeviceAwake ( ) ,
2022-10-28 14:31:12 +00:00
onChanged: ( ) {
return _autoLockOnChanged (
! Configuration . instance
. shouldKeepDeviceAwake ( ) ,
context ,
) ;
} ,
2022-10-28 09:54:30 +00:00
) ,
borderRadius: 8 ,
alignCaptionedTextToLeft: true ,
isGestureDetectorDisabled: true ,
) ,
const MenuSectionDescriptionWidget (
content:
" 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. " ,
)
] ,
)
: const SizedBox . shrink ( ) ,
2022-10-28 06:19:49 +00:00
] ,
) ,
) ,
) ;
} ,
childCount: 1 ,
) ,
) ,
] ,
) ,
) ;
}
2022-10-28 09:54:30 +00:00
2022-10-28 14:31:12 +00:00
Future < void > _autoLockOnChanged ( value , context ) async {
2022-10-28 09:54:30 +00:00
if ( value ) {
final choice = await showChoiceDialog (
context ,
" Disable automatic screen lock when ente is running? " ,
" This will ensure faster uploads by ensuring your device does not sleep when uploads are in progress. " ,
firstAction: " No " ,
secondAction: " Yes " ,
) ;
if ( choice ! = DialogUserChoice . secondChoice ) {
return ;
}
}
await Configuration . instance . setShouldKeepDeviceAwake ( value ) ;
}
2022-10-28 06:19:49 +00:00
}