From 1f77b64d9a3b94709c222c2720392bec235c248b Mon Sep 17 00:00:00 2001 From: Fmar <_@fmar.link> Date: Fri, 25 Aug 2023 17:14:56 +0200 Subject: [PATCH] remodel settings UI --- README.md | 5 +- ROADMAP.md | 3 +- lib/i18n/i18n.dart | 32 +- lib/i18n/intl/messages_en.dart | 6 +- lib/provider/setting_provider.dart | 2 +- lib/router/edit/poll_input_component.dart | 2 +- lib/router/index/index_router.dart | 82 +++-- lib/router/setting/setting_router.dart | 411 +++++++++++++--------- pubspec.lock | 8 + pubspec.yaml | 1 + 10 files changed, 304 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index 6dbaf9c3..d0ffafea 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Or you can just download them from the release's page and install it directly wi - [x] Hashtag Following and Custom Hashtags - [x] Polls ([NIP-69](https://github.com/nostr-protocol/nips/blob/master/69.md)) - [x] Relay Pages ([NIP-11](https://github.com/nostr-protocol/nips/blob/master/11.md)) +- [X] Multiple Accounts - [ ] Video/LnInvoice Previews - [ ] Public Chats ([NIP-28](https://github.com/nostr-protocol/nips/blob/master/28.md)) - [ ] Automatic Translations @@ -66,7 +67,6 @@ Or you can just download them from the release's page and install it directly wi - [ ] Login with QR - [ ] Wallet Connect API ([NIP-47](https://github.com/nostr-protocol/nips/blob/master/47.md)) - [ ] External Identity Support ([NIP-39](https://github.com/nostr-protocol/nips/blob/master/39.md)) -- [ ] Multiple Accounts - [ ] Markdown Support - [ ] Relay Authentication ([NIP-42](https://github.com/nostr-protocol/nips/blob/master/42.md)) - [ ] Content stored in relays themselves ([NIP-95](https://github.com/nostr-protocol/nips/blob/master/95.md)) @@ -103,9 +103,10 @@ Or you can just download them from the release's page and install it directly wi ## Contributions -Some initial code was used from https://github.com/haorendashu/nostrmo project +Some initial code was used from https://github.com/haorendashu/nostrmo project.\ ## Join I welcome contributors to join the project, specially Designers UI/UX, coders, testers.\ If you're not a coder but would like to see something added/implemented, or you have a great idea for a new feature, just don't hesitate to fill up a issue. +All constructive feedback is welcomed. diff --git a/ROADMAP.md b/ROADMAP.md index 835aa9d1..1df3ce76 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -11,11 +11,11 @@ - ~~store private Key in securedStorage~~ - ~~replace relays numbers with search, move numbers to drawer~~ - ~~fix zaps amounts in notes~~ +- ~~add theme icon on drawer for quick switching of dark/light theme~~ - badges when something new in home/notifications/DMS - allow to login with npub - add SystemMouseCursors.click to everything that is clickable for web version -- add theme icon on drawer for quick switching of dark/light theme - filter out new posts from replies - include reposts in following - integration with https://github.com/greenart7c3/Amber @@ -33,7 +33,6 @@ - in thread view decrease the tree branches padding to allow more space for content - only use tablet second view if horizontal tablet - fix zooming of pictures and X position -- download followed & zaps in the background, not on demand - when new user with no following, suggest jack, fiatjaf and others - Nostr Wallet Connect with balance - linux AppImage build diff --git a/lib/i18n/i18n.dart b/lib/i18n/i18n.dart index 1520d8df..3ad77493 100644 --- a/lib/i18n/i18n.dart +++ b/lib/i18n/i18n.dart @@ -140,17 +140,17 @@ class I18n { } /// `Dark` - String get Dark { + String get Dark_mode { return Intl.message( - 'Dark', - name: 'Dark', + 'Dark mode', + name: 'Dark_mode', desc: '', args: [], ); } /// `Setting` - String get Setting { + String get Settings { return Intl.message( 'Setting', name: 'Setting', @@ -162,23 +162,13 @@ class I18n { /// `Theme Style` String get Theme_Style { return Intl.message( - 'Theme Style', + 'Use theme from System', name: 'Theme_Style', desc: '', args: [], ); } - /// `Theme Color` - String get Theme_Color { - return Intl.message( - 'Theme Color', - name: 'Theme_Color', - desc: '', - args: [], - ); - } - /// `Default Color` String get Default_Color { return Intl.message( @@ -262,7 +252,7 @@ class I18n { /// `Privacy Lock` String get Privacy_Lock { return Intl.message( - 'Privacy Lock', + 'Require unlock to use', name: 'Privacy_Lock', desc: '', args: [], @@ -440,10 +430,10 @@ class I18n { } /// `Video preview in list` - String get Video_preview_in_list { + String get Video_preview { return Intl.message( - 'Video preview in list', - name: 'Video_preview_in_list', + 'Video preview', + name: 'Video_preview', desc: '', args: [], ); @@ -480,9 +470,9 @@ class I18n { } /// `Forbid image` - String get Forbid_image { + String get Image_preview { return Intl.message( - 'Forbid image', + 'Image Preview', name: 'Forbid_image', desc: '', args: [], diff --git a/lib/i18n/intl/messages_en.dart b/lib/i18n/intl/messages_en.dart index 90e53cd8..abea583f 100644 --- a/lib/i18n/intl/messages_en.dart +++ b/lib/i18n/intl/messages_en.dart @@ -113,7 +113,7 @@ class MessageLookup extends MessageLookupByLibrary { "Font_Family": MessageLookupByLibrary.simpleMessage("Font Family"), "Font_Size": MessageLookupByLibrary.simpleMessage("Font Size"), "Forbid": MessageLookupByLibrary.simpleMessage("Forbid"), - "Forbid_image": MessageLookupByLibrary.simpleMessage("Forbid image"), + "Forbid_image": MessageLookupByLibrary.simpleMessage("Image preview"), "Forbid_video": MessageLookupByLibrary.simpleMessage("Forbid video"), "From": MessageLookupByLibrary.simpleMessage("From"), "Gen_invoice_code_error": @@ -224,7 +224,7 @@ class MessageLookup extends MessageLookupByLibrary { "Posts": MessageLookupByLibrary.simpleMessage("Posts"), "Posts_and_replies": MessageLookupByLibrary.simpleMessage("Posts & Replies"), - "Privacy_Lock": MessageLookupByLibrary.simpleMessage("Privacy Lock"), + "Privacy_Lock": MessageLookupByLibrary.simpleMessage("Require unlock to use"), "Private_key_is_null": MessageLookupByLibrary.simpleMessage("Private key is null."), "Quote": MessageLookupByLibrary.simpleMessage("Quote"), @@ -258,7 +258,7 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage( "The key is a random string that resembles your account password. Anyone with this key can access and control your account."), "Theme_Color": MessageLookupByLibrary.simpleMessage("Theme Color"), - "Theme_Style": MessageLookupByLibrary.simpleMessage("Theme Style"), + "Theme_Style": MessageLookupByLibrary.simpleMessage("Use Theme from System"), "There_should_be_a_universe_here": MessageLookupByLibrary.simpleMessage( "There should be a universe here"), "This_note_contains_sensitive_content": diff --git a/lib/provider/setting_provider.dart b/lib/provider/setting_provider.dart index b38f81ec..62873d13 100644 --- a/lib/provider/setting_provider.dart +++ b/lib/provider/setting_provider.dart @@ -205,7 +205,7 @@ class SettingProvider extends ChangeNotifier { int? get openTranslate => _settingData!.openTranslate; static const ALL_SUPPORT_LANGUAGES = - "af,sq,ar,be,bn,bg,ca,zh,hr,cs,da,nl,en,eo,et,fi,fr,gl,ka,de,el,gu,ht,he,hi,hu,is,id,ga,it,ja,kn,ko,lv,lt,mk,ms,mt,mr,no,fa,pl,pt,ro,ru,sk,sl,es,sw,sv,tl,ta,te,th,tr,uk,ur,vi,cy"; + "en"; String? get translateSourceArgs { if (StringUtil.isNotBlank(_settingData!.translateSourceArgs)) { diff --git a/lib/router/edit/poll_input_component.dart b/lib/router/edit/poll_input_component.dart index 9886f581..49befcf1 100644 --- a/lib/router/edit/poll_input_component.dart +++ b/lib/router/edit/poll_input_component.dart @@ -111,7 +111,7 @@ class _PollInputComponent extends State { onPressed: () { delPollOption(controller); }, - icon: Icon(Icons.delete)), + icon: const Icon(Icons.delete)), ], ); } diff --git a/lib/router/index/index_router.dart b/lib/router/index/index_router.dart index 99e4a671..2cf84636 100644 --- a/lib/router/index/index_router.dart +++ b/lib/router/index/index_router.dart @@ -255,64 +255,62 @@ class _IndexRouter extends CustState floatingActionButton: addBtn, floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, body: Row(children: [ - Container( + SizedBox( width: column0Width, - child: IndexDrawerContnetComponnent(), + child: IndexDrawerContentComponent(reload: widget.reload), ), Container( width: column1Width, - margin: EdgeInsets.only( + margin: const EdgeInsets.only( // left: 1, right: 1, ), child: mainIndex, ), Expanded( - child: Container( - child: Selector>( - builder: (context, infos, child) { - if (infos.isEmpty) { - return Container( - child: Center( - child: Text(s.There_should_be_a_universe_here), - ), - ); - } + child: Selector>( + builder: (context, infos, child) { + if (infos.isEmpty) { + return Container( + child: Center( + child: Text(s.There_should_be_a_universe_here), + ), + ); + } - List pages = []; - for (var info in infos) { - if (StringUtil.isNotBlank(info.routerPath) && - routes[info.routerPath] != null) { - var builder = routes[info.routerPath]; - if (builder != null) { - pages.add(PcRouterFake( - info: info, - child: builder(context), - )); - } - } else if (info.buildContent != null) { + List pages = []; + for (var info in infos) { + if (StringUtil.isNotBlank(info.routerPath) && + routes[info.routerPath] != null) { + var builder = routes[info.routerPath]; + if (builder != null) { pages.add(PcRouterFake( info: info, - child: info.buildContent!(context), + child: builder(context), )); } + } else if (info.buildContent != null) { + pages.add(PcRouterFake( + info: info, + child: info.buildContent!(context), + )); } + } - return IndexedStack( - index: pages.length - 1, - children: pages, - ); - }, - selector: (context, _provider) { - return _provider.routerFakeInfos; - }, - shouldRebuild: (previous, next) { - if (previous != next) { - return true; - } - return false; - }, - ), + return IndexedStack( + index: pages.length - 1, + children: pages, + ); + }, + selector: (context, _provider) { + return _provider.routerFakeInfos; + }, + shouldRebuild: (previous, next) { + if (previous != next) { + return true; + } + return false; + }, ), ) ]), @@ -334,7 +332,7 @@ class _IndexRouter extends CustState floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, drawer: Drawer( - child: IndexDrawerContnetComponnent(), + child: IndexDrawerContentComponent(reload: widget.reload), ), // extendBodyBehindAppBar: true, bottomNavigationBar: AnimatedContainer( diff --git a/lib/router/setting/setting_router.dart b/lib/router/setting/setting_router.dart index d5b13a55..17bf6585 100644 --- a/lib/router/setting/setting_router.dart +++ b/lib/router/setting/setting_router.dart @@ -7,6 +7,7 @@ import 'package:flutter_font_picker/flutter_font_picker.dart'; import 'package:google_mlkit_translation/google_mlkit_translation.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; +import 'package:settings_ui/settings_ui.dart'; import 'package:yana/models/event_mem_box.dart'; import 'package:yana/nostr/filter.dart'; import 'package:yana/nostr/nip02/cust_contact_list.dart'; @@ -15,25 +16,22 @@ import 'package:yana/utils/platform_util.dart'; import 'package:yana/utils/router_util.dart'; import 'package:yana/utils/when_stop_function.dart'; -import '../../utils/base.dart'; -import '../../utils/base_consts.dart'; -import '../../utils/image_services.dart'; -import '../../utils/theme_style.dart'; import '../../i18n/i18n.dart'; import '../../main.dart'; import '../../models/metadata.dart'; import '../../nostr/event.dart'; import '../../nostr/event_kind.dart' as kind; import '../../provider/setting_provider.dart'; -import '../../ui/colors_selector_component.dart'; import '../../ui/comfirm_dialog.dart'; -import '../../ui/editor/text_input_dialog.dart'; import '../../ui/enum_multi_selector_component.dart'; import '../../ui/enum_selector_component.dart'; import '../../ui/translate/translate_model_manager.dart'; import '../../utils/auth_util.dart'; +import '../../utils/base_consts.dart'; +import '../../utils/image_services.dart'; import '../../utils/locale_util.dart'; import '../../utils/string_util.dart'; +import '../../utils/theme_style.dart'; import 'setting_group_item_component.dart'; import 'setting_group_title_component.dart'; @@ -41,6 +39,7 @@ class SettingRouter extends StatefulWidget { Function indexReload; SettingRouter({ + super.key, required this.indexReload, }); @@ -51,9 +50,6 @@ class SettingRouter extends StatefulWidget { } class _SettingRouter extends State with WhenStopFunction { - void resetTheme() { - widget.indexReload(); - } @override Widget build(BuildContext context) { @@ -78,33 +74,33 @@ class _SettingRouter extends State with WhenStopFunction { List list = []; - list.add( - SettingGroupItemComponent( - name: s.Language, - value: getI18nList(_settingProvider.i18n, _settingProvider.i18nCC).name, - onTap: pickI18N, - ), - ); + // list.add( + // SettingGroupItemComponent( + // name: s.Language, + // value: getI18nList(_settingProvider.i18n, _settingProvider.i18nCC).name, + // onTap: pickI18N, + // ), + // ); // list.add(SettingGroupItemComponent( // name: s.Image_Compress, // value: getCompressList(settingProvider.imgCompress).name, // onTap: pickImageCompressList, // )); - if (!PlatformUtil.isPC()) { - list.add(SettingGroupItemComponent( - name: s.Privacy_Lock, - value: getLockOpenList(settingProvider.lockOpen).name, - onTap: pickLockOpenList, - )); - } - List defaultTabList = defaultTabListTimeline!; - list.add(SettingGroupItemComponent( - name: s.Default_tab, - value: getDefaultTab(defaultTabList, settingProvider.defaultTab).name, - onTap: () { - pickDefaultTab(defaultTabList); - }, - )); + // if (!PlatformUtil.isPC()) { + // list.add(SettingGroupItemComponent( + // name: s.Privacy_Lock, + // value: getLockOpenList(settingProvider.lockOpen).name, + // onTap: pickLockOpenList, + // )); + // } + // List defaultTabList = defaultTabListTimeline!; + // list.add(SettingGroupItemComponent( + // name: s.Default_tab, + // value: getDefaultTab(defaultTabList, settingProvider.defaultTab).name, + // onTap: () { + // pickDefaultTab(defaultTabList); + // }, + // )); list.add(SettingGroupTitleComponent(iconData: Icons.palette, title: "UI")); list.add( @@ -114,37 +110,28 @@ class _SettingRouter extends State with WhenStopFunction { onTap: pickThemeStyle, ), ); - list.add(SettingGroupItemComponent( - name: s.Theme_Color, - onTap: pickColor, - child: Container( - height: 28, - width: 28, - color: mainColor, - ), - )); - list.add(SettingGroupItemComponent( - name: s.Font_Family, - value: getFontEnumResult(settingProvider.fontFamily), - onTap: pickFontEnum, - )); - list.add(SettingGroupItemComponent( - name: s.Font_Size, - value: getFontSize(settingProvider.fontSize).name, - onTap: pickFontSize, - )); - list.add(SettingGroupItemComponent( - name: s.Web_Appbar, - value: getOpenList(settingProvider.webviewAppbarOpen).name, - onTap: pickWebviewAppbar, - )); - if (!PlatformUtil.isPC()) { - list.add(SettingGroupItemComponent( - name: s.Table_Mode, - value: getOpenMode(settingProvider.tableMode).name, - onTap: pickOpenMode, - )); - } + // list.add(SettingGroupItemComponent( + // name: s.Font_Family, + // value: getFontEnumResult(settingProvider.fontFamily), + // onTap: pickFontEnum, + // )); + // list.add(SettingGroupItemComponent( + // name: s.Font_Size, + // value: getFontSize(settingProvider.fontSize).name, + // onTap: pickFontSize, + // )); + // list.add(SettingGroupItemComponent( + // name: s.Web_Appbar, + // value: getOpenList(settingProvider.webviewAppbarOpen).name, + // onTap: pickWebviewAppbar, + // )); + // if (!PlatformUtil.isPC()) { + // list.add(SettingGroupItemComponent( + // name: s.Table_Mode, + // value: getOpenMode(settingProvider.tableMode).name, + // onTap: pickOpenMode, + // )); + // } list.add( SettingGroupTitleComponent(iconData: Icons.article, title: s.Global)); @@ -155,87 +142,170 @@ class _SettingRouter extends State with WhenStopFunction { )); if (!PlatformUtil.isPC()) { list.add(SettingGroupItemComponent( - name: s.Video_preview_in_list, + name: s.Video_preview, value: getOpenList(settingProvider.videoPreviewInList).name, onTap: pickVideoPreviewInList, )); } - String? networkHintText = settingProvider.network; - if (StringUtil.isBlank(networkHintText)) { - networkHintText = s.Please_input + " " + s.Network; - } - Widget networkWidget = Text( - networkHintText!, - style: TextStyle( - color: hintColor, - overflow: TextOverflow.ellipsis, - fontWeight: FontWeight.bold, - fontSize: 16, - ), - ); - list.add(SettingGroupItemComponent( - name: s.Network, - onTap: inputNetwork, - child: networkWidget, - )); - list.add(SettingGroupItemComponent( - name: s.Image_service, - value: getImageServcie(settingProvider.imageService).name, - onTap: pickImageServcie, - )); + // list.add(SettingGroupItemComponent( + // name: s.Image_service, + // value: getImageServcie(settingProvider.imageService).name, + // onTap: pickImageServcie, + // )); list.add(SettingGroupItemComponent( - name: s.Forbid_image, + name: s.Image_preview, value: getOpenList(settingProvider.imagePreview).name, onTap: pickImagePreview, )); + // if (!PlatformUtil.isPC()) { + // list.add(SettingGroupItemComponent( + // name: s.Forbid_video, + // value: getOpenList(settingProvider.videoPreview).name, + // onTap: pickVideoPreview, + // )); + // list.add(SettingGroupItemComponent( + // name: s.Translate, + // value: getOpenTranslate(settingProvider.openTranslate).name, + // onTap: pickOpenTranslate, + // )); + // if (settingProvider.openTranslate == OpenStatus.OPEN) { + // list.add(SettingGroupItemComponent( + // name: s.Translate_Source_Language, + // value: settingProvider.translateSourceArgs, + // onTap: pickTranslateSource, + // )); + // list.add(SettingGroupItemComponent( + // name: s.Translate_Target_Language, + // value: settingProvider.translateTarget, + // onTap: pickTranslateTarget, + // )); + // } + // } + // list.add(SettingGroupItemComponent( + // name: s.Broadcast_When_Boost, + // value: getOpenList(settingProvider.broadcaseWhenBoost).name, + // onTap: pickBroadcaseWhenBoost, + // )); + // list.add(SettingGroupItemComponent( + // name: s.Auto_Open_Sensitive_Content, + // value: getOpenListDefault(settingProvider.autoOpenSensitive).name, + // onTap: pickAutoOpenSensitive, + // )); + // + // list.add(SettingGroupTitleComponent(iconData: Icons.source, title: s.Data)); + // list.add(SettingGroupItemComponent( + // name: s.Delete_Account, + // nameColor: Colors.red, + // onTap: askToDeleteAccount, + // )); + + list.add(SliverToBoxAdapter( + child: Container( + height: 30, + ), + )); + + List interfaceTiles = []; + interfaceTiles.add(SettingsTile.navigation( + leading: const Icon(Icons.language), + title: Text(s.Language), + value: const Text('English'), + onPressed: (context) { + pickI18N(); + }, + )); + + interfaceTiles.add(SettingsTile.switchTile( + onToggle: (value) { + settingProvider.themeStyle = value ? ThemeStyle.AUTO : ThemeStyle.LIGHT; + widget.indexReload(); + }, + initialValue: settingProvider.themeStyle == ThemeStyle.AUTO, + leading: const Icon(Icons.lan), + title: Text(s.Theme_Style))); + + interfaceTiles.add(SettingsTile.switchTile( + enabled: settingProvider.themeStyle != ThemeStyle.AUTO, + onToggle: (value) { + settingProvider.themeStyle = value ? ThemeStyle.DARK : ThemeStyle.LIGHT; + widget.indexReload(); + }, + + initialValue: settingProvider.themeStyle == ThemeStyle.DARK, + leading: const Icon(Icons.dark_mode_outlined), + title: Text(s.Dark_mode))); + + interfaceTiles.add(SettingsTile.switchTile( + onToggle: (value) { + settingProvider.linkPreview = value ? 1 : 0; + }, + initialValue: settingProvider.linkPreview == OpenStatus.OPEN , + leading: const Icon(Icons.link_outlined), + title: Text(s.Link_preview))); + interfaceTiles.add(SettingsTile.switchTile( + onToggle: (value) { + settingProvider.imagePreview = value ? 1 : 0; + }, + initialValue: settingProvider.imagePreview == OpenStatus.OPEN, + leading: const Icon(Icons.image_outlined), + title: Text(s.Image_preview))); + interfaceTiles.add(SettingsTile.switchTile( + onToggle: (value) { + settingProvider.videoPreviewInList = value ? 1 : 0; + }, + initialValue: settingProvider.videoPreviewInList == OpenStatus.OPEN, + leading: const Icon(Icons.video_collection_outlined), + title: Text(s.Video_preview))); + + List securityTiles = []; + if (!PlatformUtil.isPC()) { - list.add(SettingGroupItemComponent( - name: s.Forbid_video, - value: getOpenList(settingProvider.videoPreview).name, - onTap: pickVideoPreview, - )); - list.add(SettingGroupItemComponent( - name: s.Translate, - value: getOpenTranslate(settingProvider.openTranslate).name, - onTap: pickOpenTranslate, + securityTiles.add(SettingsTile.switchTile( + onToggle: (value) { + authenticate( + value, s.Please_authenticate_to_turn_off_the_privacy_lock); + }, + initialValue: settingProvider.lockOpen == OpenStatus.OPEN, + leading: const Icon(Icons.lock_open), + title: Text(s.Privacy_Lock), )); - if (settingProvider.openTranslate == OpenStatus.OPEN) { - list.add(SettingGroupItemComponent( - name: s.Translate_Source_Language, - value: settingProvider.translateSourceArgs, - onTap: pickTranslateSource, - )); - list.add(SettingGroupItemComponent( - name: s.Translate_Target_Language, - value: settingProvider.translateTarget, - onTap: pickTranslateTarget, - )); - } } - list.add(SettingGroupItemComponent( - name: s.Broadcast_When_Boost, - value: getOpenList(settingProvider.broadcaseWhenBoost).name, - onTap: pickBroadcaseWhenBoost, - )); - list.add(SettingGroupItemComponent( - name: s.Auto_Open_Sensitive_Content, - value: getOpenListDefault(settingProvider.autoOpenSensitive).name, - onTap: pickAutoOpenSensitive, - )); - list.add(SettingGroupTitleComponent(iconData: Icons.source, title: s.Data)); - list.add(SettingGroupItemComponent( - name: s.Delete_Account, - nameColor: Colors.red, - onTap: askToDeleteAccount, + List accountTiles = []; + + accountTiles.add(SettingsTile.navigation( + trailing: const Text(""), + onPressed: (context) { + var index = settingProvider.privateKeyIndex; + if (index != null) { + AccountsState.onLogoutTap(index, routerBack: true, context: context); + metadataProvider.clear(); + } else { + nostr = null; + } + }, + leading: const Icon(Icons.logout), + title: const Text("Logout"), )); - list.add(SliverToBoxAdapter( - child: Container( - height: 30, - ), + accountTiles.add(SettingsTile.navigation( + trailing: const Text(""), + onPressed: (context) { + askToDeleteAccount(); + }, + leading: const Icon(Icons.delete_outline), + title: Text(s.Delete_Account, style: const TextStyle(color: Colors.red)), )); + SettingsList settingsList = SettingsList( + applicationType: ApplicationType.both, + sections: [ + SettingsSection(title: Text('Interface'), tiles: interfaceTiles), + SettingsSection(title: Text('Security'), tiles: securityTiles), + SettingsSection(title: Text('Account'), tiles: accountTiles), + ], + ); + return Scaffold( appBar: AppBar( leading: GestureDetector( @@ -248,23 +318,24 @@ class _SettingRouter extends State with WhenStopFunction { ), ), title: Text( - s.Setting, + s.Settings, style: TextStyle( fontWeight: FontWeight.bold, fontSize: titleFontSize, ), ), ), - body: Container( - margin: EdgeInsets.only(top: Base.BASE_PADDING), - padding: EdgeInsets.only( - left: 20, - right: 20, - ), - child: CustomScrollView( - slivers: list, - ), - ), + body: + // CustomScrollView( + // slivers: list, + // ), + Container( + // margin: const EdgeInsets.only(top: Base.BASE_PADDING), + // padding: const EdgeInsets.only( + // left: 20, + // right: 20, + // ), + child: settingsList), ); } @@ -335,7 +406,7 @@ class _SettingRouter extends State with WhenStopFunction { } } } - resetTheme(); + widget.indexReload(); Future.delayed(Duration(seconds: 1), () { setState(() { // TODO others setting enumObjList @@ -419,6 +490,7 @@ class _SettingRouter extends State with WhenStopFunction { } } } + List? defaultTabListTimeline; void initDefaultTabListTimeline(I18n s) { @@ -434,7 +506,7 @@ class _SettingRouter extends State with WhenStopFunction { EnumObj? resultEnumObj = await EnumSelectorComponent.show(context, list); if (resultEnumObj != null) { settingProvider.defaultTab = resultEnumObj.value; - resetTheme(); + widget.indexReload(); } } @@ -454,7 +526,7 @@ class _SettingRouter extends State with WhenStopFunction { themeStyleList = []; themeStyleList?.add(EnumObj(ThemeStyle.AUTO, s.Follow_System)); themeStyleList?.add(EnumObj(ThemeStyle.LIGHT, s.Light)); - themeStyleList?.add(EnumObj(ThemeStyle.DARK, s.Dark)); + themeStyleList?.add(EnumObj(ThemeStyle.DARK, s.Dark_mode)); } } @@ -463,7 +535,7 @@ class _SettingRouter extends State with WhenStopFunction { await EnumSelectorComponent.show(context, themeStyleList!); if (resultEnumObj != null) { settingProvider.themeStyle = resultEnumObj.value; - resetTheme(); + widget.indexReload(); } } @@ -476,14 +548,6 @@ class _SettingRouter extends State with WhenStopFunction { return themeStyleList![0]; } - Future pickColor() async { - Color? color = await ColorSelectorComponent.show(context); - if (color != null) { - settingProvider.themeColor = color.value; - resetTheme(); - } - } - List? fontEnumList; void initFontEnumList(I18n s) { @@ -509,7 +573,7 @@ class _SettingRouter extends State with WhenStopFunction { pickFont(); } else { settingProvider.fontFamily = null; - resetTheme(); + widget.indexReload(); } } } @@ -520,7 +584,7 @@ class _SettingRouter extends State with WhenStopFunction { builder: (context) => FontPicker( onFontChanged: (PickerFont font) { settingProvider.fontFamily = font.fontFamily; - resetTheme(); + widget.indexReload(); }, ), ), @@ -553,7 +617,7 @@ class _SettingRouter extends State with WhenStopFunction { await EnumSelectorComponent.show(context, fontSizeList); if (resultEnumObj != null) { settingProvider.fontSize = resultEnumObj.value; - resetTheme(); + widget.indexReload(); } } @@ -573,41 +637,30 @@ class _SettingRouter extends State with WhenStopFunction { } } - inputNetwork() async { - var s = I18n.of(context); - var text = await TextInputDialog.show( - context, - "${s.Please_input} ${s.Network}\nSOCKS5/SOCKS4/PROXY username:password@host:port", - value: settingProvider.network, - ); - settingProvider.network = text; - BotToast.showText(text: s.network_take_effect_tip); - } - - List? imageServcieList; + List? imageServiceList; void initImageServcieList() { - if (imageServcieList == null) { - imageServcieList = []; - imageServcieList! + if (imageServiceList == null) { + imageServiceList = []; + imageServiceList! .add(EnumObj(ImageServices.NOSTRIMG_COM, ImageServices.NOSTRIMG_COM)); - imageServcieList! + imageServiceList! .add(EnumObj(ImageServices.NOSTR_BUILD, ImageServices.NOSTR_BUILD)); } } EnumObj getImageServcie(String? o) { - for (var eo in imageServcieList!) { + for (var eo in imageServiceList!) { if (eo.value == o) { return eo; } } - return imageServcieList![0]; + return imageServiceList![0]; } Future pickImageServcie() async { EnumObj? resultEnumObj = - await EnumSelectorComponent.show(context, imageServcieList!); + await EnumSelectorComponent.show(context, imageServiceList!); if (resultEnumObj != null) { settingProvider.imageService = resultEnumObj.value; } @@ -692,8 +745,7 @@ class _SettingRouter extends State with WhenStopFunction { } finally { var index = settingProvider.privateKeyIndex; if (index != null) { - AccountsState.onLogoutTap(index, - routerBack: true, context: context); + AccountsState.onLogoutTap(index, routerBack: true, context: context); metadataProvider.clear(); } else { nostr = null; @@ -781,7 +833,8 @@ class _SettingRouter extends State with WhenStopFunction { bcpCodes.add(translateTarget!); var translateModelManager = TranslateModelManager.getInstance(); - BotToast.showText(text: I18n.of(context).Begin_to_download_translate_model); + BotToast.showText( + text: I18n.of(context).Begin_to_download_translate_model); var cancelFunc = BotToast.showLoading(); try { await translateModelManager.checkAndDownloadTargetModel(bcpCodes); @@ -843,7 +896,13 @@ class _SettingRouter extends State with WhenStopFunction { await EnumSelectorComponent.show(context, openList!); if (resultEnumObj != null) { settingProvider.tableMode = resultEnumObj.value; - resetTheme(); + widget.indexReload(); + } + } + + void authenticate(value, text) async { + if (await AuthUtil.authenticate(context, text)) { + settingProvider.lockOpen = value ? 1 : 0; } } } diff --git a/pubspec.lock b/pubspec.lock index caf0a1cd..c61f8d07 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1285,6 +1285,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + settings_ui: + dependency: "direct main" + description: + name: settings_ui + sha256: d9838037cb554b24b4218b2d07666fbada3478882edefae375ee892b6c820ef3 + url: "https://pub.dev" + source: hosted + version: "2.0.2" share_plus: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 4bfb11a2..a35717b1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -103,6 +103,7 @@ dependencies: package_info_plus: ^4.1.0 assorted_layout_widgets: ^8.0.4 flutter_secure_storage: ^8.0.0 + settings_ui: ^2.0.2 dev_dependencies: flutter_launcher_icons: ^0.13.1