nc-photos/app/lib/widget/setup.dart

224 lines
6.2 KiB
Dart
Raw Normal View History

2021-04-10 06:28:12 +02:00
import 'package:flutter/material.dart';
2021-07-25 07:00:38 +02:00
import 'package:nc_photos/app_localizations.dart';
2023-07-17 09:35:45 +02:00
import 'package:nc_photos/entity/pref.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/widget/home.dart';
import 'package:nc_photos/widget/sign_in.dart';
import 'package:page_view_indicators/circle_page_indicator.dart';
2021-10-27 22:40:54 +02:00
bool isNeedSetup() => Pref().getSetupProgressOr() & _PageId.all != _PageId.all;
2021-04-10 06:28:12 +02:00
class Setup extends StatefulWidget {
static const routeName = "/setup";
2021-09-15 08:58:06 +02:00
const Setup({
Key? key,
}) : super(key: key);
2021-04-10 06:28:12 +02:00
@override
createState() => _SetupState();
}
class _SetupState extends State<Setup> {
@override
build(BuildContext context) {
2022-11-12 10:55:33 +01:00
return Scaffold(
appBar: _buildAppBar(context),
body: Builder(builder: (context) => _buildContent(context)),
2021-04-10 06:28:12 +02:00
);
}
2021-07-23 22:05:57 +02:00
PreferredSizeWidget _buildAppBar(BuildContext context) {
2021-04-10 06:28:12 +02:00
return AppBar(
title: Text(L10n.global().setupWidgetTitle),
2021-04-10 06:28:12 +02:00
elevation: 0,
);
}
Widget _buildContent(BuildContext context) {
2021-07-23 22:05:57 +02:00
final page = _pageController.hasClients ? _pageController.page!.round() : 0;
2021-04-10 06:28:12 +02:00
final pages = <Widget>[
if (_initialProgress & _PageId.exif == 0) _Exif(),
if (_initialProgress & _PageId.hiddenPrefDirNotice == 0)
_HiddenPrefDirNotice(),
];
final isLastPage = page >= pages.length - 1;
return Column(
children: [
Expanded(
child: PageView(
controller: _pageController,
2021-09-15 08:58:06 +02:00
physics: const NeverScrollableScrollPhysics(),
2021-04-10 06:28:12 +02:00
children: pages,
onPageChanged: (page) {
setState(() {
_currentPageNotifier.value = page;
});
},
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16),
child: Stack(
alignment: Alignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: isLastPage
? [
ElevatedButton(
onPressed: _onDonePressed,
child: Text(L10n.global().doneButtonLabel),
2021-04-10 06:28:12 +02:00
),
]
: [
ElevatedButton(
2021-07-23 22:05:57 +02:00
onPressed: () {
if (_pageController.hasClients) {
_onNextPressed(
(pages[_pageController.page!.round()]
as _Page)
.getPageId());
}
},
child: Text(L10n.global().nextButtonLabel),
2021-04-10 06:28:12 +02:00
),
],
),
CirclePageIndicator(
itemCount: pages.length,
currentPageNotifier: _currentPageNotifier,
),
],
),
),
],
);
}
void _onDonePressed() {
2021-10-27 22:40:54 +02:00
Pref().setSetupProgress(_PageId.all);
2021-04-10 06:28:12 +02:00
2021-10-27 22:40:54 +02:00
final account = Pref().getCurrentAccount();
2021-04-10 06:28:12 +02:00
if (account == null) {
Navigator.pushReplacementNamed(context, SignIn.routeName);
} else {
Navigator.pushReplacementNamed(context, Home.routeName,
arguments: HomeArguments(account));
}
}
void _onNextPressed(int pageId) {
2021-10-27 22:40:54 +02:00
Pref().setSetupProgress(Pref().getSetupProgressOr() | pageId);
2021-04-10 06:28:12 +02:00
_pageController.nextPage(
duration: k.animationDurationNormal, curve: Curves.easeInOut);
}
2021-10-27 22:40:54 +02:00
final _initialProgress = Pref().getSetupProgressOr();
2021-04-10 06:28:12 +02:00
final _pageController = PageController();
2021-09-15 08:58:06 +02:00
final _currentPageNotifier = ValueNotifier<int>(0);
2021-04-10 06:28:12 +02:00
}
class _PageId {
static const exif = 0x01;
static const hiddenPrefDirNotice = 0x02;
static const all = exif | hiddenPrefDirNotice;
}
abstract class _Page {
int getPageId();
}
class _Exif extends StatefulWidget implements _Page {
@override
createState() => _ExifState();
@override
getPageId() => _PageId.exif;
}
class _ExifState extends State<_Exif> {
@override
build(BuildContext context) {
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SwitchListTile(
title: Text(L10n.global().settingsExifSupportTitle),
2021-04-10 06:28:12 +02:00
value: _isEnableExif,
onChanged: _onValueChanged,
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(L10n.global().exifSupportDetails),
2021-04-10 06:28:12 +02:00
),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
2023-05-26 13:45:46 +02:00
child: Text(
L10n.global().setupSettingsModifyLaterHint,
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(fontStyle: FontStyle.italic),
),
2021-04-10 06:28:12 +02:00
),
const SizedBox(height: 8),
],
),
);
}
@override
dispose() {
super.dispose();
// persist user's choice
2021-10-27 22:40:54 +02:00
Pref().setEnableExif(_isEnableExif);
}
2021-04-10 06:28:12 +02:00
void _onValueChanged(bool value) {
setState(() {
_isEnableExif = value;
});
}
2021-10-27 22:40:54 +02:00
bool _isEnableExif = Pref().isEnableExifOr();
2021-04-10 06:28:12 +02:00
}
class _HiddenPrefDirNotice extends StatefulWidget implements _Page {
@override
createState() => _HiddenPrefDirNoticeState();
@override
getPageId() => _PageId.hiddenPrefDirNotice;
}
class _HiddenPrefDirNoticeState extends State<_HiddenPrefDirNotice> {
@override
build(BuildContext context) {
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(L10n.global().setupHiddenPrefDirNoticeDetail),
2021-04-10 06:28:12 +02:00
),
const SizedBox(height: 24),
Align(
alignment: Alignment.center,
child: Image.asset(
"assets/setup_hidden_pref_dir.png",
fit: BoxFit.contain,
filterQuality: FilterQuality.high,
),
),
const SizedBox(height: 8),
],
),
);
}
}