Skip to content

Commit

Permalink
feat(*): update lock card style
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Sep 27, 2024
1 parent cd4d728 commit 76251ea
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 54 deletions.
127 changes: 127 additions & 0 deletions lib/features/settings/view/debug_showcase_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tsdm_client/features/theme/cubit/theme_cubit.dart';
import 'package:tsdm_client/utils/html/html_muncher.dart';
import 'package:universal_html/parsing.dart';

/// Showcase page for debugging.
class DebugShowcasePage extends StatefulWidget {
/// Constructor.
const DebugShowcasePage({super.key});

@override
State<DebugShowcasePage> createState() => _DebugShowcasePageState();
}

class _DebugShowcasePageState extends State<DebugShowcasePage>
with SingleTickerProviderStateMixin {
late TabController tabController;

@override
void initState() {
super.initState();
tabController = TabController(length: 1, vsync: this);
}

@override
void dispose() {
tabController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SHOWCASE'),
bottom: TabBar(
tabAlignment: TabAlignment.start,
isScrollable: true,
controller: tabController,
tabs: const [
Tab(text: 'HTML'),
],
),
actions: [
IconButton(
icon: const Icon(Icons.dark_mode_outlined),
selectedIcon: const Icon(Icons.dark_mode),
isSelected: Theme.of(context).brightness == Brightness.dark,
onPressed: () {
switch (Theme.of(context).brightness) {
case Brightness.dark:
context.read<ThemeCubit>().setThemeModeIndex(1);
case Brightness.light:
context.read<ThemeCubit>().setThemeModeIndex(2);
}
},
),
],
),
body: TabBarView(
controller: tabController,
children: const [
_HtmlFragment(),
],
),
);
}
}

