Skip to content

Commit

Permalink
Merge branch 'main' of github.com:w568w/DanXi into main
Browse files Browse the repository at this point in the history
  • Loading branch information
w568w committed May 1, 2021
2 parents 7c3c267 + cdb0a66 commit 8fac578
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 天"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"end_reached": "已经到底了",
"latest_reply": "[{username}] 于{date}回复:",
"no_summary": "[无法显示此类型的消息]",
"image_tag": "[图片]",

"classroom": "教室",
"morning": "上午",
Expand Down
94 changes: 75 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,49 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
}

/// List of all of the subpages' action button icon. They will show on the appbar of each tab page.
final List<Function> _subpageActionButtonIconBuilders = [
final List<Function> _subpageRightmostActionButtonIconBuilders = [
(cxt) => null,
(cxt) =>
PlatformX.isAndroid ? PlatformIcons(cxt).add : SFSymbols.plus_circle,
(cxt) => PlatformX.isAndroid ? Icons.share : SFSymbols.square_arrow_up,
(cxt) => null
];

final List<Function> _subpageRightsecondActionButtonIconBuilders = [
(cxt) => null,
(cxt) => SFSymbols.search,
(cxt) => null,
(cxt) => null
];

final List<Function> _subpageLeadingActionButtonIconBuilders = [
(cxt) => null,
(cxt) => SFSymbols.sort_down_circle,
(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<Function> _subpageActionButtonTextBuilders = [
final List<Function> _subpageRightmostActionButtonTextBuilders = [
(cxt) => null,
(cxt) => S.of(cxt).new_post,
(cxt) => S.of(cxt).share,
(cxt) => null,
];

final List<Function> _subpageRightsecondActionButtonTextBuilders = [
(cxt) => null,
(cxt) => S.of(cxt).new_post, //TODO: search
(cxt) => null,
(cxt) => null,
];

final List<Function> _subpageLeadingActionButtonTextBuilders = [
(cxt) => null,
(cxt) => S.of(cxt).new_post, //TODO: sort by
(cxt) => null,
(cxt) => null,
];

@override
void dispose() {
Expand Down Expand Up @@ -367,17 +395,32 @@ class _HomePageState extends State<HomePage> 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;
}
}
Expand All @@ -394,9 +437,9 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
trailingActions: [
PlatformIconButton(
padding: EdgeInsets.zero,
icon: Icon(_subpageActionButtonIconBuilders[_pageIndex.value](
icon: Icon(_subpageRightmostActionButtonIconBuilders[_pageIndex.value](
context)),
onPressed: _onPressActionButton,
onPressed: _onPressRightmostActionButton,
)
],
),
Expand All @@ -407,13 +450,6 @@ class _HomePageState extends State<HomePage> 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)),
Expand All @@ -434,17 +470,37 @@ class _HomePageState extends State<HomePage> 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(
Expand Down
25 changes: 24 additions & 1 deletion lib/page/subpage_bbs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ class BBSSubpage extends PlatformSubpage {
}

class AddNewPostEvent {}

class RetrieveNewPostEvent {}
class SearchEvent {}
class SortOrderChangedEvent {}

class _BBSSubpageState extends State<BBSSubpage>
with AutomaticKeepAliveClientMixin {
static StreamSubscription _postSubscription;
static StreamSubscription _refreshSubscription;
static StreamSubscription _searchSubscription;
static StreamSubscription _sortOrderChangedSubscription;
static StreamSubscription _goTopSubscription;
ScrollController _controller = ScrollController();
HtmlEditorController controller = HtmlEditorController();
Expand Down Expand Up @@ -115,6 +118,20 @@ class _BBSSubpageState extends State<BBSSubpage>
TopController.scrollToTop(_controller);
});
}
if (_searchSubscription == null) {
_searchSubscription =
Constant.eventBus.on<SearchEvent>().listen((event) {
//TODO: show search view
});
}
if (_sortOrderChangedSubscription == null) {
_sortOrderChangedSubscription =
Constant.eventBus.on<SortOrderChangedEvent>().listen((event) {
//TODO: change sort order
});
}


if (_controller != null) {
// Over-scroll event
_controller.addListener(_scrollListener);
Expand All @@ -137,8 +154,12 @@ class _BBSSubpageState extends State<BBSSubpage>
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);
}

Expand Down Expand Up @@ -258,6 +279,8 @@ class _BBSSubpageState extends State<BBSSubpage>
/// 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();
}

Expand Down
19 changes: 19 additions & 0 deletions lib/page/subpage_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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';
Expand Down Expand Up @@ -42,15 +45,31 @@ class HomeSubpage extends PlatformSubpage {
HomeSubpage({Key key});
}

class RefreshHomepageEvent {}

class _HomeSubpageState extends State<HomeSubpage>
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;

static StreamSubscription _refreshSubscription;

@override
void initState() {
super.initState();
initPlatformState();
if (_refreshSubscription == null) {
_refreshSubscription = Constant.eventBus
.on<RefreshHomepageEvent>()
.listen((_) => refreshSelf());
}
}

@override
void dispose() {
super.dispose();
if (_refreshSubscription != null) _refreshSubscription.cancel();
_refreshSubscription = null;
}

//Get current brightness with _brightness
Expand Down
3 changes: 2 additions & 1 deletion lib/page/subpage_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -158,7 +159,7 @@ class _SettingsSubpageState extends State<SettingsSubpage> {
Function onTapListener = (Campus campus) {
SettingsProvider.of(_preferences).campus = campus;
Navigator.of(context).pop();
Phoenix.rebirth(context);
RefreshHomepageEvent().fire();
refreshSelf();
};
Constant.CAMPUS_VALUES.forEach((value) {
Expand Down

0 comments on commit 8fac578

Please sign in to comment.