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 09:54:30 +00:00
class BackupSettingsScreen extends StatefulWidget {
2022-10-28 06:19:49 +00:00
const BackupSettingsScreen ( { super . key } ) ;
2022-10-28 09:54:30 +00:00
@ override
State < BackupSettingsScreen > createState ( ) = > _BackupSettingsScreenState ( ) ;
}
class _BackupSettingsScreenState extends State < BackupSettingsScreen > {
2022-10-28 06:19:49 +00:00
@ override
Widget build ( BuildContext context ) {
final colorScheme = getEnteColorScheme ( context ) ;
return Scaffold (
body: CustomScrollView (
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
) ,
] ,
) ,
SliverList (
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 09:54:30 +00:00
value: Configuration . instance
. shouldBackupOverMobileData ( ) ,
onChanged: ( value ) async {
Configuration . instance
. setBackupOverMobileData ( value ) ;
setState ( ( ) { } ) ;
} ,
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 09:54:30 +00:00
value:
Configuration . instance . shouldBackupVideos ( ) ,
onChanged: ( value ) async {
Configuration . instance
. setShouldBackupVideos ( value ) ;
setState ( ( ) { } ) ;
} ,
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 (
value: Configuration . instance
. shouldKeepDeviceAwake ( ) ,
onChanged: _autoLockOnChanged ,
) ,
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
void _autoLockOnChanged ( value ) async {
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 ) ;
setState ( ( ) { } ) ;
}
2022-10-28 06:19:49 +00:00
}