From 5a1fb0b23d4938310b5f05c2dbfa4d00a373c542 Mon Sep 17 00:00:00 2001 From: singularity Date: Fri, 30 Apr 2021 11:20:30 +0800 Subject: [PATCH 1/3] Support image tags in preview --- lib/generated/intl/messages_en.dart | 1 + lib/generated/intl/messages_zh.dart | 1 + lib/generated/l10n.dart | 10 ++++++++++ lib/l10n/intl_en.arb | 1 + lib/l10n/intl_zh.arb | 1 + lib/page/subpage_bbs.dart | 2 ++ 6 files changed, 16 insertions(+) diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 41de6d05..63f184b9 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -116,6 +116,7 @@ class MessageLookup extends MessageLookupByLibrary { "handan_campus" : MessageLookupByLibrary.simpleMessage("Handan"), "hour_ago" : m3, "i_see" : MessageLookupByLibrary.simpleMessage("OK"), + "image_tag" : MessageLookupByLibrary.simpleMessage("[Image]"), "jiangwan_campus" : MessageLookupByLibrary.simpleMessage("Jiangwan"), "last_15_days" : MessageLookupByLibrary.simpleMessage("Last 15 days"), "last_30_days" : MessageLookupByLibrary.simpleMessage("Last 30 days"), diff --git a/lib/generated/intl/messages_zh.dart b/lib/generated/intl/messages_zh.dart index 2dc22eb9..c6e98b42 100644 --- a/lib/generated/intl/messages_zh.dart +++ b/lib/generated/intl/messages_zh.dart @@ -101,6 +101,7 @@ class MessageLookup extends MessageLookupByLibrary { "handan_campus" : MessageLookupByLibrary.simpleMessage("邯郸校区"), "hour_ago" : m3, "i_see" : MessageLookupByLibrary.simpleMessage("好"), + "image_tag" : MessageLookupByLibrary.simpleMessage("[图片]"), "jiangwan_campus" : MessageLookupByLibrary.simpleMessage("江湾校区"), "last_15_days" : MessageLookupByLibrary.simpleMessage("过去 15 天"), "last_30_days" : MessageLookupByLibrary.simpleMessage("过去 30 天"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 69292e71..386c816e 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -1015,6 +1015,16 @@ class S { ); } + /// `[Image]` + String get image_tag { + return Intl.message( + '[Image]', + name: 'image_tag', + desc: '', + args: [], + ); + } + /// `Classroom` String get classroom { return Intl.message( diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 95f67b1d..f110e4f2 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -101,6 +101,7 @@ "end_reached": "You have reached the end.", "latest_reply": "[{username}] replied {date}:", "no_summary": "[Unable to display content of this type.]", + "image_tag": "[Image]", "classroom": "Classroom", "morning": "Morning", diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index 6271be51..9405e45d 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -98,6 +98,7 @@ "end_reached": "已经到底了", "latest_reply": "[{username}] 于{date}回复:", "no_summary": "[无法显示此类型的消息]", + "image_tag": "[图片]", "classroom": "教室", "morning": "上午", diff --git a/lib/page/subpage_bbs.dart b/lib/page/subpage_bbs.dart index 477b8f15..514b0931 100644 --- a/lib/page/subpage_bbs.dart +++ b/lib/page/subpage_bbs.dart @@ -258,6 +258,8 @@ class _BBSSubpageState extends State /// Render the text from a clip of [html]. String _renderTitle(String html) { var soup = Beautifulsoup(html); + var images = soup.find_all("img"); + if (images.length > 0) return soup.get_text() + S.of(context).image_tag; return soup.get_text(); } From 6ad12d79749522e184180e654b98c10a3827b83d Mon Sep 17 00:00:00 2001 From: singularity Date: Fri, 30 Apr 2021 14:51:12 +0800 Subject: [PATCH 2/3] Add search & sort button UI stubs --- lib/main.dart | 94 +++++++++++++++++++++++++++++++-------- lib/page/subpage_bbs.dart | 23 +++++++++- 2 files changed, 97 insertions(+), 20 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 050606ba..2b19104e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -217,7 +217,7 @@ class _HomePageState extends State with WidgetsBindingObserver { } /// List of all of the subpages' action button icon. They will show on the appbar of each tab page. - final List _subpageActionButtonIconBuilders = [ + final List _subpageRightmostActionButtonIconBuilders = [ (cxt) => null, (cxt) => PlatformX.isAndroid ? PlatformIcons(cxt).add : SFSymbols.plus_circle, @@ -225,13 +225,41 @@ class _HomePageState extends State with WidgetsBindingObserver { (cxt) => null ]; + final List _subpageRightsecondActionButtonIconBuilders = [ + (cxt) => null, + (cxt) => PlatformIcons(cxt).search, + (cxt) => null, + (cxt) => null + ]; + + final List _subpageLeadingActionButtonIconBuilders = [ + (cxt) => null, + (cxt) => SFSymbols.sort_down, + (cxt) => null, + (cxt) => null + ]; + /// List of all of the subpage action buttons' description. They will show on the appbar of each tab page. - final List _subpageActionButtonTextBuilders = [ + final List _subpageRightmostActionButtonTextBuilders = [ (cxt) => null, (cxt) => S.of(cxt).new_post, (cxt) => S.of(cxt).share, (cxt) => null, ]; + + final List _subpageRightsecondActionButtonTextBuilders = [ + (cxt) => null, + (cxt) => S.of(cxt).new_post, //TODO: search + (cxt) => null, + (cxt) => null, + ]; + + final List _subpageLeadingActionButtonTextBuilders = [ + (cxt) => null, + (cxt) => S.of(cxt).new_post, //TODO: sort by + (cxt) => null, + (cxt) => null, + ]; @override void dispose() { @@ -367,17 +395,32 @@ class _HomePageState extends State with WidgetsBindingObserver { } /// When user clicks the action button on appbar - void _onPressActionButton() async { + void _onPressRightmostActionButton() async { switch (_pageIndex.value) { - case 0: - break; + //Entries omitted case 1: AddNewPostEvent().fire(); break; case 2: ShareTimetableEvent().fire(); break; - case 3: + } + } + + void _onPressRightsecondActionButton() async { + switch (_pageIndex.value) { + //Entries omitted + case 1: + AddNewPostEvent().fire(); //TODO: search event + break; + } + } + + void _onPressLeadingActionButton() async { + switch (_pageIndex.value) { + //Entries omitted + case 1: + AddNewPostEvent().fire(); //TODO: change sort order break; } } @@ -394,9 +437,9 @@ class _HomePageState extends State with WidgetsBindingObserver { trailingActions: [ PlatformIconButton( padding: EdgeInsets.zero, - icon: Icon(_subpageActionButtonIconBuilders[_pageIndex.value]( + icon: Icon(_subpageRightmostActionButtonIconBuilders[_pageIndex.value]( context)), - onPressed: _onPressActionButton, + onPressed: _onPressRightmostActionButton, ) ], ), @@ -407,13 +450,6 @@ class _HomePageState extends State with WidgetsBindingObserver { iosContentPadding: _subpage[_pageIndex.value].needPadding, appBar: PlatformAppBar( cupertino: (_, __) => CupertinoNavigationBarData( - // Issue with cupertino where a bar with no transparency - // will push the list down. Adding some alpha value fixes it (in a hacky way) - //backgroundColor: Colors.white.withAlpha(254), - /*leading: MediaQuery( - data: MediaQueryData(textScaleFactor: MediaQuery.textScaleFactorOf(context)), - child: CupertinoNavigationBarBackButton(), - ),*/ title: MediaQuery( data: MediaQueryData( textScaleFactor: MediaQuery.textScaleFactorOf(context)), @@ -434,17 +470,37 @@ class _HomePageState extends State with WidgetsBindingObserver { onDoubleTap: () => ScrollToTopEvent().fire(), ), ), + leading: PlatformIconButton( + material: (_, __) => MaterialIconButtonData( + tooltip: + _subpageLeadingActionButtonTextBuilders[_pageIndex.value]( + context)), + padding: EdgeInsets.zero, + icon: Icon(_subpageLeadingActionButtonIconBuilders[_pageIndex.value]( + context)), + onPressed: _onPressLeadingActionButton, + ), trailingActions: [ PlatformIconButton( material: (_, __) => MaterialIconButtonData( tooltip: - _subpageActionButtonTextBuilders[_pageIndex.value]( + _subpageRightsecondActionButtonTextBuilders[_pageIndex.value]( + context)), + padding: EdgeInsets.zero, + icon: Icon(_subpageRightsecondActionButtonIconBuilders[_pageIndex.value]( + context)), + onPressed: _onPressRightsecondActionButton, + ), + PlatformIconButton( + material: (_, __) => MaterialIconButtonData( + tooltip: + _subpageRightmostActionButtonTextBuilders[_pageIndex.value]( context)), padding: EdgeInsets.zero, - icon: Icon(_subpageActionButtonIconBuilders[_pageIndex.value]( + icon: Icon(_subpageRightmostActionButtonIconBuilders[_pageIndex.value]( context)), - onPressed: _onPressActionButton, - ) + onPressed: _onPressRightmostActionButton, + ), ], ), body: MultiProvider( diff --git a/lib/page/subpage_bbs.dart b/lib/page/subpage_bbs.dart index 514b0931..caaa6eb2 100644 --- a/lib/page/subpage_bbs.dart +++ b/lib/page/subpage_bbs.dart @@ -53,13 +53,16 @@ class BBSSubpage extends PlatformSubpage { } class AddNewPostEvent {} - class RetrieveNewPostEvent {} +class SearchEvent {} +class SortOrderChangedEvent {} class _BBSSubpageState extends State with AutomaticKeepAliveClientMixin { static StreamSubscription _postSubscription; static StreamSubscription _refreshSubscription; + static StreamSubscription _searchSubscription; + static StreamSubscription _sortOrderChangedSubscription; static StreamSubscription _goTopSubscription; ScrollController _controller = ScrollController(); HtmlEditorController controller = HtmlEditorController(); @@ -115,6 +118,20 @@ class _BBSSubpageState extends State TopController.scrollToTop(_controller); }); } + if (_searchSubscription == null) { + _searchSubscription = + Constant.eventBus.on().listen((event) { + //TODO: show search view + }); + } + if (_sortOrderChangedSubscription == null) { + _sortOrderChangedSubscription = + Constant.eventBus.on().listen((event) { + //TODO: change sort order + }); + } + + if (_controller != null) { // Over-scroll event _controller.addListener(_scrollListener); @@ -137,8 +154,12 @@ class _BBSSubpageState extends State super.dispose(); if (_postSubscription != null) _postSubscription.cancel(); if (_refreshSubscription != null) _refreshSubscription.cancel(); + if (_searchSubscription != null) _searchSubscription.cancel(); + if (_sortOrderChangedSubscription != null) _sortOrderChangedSubscription.cancel(); _postSubscription = null; _refreshSubscription = null; + _searchSubscription = null; + _sortOrderChangedSubscription = null; _controller.removeListener(_scrollListener); } From cdb0a665c399cb756f527d9a016f4704d728b8cc Mon Sep 17 00:00:00 2001 From: singularity Date: Fri, 30 Apr 2021 17:47:43 +0800 Subject: [PATCH 3/3] Refresh homepage only on campus change --- lib/main.dart | 4 ++-- lib/page/subpage_main.dart | 19 +++++++++++++++++++ lib/page/subpage_settings.dart | 3 ++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 2b19104e..bb657d23 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -227,14 +227,14 @@ class _HomePageState extends State with WidgetsBindingObserver { final List _subpageRightsecondActionButtonIconBuilders = [ (cxt) => null, - (cxt) => PlatformIcons(cxt).search, + (cxt) => SFSymbols.search, (cxt) => null, (cxt) => null ]; final List _subpageLeadingActionButtonIconBuilders = [ (cxt) => null, - (cxt) => SFSymbols.sort_down, + (cxt) => SFSymbols.sort_down_circle, (cxt) => null, (cxt) => null ]; diff --git a/lib/page/subpage_main.dart b/lib/page/subpage_main.dart index 6edaaf96..4594ab87 100644 --- a/lib/page/subpage_main.dart +++ b/lib/page/subpage_main.dart @@ -15,6 +15,9 @@ * along with this program. If not, see . */ +import 'dart:async'; + +import 'package:dan_xi/common/constant.dart'; import 'package:dan_xi/feature/aao_notice_feature.dart'; import 'package:dan_xi/feature/dining_hall_crowdedness_feature.dart'; import 'package:dan_xi/feature/ecard_balance_feature.dart'; @@ -42,15 +45,31 @@ class HomeSubpage extends PlatformSubpage { HomeSubpage({Key key}); } +class RefreshHomepageEvent {} + class _HomeSubpageState extends State with AutomaticKeepAliveClientMixin { @override bool get wantKeepAlive => true; + static StreamSubscription _refreshSubscription; + @override void initState() { super.initState(); initPlatformState(); + if (_refreshSubscription == null) { + _refreshSubscription = Constant.eventBus + .on() + .listen((_) => refreshSelf()); + } + } + + @override + void dispose() { + super.dispose(); + if (_refreshSubscription != null) _refreshSubscription.cancel(); + _refreshSubscription = null; } //Get current brightness with _brightness diff --git a/lib/page/subpage_settings.dart b/lib/page/subpage_settings.dart index 3f9c6693..4291a855 100644 --- a/lib/page/subpage_settings.dart +++ b/lib/page/subpage_settings.dart @@ -22,6 +22,7 @@ import 'package:dan_xi/generated/l10n.dart'; import 'package:dan_xi/model/person.dart'; import 'package:dan_xi/page/open_source_license.dart'; import 'package:dan_xi/page/platform_subpage.dart'; +import 'package:dan_xi/page/subpage_main.dart'; import 'package:dan_xi/provider/settings_provider.dart'; import 'package:dan_xi/public_extension_methods.dart'; import 'package:dan_xi/util/platform_universal.dart'; @@ -158,7 +159,7 @@ class _SettingsSubpageState extends State { Function onTapListener = (Campus campus) { SettingsProvider.of(_preferences).campus = campus; Navigator.of(context).pop(); - Phoenix.rebirth(context); + RefreshHomepageEvent().fire(); refreshSelf(); }; Constant.CAMPUS_VALUES.forEach((value) {