Quellcode durchsuchen

Add advanced settings

vishnukvmd vor 2 Jahren
Ursprung
Commit
e0792f24cc

+ 206 - 0
lib/ui/advanced_settings_screen.dart

@@ -0,0 +1,206 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:photos/core/configuration.dart';
+import 'package:photos/core/event_bus.dart';
+import 'package:photos/ente_theme_data.dart';
+import 'package:photos/events/force_reload_home_gallery_event.dart';
+import 'package:photos/theme/ente_theme.dart';
+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/title_bar_title_widget.dart';
+import 'package:photos/ui/components/title_bar_widget.dart';
+
+class AdvancedSettingsScreen extends StatefulWidget {
+  const AdvancedSettingsScreen({super.key});
+
+  @override
+  State<AdvancedSettingsScreen> createState() => _AdvancedSettingsScreenState();
+}
+
+class _AdvancedSettingsScreenState extends State<AdvancedSettingsScreen> {
+  late int _albumGridSize, _chosenGridSize;
+  final _config = Configuration.instance;
+
+  @override
+  void initState() {
+    _albumGridSize = _config.getAlbumGridSize();
+    _chosenGridSize = _albumGridSize;
+    super.initState();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    final colorScheme = getEnteColorScheme(context);
+    return Scaffold(
+      body: CustomScrollView(
+        primary: false,
+        slivers: <Widget>[
+          TitleBarWidget(
+            flexibleSpaceTitle: const TitleBarTitleWidget(
+              title: "Advanced",
+            ),
+            actionIcons: [
+              IconButtonWidget(
+                icon: Icons.close_outlined,
+                iconButtonType: IconButtonType.secondary,
+                onTap: () {
+                  Navigator.pop(context);
+                  Navigator.pop(context);
+                },
+              ),
+            ],
+          ),
+          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: [
+                            GestureDetector(
+                              onTap: () {
+                                _showAlbumGridSizePicker();
+                              },
+                              child: MenuItemWidget(
+                                captionedTextWidget: const CaptionedTextWidget(
+                                  title: "Album grid size",
+                                ),
+                                menuItemColor: colorScheme.fillFaint,
+                                trailingSwitch: Row(
+                                  mainAxisAlignment: MainAxisAlignment.end,
+                                  children: [
+                                    Text(
+                                      _albumGridSize.toString(),
+                                    ),
+                                    Icon(
+                                      Icons.chevron_right,
+                                      color: colorScheme.strokeMuted,
+                                    ),
+                                  ],
+                                ),
+                                borderRadius: 8,
+                                alignCaptionedTextToLeft: true,
+                                // isBottomBorderRadiusRemoved: true,
+                                isGestureDetectorDisabled: true,
+                              ),
+                            ),
+                          ],
+                        ),
+                      ],
+                    ),
+                  ),
+                );
+              },
+              childCount: 1,
+            ),
+          ),
+        ],
+      ),
+    );
+  }
+
+  Future<void> _showAlbumGridSizePicker() async {
+    final List<Text> options = [];
+    options.add(
+      Text("2", style: Theme.of(context).textTheme.subtitle1),
+    );
+    options.add(
+      Text("3", style: Theme.of(context).textTheme.subtitle1),
+    );
+    options.add(
+      Text("4", style: Theme.of(context).textTheme.subtitle1),
+    );
+    return showCupertinoModalPopup(
+      context: context,
+      builder: (context) {
+        return Column(
+          mainAxisAlignment: MainAxisAlignment.end,
+          children: <Widget>[
+            Container(
+              decoration: BoxDecoration(
+                color: Theme.of(context).colorScheme.cupertinoPickerTopColor,
+                border: const Border(
+                  bottom: BorderSide(
+                    color: Color(0xff999999),
+                    width: 0.0,
+                  ),
+                ),
+              ),
+              child: Row(
+                mainAxisAlignment: MainAxisAlignment.spaceBetween,
+                children: <Widget>[
+                  CupertinoButton(
+                    onPressed: () {
+                      Navigator.of(context).pop('cancel');
+                    },
+                    padding: const EdgeInsets.symmetric(
+                      horizontal: 8.0,
+                      vertical: 5.0,
+                    ),
+                    child: Text(
+                      'Cancel',
+                      style: Theme.of(context).textTheme.subtitle1,
+                    ),
+                  ),
+                  CupertinoButton(
+                    onPressed: () async {
+                      await _config.setAlbumGridSize(_chosenGridSize);
+                      Bus.instance.fire(
+                        ForceReloadHomeGalleryEvent("grid size changed"),
+                      );
+                      _albumGridSize = _chosenGridSize;
+                      setState(() {});
+                      Navigator.of(context).pop('');
+                    },
+                    padding: const EdgeInsets.symmetric(
+                      horizontal: 16.0,
+                      vertical: 2.0,
+                    ),
+                    child: Text(
+                      'Confirm',
+                      style: Theme.of(context).textTheme.subtitle1,
+                    ),
+                  )
+                ],
+              ),
+            ),
+            Container(
+              height: 220.0,
+              color: const Color(0xfff7f7f7),
+              child: CupertinoPicker(
+                backgroundColor:
+                    Theme.of(context).backgroundColor.withOpacity(0.95),
+                onSelectedItemChanged: (index) {
+                  _chosenGridSize = _getAlbumGridSizeFromIndex(index);
+                  setState(() {});
+                },
+                scrollController: FixedExtentScrollController(
+                  initialItem: _getIndexFromAlbumGridSize(_chosenGridSize),
+                ),
+                magnification: 1.3,
+                useMagnifier: true,
+                itemExtent: 25,
+                diameterRatio: 1,
+                children: options,
+              ),
+            )
+          ],
+        );
+      },
+    );
+  }
+
+  int _getAlbumGridSizeFromIndex(int index) {
+    return index + 2;
+  }
+
+  int _getIndexFromAlbumGridSize(int gridSize) {
+    return gridSize - 2;
+  }
+}

