Skip to content

Commit

Permalink
feat(*): Add settings to control shortcut entries in forum card
Browse files Browse the repository at this point in the history
Add settings to control shortcut entries in forum card:
* Disabled by default.
  • Loading branch information
realth000 committed Dec 12, 2023
1 parent cd65c37 commit f054e4e
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 51 deletions.
4 changes: 4 additions & 0 deletions lib/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"title": "Languages",
"followSystem": "Follow System",
"selectLanguage": "Select Language"
},
"showShortcutInForumCard": {
"title": "Forum Card Shortcut Entries",
"detail": "Show shortcut entries towards latest thread and subreddits in forum card"
}
},
"checkInSection": {
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/strings_zh-CN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"title": "语言",
"followSystem": "跟随系统",
"selectLanguage": "选择语言"
},
"showShortcutInForumCard": {
"title": "论坛卡片可跳转",
"detail": "论坛卡片上显示可跳转到最新帖子和子板块的部件"
}
},
"checkInSection": {
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/strings_zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"title": "語言",
"followSystem": "跟隨系統",
"selectLanguage": "選擇語言"
},
"showShortcutInForumCard": {
"title": "論壇卡可跳轉",
"detail": "論壇卡上顯示可跳到最新貼文和子板塊的零件"
}
},
"checkInSection": {
Expand Down
3 changes: 3 additions & 0 deletions lib/models/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Settings with _$Settings {
required String locale,
required String checkInFeeling,
required String checkInMessage,
required bool showShortcutInForumCard,
}) = _Settings;
}

Expand All @@ -40,6 +41,7 @@ const settingsThemeMode = 'ThemeMode';
const settingsLocale = 'locale';
const settingsCheckInFeeling = 'checkInFeeling';
const settingsCheckInMessage = 'checkInMessage';
const settingsShowShortcutInForumCard = 'showShortcutInForumCard';

/// All settings names (as keys) and settings value types (as values).
const settingsMap = <String, Type>{
Expand All @@ -58,4 +60,5 @@ const settingsMap = <String, Type>{
settingsLocale: String,
settingsCheckInFeeling: String,
settingsCheckInMessage: String,
settingsShowShortcutInForumCard: bool,
};
12 changes: 12 additions & 0 deletions lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class AppSettings extends _$AppSettings {
storage.getString(settingsCheckInFeeling) ?? _defaultCheckInFeeling,
checkInMessage:
storage.getString(settingsCheckInMessage) ?? _defaultCheckInMessage,
showShortcutInForumCard:
storage.getBool(settingsShowShortcutInForumCard) ??
_defaultShowRedirectInForumCard,
);
}

Expand Down Expand Up @@ -107,6 +110,9 @@ class AppSettings extends _$AppSettings {
/// Default check in message when check in
static const _defaultCheckInMessage = '每日签到';

/// Show shortcut widget that to redirect to latest thread or subreddit in forum card.
static const _defaultShowRedirectInForumCard = false;

Storage _getStorage() {
return ref.read(appStorageProvider);
}
Expand Down Expand Up @@ -209,4 +215,10 @@ class AppSettings extends _$AppSettings {
await storage.saveString(settingsCheckInMessage, message.truncate(50));
state = state.copyWith(checkInMessage: message.truncate(50));
}

Future<void> setShowShortcutInForumCard({required bool visible}) async {
final storage = _getStorage();
await storage.saveBool(settingsShowShortcutInForumCard, value: visible);
state = state.copyWith(showShortcutInForumCard: visible);
}
}
14 changes: 14 additions & 0 deletions lib/screens/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
await selectLanguageDialog(context, localeName);
},
),
SwitchListTile(
secondary: const Icon(Icons.shortcut_outlined),
title: Text(context
.t.settingsPage.appearanceSection.showShortcutInForumCard.title),
subtitle: Text(context
.t.settingsPage.appearanceSection.showShortcutInForumCard.detail),
contentPadding: edgeInsetsL18R18,
value: ref.read(appSettingsProvider).showShortcutInForumCard,
onChanged: (v) async {
await ref
.read(appSettingsProvider.notifier)
.setShowShortcutInForumCard(visible: v);
},
),
];
}