class _HtmlFragment extends StatelessWidget {
const _HtmlFragment();

static const htmlData = '''
<body>
<h1>TITLE 1</h1>
<h2>TITLE 2</h2>
<h3>TITLE 3</h3>
<!-- Expand/Collapse -->
<div class="spoiler">
<div class="spoiler_control">
<input class="spoiler_btn" type="button" value="Detail Card"/>
</div>
<div class="spoiler_content">
<div class="showhide">
detail 1
<br/>
detail 2
</div>
</div>
</div>
<!-- Locked with purchase -->
<div class="locked">
<a class="y viewpay" title="title: purchase to see this content"
onclick="showWindow('pay', 'forum.php?mod=misc&action=pay&tid=0&pid=0')">
SOMETHING HERE
</a>
<em class="right">已有 12347890 人购买</em>
<strong>4 coins</strong>
</div>
<!-- Locked with author -->
<div class="locked">此帖仅作者可见</div>
<!-- Locked with points -->
<div class="locked">
USERNAME本帖隐藏的内容需要积分高于 1234567 才可浏览,您当前积分为 1234
</div>
<!-- Locked with reply -->
<div class="locked">
USERNAME,如果您要查看本帖隐藏内容请<a href="forum.php?mod=post&amp;action=reply&amp;fid=0&amp;tid=0" onclick="showWindow('reply', this.href)">回复</a>
</div>
</body>
''';

@override
Widget build(BuildContext context) {
return munchElement(
context,
parseHtmlDocument(htmlData).body!,
parseLockedWithPurchase: true,
);
}
}
13 changes: 13 additions & 0 deletions lib/features/settings/view/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:system_theme/system_theme.dart';
import 'package:tsdm_client/constants/constants.dart';
import 'package:tsdm_client/features/settings/bloc/settings_bloc.dart';
import 'package:tsdm_client/features/settings/repositories/settings_repository.dart';
import 'package:tsdm_client/features/settings/view/debug_showcase_page.dart';
import 'package:tsdm_client/features/settings/widgets/check_in_dialog.dart';
import 'package:tsdm_client/features/settings/widgets/clear_cache_bottom_sheet.dart';
import 'package:tsdm_client/features/settings/widgets/color_picker_dialog.dart';
Expand Down Expand Up @@ -440,6 +441,18 @@ class _SettingsPageState extends State<SettingsPage> {
final tr = context.t.settingsPage.advancedSection;
return [
SectionTitleText(tr.title),
SectionListTile(
leading: const Icon(Icons.developer_mode_outlined),
title: const Text('DEBUG SHOWCASE'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => const DebugShowcasePage(),
),
);
},
),
SectionSwitchListTile(
secondary: Icon(MdiIcons.networkOutline),
title: Text(tr.useProxy),
Expand Down
11 changes: 7 additions & 4 deletions lib/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@
"lockedCard": {
"points": {
"title": "Some content requires enough points to be visible",
"detail": "$requiredPoints points are required, but you only have $points points"
"detail(rich)": "$requiredPoints points are required, but you only have $points points"
},
"purchase": {
"title": "Some content requires purchase",
"purchasedInfo": "$num people have purchased this article",
"purchasedInfo(rich)": "$num people have purchased this article",
"failedPurchase": "Can not purchase",
"failedParsingPurchase": "Failed when parsing purchase info",
"failedParsingConfirmInfo": "Failed when parsing purchase confirm info",
Expand All @@ -488,10 +488,13 @@
},
"reply": {
"title": "Some content requires reply",
"detail": "Reply to see contents here"
"detail(rich)": "$reply to see contents here",
"detailReply": "Reply"
},
"author": {
"title": "Only visible to the thread author"
"title": "Only visible to the thread author",
"detail(rich)": "This content only visible to $author",
"detailAuthor": "author"
}
},
"rateCard": {
Expand Down
11 changes: 7 additions & 4 deletions lib/i18n/strings_zh-CN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@
"lockedCard": {
"points": {
"title": "部分内容要求积分足够才可见",
"detail": "需要 $requiredPoints 积分,但是你只有 $points 积分"
"detail(rich)": "需要 $requiredPoints 积分,但是你只有 $points 积分"
},
"purchase": {
"title": "部分内容需要购买才可浏览",
"purchasedInfo": "$num 人已购买此帖子",
"purchasedInfo(rich)": "$num 人已购买此帖子",
"failedPurchase": "购买失败",
"failedParsingPurchase": "解析购买信息时失败",
"failedParsingConfirmInfo": "解析购买确认信息时失败",
Expand All @@ -488,10 +488,13 @@
},
"reply": {
"title": "部分需要回复才可浏览",
"detail": "回复以查看该部分内容"
"detail(rich)": "$reply以查看该部分内容",
"detailReply": "回复"
},
"author": {
"title": "仅对作者可见"
"title": "仅对作者可见",
"detail(rich)": "该部分内容仅对$author可见",
"detailAuthor": "作者"
}
},
"rateCard": {
Expand Down
11 changes: 7 additions & 4 deletions lib/i18n/strings_zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@
"lockedCard": {
"points": {
"title": "部分內容要求積分足夠才可見",
"detail": "需要 $requiredPoints 積分,但你只有 $points 積分"
"detail(rich)": "需要 $requiredPoints 積分,但你只有 $points 積分"
},
"purchase": {
"title": "部分內容需要購買才可瀏覽",
"purchasedInfo": "$num 人已購買此帖子",
"purchasedInfo(rich)": "$num 人已購買此帖子",
"failedPurchase": "購買失敗",
"failedParsingPurchase": "解析購買資訊時失敗",
"failedPurchaseMessage": "購買失敗: $message",
Expand All @@ -488,10 +488,13 @@
},
"reply": {
"title": "部分需要回覆才可瀏覽",
"detail": "回覆以查看該部分內容"
"detail(rich)": "$reply以查看該部分內容",
"detailReply": "回覆"
},
"author": {
"title": "僅對作者可見"
"title": "僅對作者可見",
"detail(rich)": "該部分內容僅對$author可見",
"detailAuthor": "作者"
}
},
"rateCard": {
Expand Down
18 changes: 14 additions & 4 deletions lib/utils/html/html_muncher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ const emptySpan = TextSpan(text: '\n');
/// widget.
///
/// Main entry of this package.
Widget munchElement(BuildContext context, uh.Element rootElement) {
Widget munchElement(
BuildContext context,
uh.Element rootElement, {
bool parseLockedWithPurchase = false,
}) {
final muncher = _Muncher(
context,
parseLockedWithPurchase: parseLockedWithPurchase,
);

final ret = muncher._munch(rootElement);
Expand Down Expand Up @@ -178,11 +183,14 @@ class _MunchState {
/// Munch html nodes into flutter widgets.
final class _Muncher with LoggerMixin {
/// Constructor.
_Muncher(this.context);
_Muncher(this.context, {required this.parseLockedWithPurchase});

/// Context to build widget when munching.
final BuildContext context;

//////// Configs ////////
bool parseLockedWithPurchase;

/// Munch state to use when munching.
final _MunchState state = _MunchState();

Expand Down Expand Up @@ -565,8 +573,10 @@ final class _Muncher with LoggerMixin {
}

List<InlineSpan>? _buildLockedArea(uh.Element element) {
final lockedArea =
Locked.fromLockDivNode(element, allowWithPurchase: false);
final lockedArea = Locked.fromLockDivNode(
element,
allowWithPurchase: parseLockedWithPurchase,
);
if (lockedArea.isNotValid()) {
return null;
}
Expand Down
Loading

0 comments on commit 76251ea

Please sign in to comment.