+ 97 - 0
lib/ui/settings/general_section_widget.dart

@@ -0,0 +1,97 @@
+// @dart=2.9
+
+import 'package:flutter/material.dart';
+import 'package:photos/services/billing_service.dart';
+import 'package:photos/services/user_service.dart';
+import 'package:photos/theme/ente_theme.dart';
+import 'package:photos/ui/advanced_settings_screen.dart';
+import 'package:photos/ui/components/captioned_text_widget.dart';
+import 'package:photos/ui/components/expandable_menu_item_widget.dart';
+import 'package:photos/ui/components/menu_item_widget.dart';
+import 'package:photos/ui/payment/subscription.dart';
+import 'package:photos/ui/settings/common_settings.dart';
+import 'package:photos/utils/dialog_util.dart';
+import 'package:photos/utils/navigation_util.dart';
+
+class GeneralSectionWidget extends StatelessWidget {
+  const GeneralSectionWidget({Key key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return ExpandableMenuItemWidget(
+      title: "General",
+      selectionOptionsWidget: _getSectionOptions(context),
+      leadingIcon: Icons.graphic_eq,
+    );
+  }
+
+  Widget _getSectionOptions(BuildContext context) {
+    return Column(
+      children: [
+        sectionOptionSpacing,
+        MenuItemWidget(
+          captionedTextWidget: const CaptionedTextWidget(
+            title: "Manage subscription",
+          ),
+          pressedColor: getEnteColorScheme(context).fillFaint,
+          trailingIcon: Icons.chevron_right_outlined,
+          trailingIconIsMuted: true,
+          onTap: () {
+            _onManageSubscriptionTapped(context);
+          },
+        ),
+        sectionOptionSpacing,
+        MenuItemWidget(
+          captionedTextWidget: const CaptionedTextWidget(
+            title: "Family plans",
+          ),
+          pressedColor: getEnteColorScheme(context).fillFaint,
+          trailingIcon: Icons.chevron_right_outlined,
+          trailingIconIsMuted: true,
+          onTap: () {
+            _onFamilyPlansTapped(context);
+          },
+        ),
+        sectionOptionSpacing,
+        MenuItemWidget(
+          captionedTextWidget: const CaptionedTextWidget(
+            title: "Advanced",
+          ),
+          pressedColor: getEnteColorScheme(context).fillFaint,
+          trailingIcon: Icons.chevron_right_outlined,
+          trailingIconIsMuted: true,
+          onTap: () {
+            _onAdvancedTapped(context);
+          },
+        ),
+        sectionOptionSpacing,
+      ],
+    );
+  }
+
+  void _onManageSubscriptionTapped(BuildContext context) {
+    Navigator.of(context).push(
+      MaterialPageRoute(
+        builder: (BuildContext context) {
+          return getSubscriptionPage();
+        },
+      ),
+    );
+  }
+
+  Future<void> _onFamilyPlansTapped(BuildContext context) async {
+    final dialog = createProgressDialog(context, "Please wait...");
+    await dialog.show();
+    final userDetails =
+        await UserService.instance.getUserDetailsV2(memoryCount: false);
+    await dialog.hide();
+    BillingService.instance.launchFamilyPortal(context, userDetails);
+  }
+
+  void _onAdvancedTapped(BuildContext context) {
+    routeToPage(
+      context,
+      const AdvancedSettingsScreen(),
+    );
+  }
+}

+ 3 - 0
lib/ui/settings_page.dart

@@ -14,6 +14,7 @@ import 'package:photos/ui/settings/app_version_widget.dart';
 import 'package:photos/ui/settings/backup_section_widget.dart';
 import 'package:photos/ui/settings/danger_section_widget.dart';
 import 'package:photos/ui/settings/debug_section_widget.dart';
+import 'package:photos/ui/settings/general_section_widget.dart';
 import 'package:photos/ui/settings/security_section_widget.dart';
 import 'package:photos/ui/settings/settings_title_bar_widget.dart';
 import 'package:photos/ui/settings/social_section_widget.dart';
@@ -91,6 +92,8 @@ class SettingsPage extends StatelessWidget {
       sectionSpacing,
       const SocialSectionWidget(),
       sectionSpacing,
+      const GeneralSectionWidget(),
+      sectionSpacing,
       const AboutSectionWidget(),
     ]);
     if (hasLoggedIn) {