Expand Down
109 changes: 58 additions & 51 deletions lib/widgets/forum_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:tsdm_client/extensions/date_time.dart';
import 'package:tsdm_client/extensions/string.dart';
import 'package:tsdm_client/generated/i18n/strings.g.dart';
import 'package:tsdm_client/models/forum.dart';
import 'package:tsdm_client/providers/settings_provider.dart';
import 'package:tsdm_client/routes/screen_paths.dart';
import 'package:tsdm_client/themes/widget_themes.dart';
import 'package:tsdm_client/utils/debug.dart';
Expand Down Expand Up @@ -83,6 +84,7 @@ class _ForumCardState extends ConsumerState<ForumCard> {

@override
Widget build(BuildContext context) {
final showShortCut = ref.watch(appSettingsProvider).showShortcutInForumCard;
final forumInfoList = [
(
Icons.forum_outlined,
Expand Down Expand Up @@ -151,58 +153,63 @@ class _ForumCardState extends ConsumerState<ForumCard> {
? Text(widget.forum.latestThreadTime!.elapsedTillNow())
: null,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.forum.isExpanded)
ListTile(
title: Row(
children: [
Text(
widget.forum.latestThreadTitle ?? '',
style: Theme.of(context).textTheme.labelMedium,
),
Expanded(child: Container()),
Text(
widget.forum.latestThreadUserName ?? '',
style: Theme.of(context).textTheme.labelSmall,
),
],
if (showShortCut)
Column(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.forum.isExpanded)
ListTile(
title: Row(
children: [
Text(
widget.forum.latestThreadTitle ?? '',
style: Theme.of(context).textTheme.labelMedium,
),
Expanded(child: Container()),
Text(
widget.forum.latestThreadUserName ?? '',
style: Theme.of(context).textTheme.labelSmall,
),
],
),
onTap: () async {
final target =
widget.forum.latestThreadUrl?.parseUrlToRoute();
if (target == null) {
debug(
'invalid latest thread url: ${widget.forum.latestThreadUrl}');
return;
}
await context.pushNamed(
target.$1,
pathParameters: target.$2,
);
},
),
onTap: () async {
final target =
widget.forum.latestThreadUrl?.parseUrlToRoute();
if (target == null) {
debug(
'invalid latest thread url: ${widget.forum.latestThreadUrl}');
return;
}
await context.pushNamed(
target.$1,
pathParameters: target.$2,
);
},
),
if (widget.forum.subThreadList?.isNotEmpty ?? false)
..._buildWrapSection(context, ref, context.t.forumCard.links,
widget.forum.subThreadList!, showingSubThread, () {
setState(() {
showingSubThread = !showingSubThread;
});
}),
if (widget.forum.subForumList?.isNotEmpty ?? false)
..._buildWrapSection(
context,
ref,
context.t.forumCard.subForums,
widget.forum.subForumList!,
showingSubForum, () {
setState(() {
showingSubForum = !showingSubForum;
});
}),
],
),
if (widget.forum.subThreadList?.isNotEmpty ?? false)
..._buildWrapSection(
context,
ref,
context.t.forumCard.links,
widget.forum.subThreadList!,
showingSubThread, () {
setState(() {
showingSubThread = !showingSubThread;
});
}),
if (widget.forum.subForumList?.isNotEmpty ?? false)
..._buildWrapSection(
context,
ref,
context.t.forumCard.subForums,
widget.forum.subForumList!,
showingSubForum, () {
setState(() {
showingSubForum = !showingSubForum;
});
}),
],
),
Padding(
padding: edgeInsetsL15R15B10,
child: Column(
Expand Down

0 comments on commit f054e4e

Please sign in to comment.