mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 14:56:20 +01:00
Lab settings
This commit is contained in:
parent
a28f8b6c1b
commit
74b05682a8
5 changed files with 132 additions and 1 deletions
|
@ -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._();
|
||||
|
||||
|
|
|
@ -66,6 +66,11 @@ class Pref {
|
|||
Future<bool> setNewSharedAlbum(bool value) =>
|
||||
_pref.setBool("hasNewSharedAlbum", value);
|
||||
|
||||
bool? isLabEnableSharedAlbum() => _pref.getBool("isLabEnableSharedAlbum");
|
||||
bool isLabEnableSharedAlbumOr(bool def) => isLabEnableSharedAlbum() ?? def;
|
||||
Future<bool> setLabEnableSharedAlbum(bool value) =>
|
||||
_pref.setBool("isLabEnableSharedAlbum", value);
|
||||
|
||||
Pref._();
|
||||
|
||||
static final _inst = Pref._();
|
||||
|
|
112
lib/widget/lab_settings.dart
Normal file
112
lib/widget/lab_settings.dart
Normal file
|
@ -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<LabSettings> {
|
||||
@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<bool>? 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;
|
||||
}
|
|
@ -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<MyApp> implements SnackBarHandler {
|
|||
Setup.routeName: (context) => Setup(),
|
||||
SignIn.routeName: (context) => SignIn(),
|
||||
Splash.routeName: (context) => Splash(),
|
||||
LabSettings.routeName: (context) => LabSettings(),
|
||||
};
|
||||
|
||||
Route<dynamic>? _onGenerateRoute(RouteSettings settings) {
|
||||
|
|
|
@ -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<Settings> {
|
|||
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<Settings> {
|
|||
}
|
||||
}
|
||||
|
||||
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<Settings> {
|
|||
"https://gitlab.com/nkming2/nc-photos/-/tree/master/lib/l10n";
|
||||
|
||||
late bool _isEnableExif;
|
||||
int _labUnlockCount = 0;
|
||||
|
||||
static final _log = Logger("widget.settings._SettingsState");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue