From 74b05682a85acd9e0b7008540ad8708ba0e9ca9f Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Mon, 9 Aug 2021 02:46:16 +0800 Subject: [PATCH] Lab settings --- lib/lab.dart | 4 +- lib/pref.dart | 5 ++ lib/widget/lab_settings.dart | 112 +++++++++++++++++++++++++++++++++++ lib/widget/my_app.dart | 2 + lib/widget/settings.dart | 10 ++++ 5 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 lib/widget/lab_settings.dart diff --git a/lib/lab.dart b/lib/lab.dart index 7329880c..b8f93b8e 100644 --- a/lib/lab.dart +++ b/lib/lab.dart @@ -1,3 +1,5 @@ +import 'package:nc_photos/pref.dart'; + /// Experimental feature flags class Lab { factory Lab() { @@ -7,7 +9,7 @@ class Lab { return _inst!; } - bool get enableSharedAlbum => false; + bool get enableSharedAlbum => Pref.inst().isLabEnableSharedAlbumOr(false); Lab._(); diff --git a/lib/pref.dart b/lib/pref.dart index 010b1662..b639606d 100644 --- a/lib/pref.dart +++ b/lib/pref.dart @@ -66,6 +66,11 @@ class Pref { Future setNewSharedAlbum(bool value) => _pref.setBool("hasNewSharedAlbum", value); + bool? isLabEnableSharedAlbum() => _pref.getBool("isLabEnableSharedAlbum"); + bool isLabEnableSharedAlbumOr(bool def) => isLabEnableSharedAlbum() ?? def; + Future setLabEnableSharedAlbum(bool value) => + _pref.setBool("isLabEnableSharedAlbum", value); + Pref._(); static final _inst = Pref._(); diff --git a/lib/widget/lab_settings.dart b/lib/widget/lab_settings.dart new file mode 100644 index 00000000..a35e3b11 --- /dev/null +++ b/lib/widget/lab_settings.dart @@ -0,0 +1,112 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:nc_photos/pref.dart'; +import 'package:nc_photos/theme.dart'; + +class LabSettings extends StatefulWidget { + static const routeName = "/lab-settings"; + + @override + createState() => _LabSettingsState(); +} + +class _LabSettingsState extends State { + @override + initState() { + super.initState(); + WidgetsBinding.instance!.addPostFrameCallback((_) { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text("Warning"), + content: Text( + "Features listed here may be untested, unfinished, or even completely broken. They may break the app and corrupt your data. No help/support will be provided.\n\nDO NOT proceed unless you understand the risk"), + actions: [ + Align( + alignment: AlignmentDirectional.centerEnd, + child: TextButton( + onPressed: () { + Navigator.of(context).pop(true); + }, + child: Text("I UNDERSTAND"), + ), + ), + ], + ), + ).then((value) { + if (value != true) { + Navigator.of(context).pop(); + } + }); + }); + } + + @override + build(BuildContext context) { + return AppTheme( + child: Scaffold( + body: Builder(builder: (context) => _buildContent(context)), + appBar: AppBar( + title: Text("Lab Settings"), + ), + ), + ); + } + + Widget _buildContent(BuildContext context) { + return ListView( + children: [ + _LabBoolItem( + title: Text("enableSharedAlbum"), + isSelected: Pref.inst().isLabEnableSharedAlbumOr(false), + onChanged: (value) { + Pref.inst().setLabEnableSharedAlbum(value); + }, + ), + ], + ); + } +} + +class _LabBoolItem extends StatefulWidget { + _LabBoolItem({ + Key? key, + required this.title, + this.subtitle, + required this.isSelected, + this.onChanged, + }) : super(key: key); + + @override + createState() => _LabBoolItemState(); + + final Widget title; + final Widget? subtitle; + final bool isSelected; + final ValueChanged? onChanged; +} + +class _LabBoolItemState extends State<_LabBoolItem> { + @override + initState() { + super.initState(); + _isSelected = widget.isSelected; + } + + @override + build(BuildContext context) { + return CheckboxListTile( + title: widget.title, + subtitle: widget.subtitle, + value: _isSelected, + onChanged: (value) { + setState(() { + _isSelected = value!; + }); + widget.onChanged?.call(value!); + }, + ); + } + + late bool _isSelected; +} diff --git a/lib/widget/my_app.dart b/lib/widget/my_app.dart index cc9ff848..3a0187b0 100644 --- a/lib/widget/my_app.dart +++ b/lib/widget/my_app.dart @@ -15,6 +15,7 @@ import 'package:nc_photos/widget/archive_browser.dart'; import 'package:nc_photos/widget/connect.dart'; import 'package:nc_photos/widget/dynamic_album_browser.dart'; import 'package:nc_photos/widget/home.dart'; +import 'package:nc_photos/widget/lab_settings.dart'; import 'package:nc_photos/widget/root_picker.dart'; import 'package:nc_photos/widget/settings.dart'; import 'package:nc_photos/widget/setup.dart'; @@ -89,6 +90,7 @@ class _MyAppState extends State implements SnackBarHandler { Setup.routeName: (context) => Setup(), SignIn.routeName: (context) => SignIn(), Splash.routeName: (context) => Splash(), + LabSettings.routeName: (context) => LabSettings(), }; Route? _onGenerateRoute(RouteSettings settings) { diff --git a/lib/widget/settings.dart b/lib/widget/settings.dart index d1a77d49..27c25408 100644 --- a/lib/widget/settings.dart +++ b/lib/widget/settings.dart @@ -13,6 +13,7 @@ import 'package:nc_photos/pref.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/widget/fancy_option_picker.dart'; +import 'package:nc_photos/widget/lab_settings.dart'; import 'package:url_launcher/url_launcher.dart'; class SettingsArguments { @@ -91,6 +92,7 @@ class _SettingsState extends State { ListTile( title: Text(L10n.of(context).settingsVersionTitle), subtitle: const Text(k.versionStr), + onTap: () => _onVersionTap(context), ), ListTile( title: Text(L10n.of(context).settingsSourceCodeTitle), @@ -200,6 +202,13 @@ class _SettingsState extends State { } } + void _onVersionTap(BuildContext context) { + if (++_labUnlockCount >= 10) { + Navigator.of(context).pushNamed(LabSettings.routeName); + _labUnlockCount = 0; + } + } + void _setExifSupport(bool value) { final oldValue = _isEnableExif; setState(() { @@ -232,6 +241,7 @@ class _SettingsState extends State { "https://gitlab.com/nkming2/nc-photos/-/tree/master/lib/l10n"; late bool _isEnableExif; + int _labUnlockCount = 0; static final _log = Logger("widget.settings._SettingsState"); }