Skip to content

Commit

Permalink
feat: add option to skip tagged words in word book
Browse files Browse the repository at this point in the history
  • Loading branch information
mumu-lhl committed Feb 6, 2025
1 parent 6e0f7b8 commit cd0fd41
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 25 deletions.
31 changes: 23 additions & 8 deletions lib/database/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,30 @@ class WordbookDao extends DatabaseAccessor<AppDatabase>
return (select(wordbook)).get();
}

// ignore: avoid_init_to_null
Future<List<WordbookData>> getAllWordsWithTag({int? tag = null}) {
Future<List<WordbookData>> getAllWordsWithTag(
// ignore: avoid_init_to_null
{int? tag = null, bool skipTagged = false}) {
if (tag == null) {
return (select(wordbook)
..where((t) => t.tag.isNull())
..orderBy([
(t) => OrderingTerm(expression: t.rowId, mode: OrderingMode.desc)
]))
.get();
if (skipTagged) {
final subquery = selectOnly(wordbook)
..addColumns([wordbook.word])
..where(wordbook.tag.isNotNull());
return (select(wordbook)
..where((t) => t.tag.isNull() & t.word.isNotInQuery(subquery))
..orderBy([
(t) =>
OrderingTerm(expression: t.rowId, mode: OrderingMode.desc)
]))
.get();
} else {
return (select(wordbook)
..where((t) => t.tag.isNull())
..orderBy([
(t) =>
OrderingTerm(expression: t.rowId, mode: OrderingMode.desc)
]))
.get();
}
} else {
return (select(wordbook)
..where((t) => t.tag.isValue(tag))
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "Wort bearbeiten",
"notification": "Benachrichtigung",
"moreOptionsButton": "Mehr Optionen Schaltfläche",
"titleAlias": "Titel Alias"
"titleAlias": "Titel Alias",
"skipTaggedWord": "Markiertes Wort überspringen"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,7 @@
"moreOptionsButton": "More Options Button",
"@moreOptionsButton": {},
"titleAlias": "Title Alias",
"@titleAlias": {}
"@titleAlias": {},
"skipTaggedWord": "Skip Tagged Word",
"@skipTaggedWord": {}
}
3 changes: 2 additions & 1 deletion lib/l10n/app_fa.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "ویرایش کلمه",
"notification": "اعلان",
"moreOptionsButton": "دکمه گزینه‌های بیشتر",
"titleAlias": "عنوان مستعار"
"titleAlias": "عنوان مستعار",
"skipTaggedWord": "رد شدن از کلمه تگ شده"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_nb.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "Rediger ord",
"notification": "Varsling",
"moreOptionsButton": "Flere alternativer-knapp",
"titleAlias": "Tittel Alias"
"titleAlias": "Tittel Alias",
"skipTaggedWord": "Hopp over merket ord"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "Редактировать слово",
"notification": "Уведомление",
"moreOptionsButton": "Кнопка дополнительных параметров",
"titleAlias": "Псевдоним заголовка"
"titleAlias": "Псевдоним заголовка",
"skipTaggedWord": "Пропускать помеченное слово"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_sc.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "Modìfica sa paràula",
"notification": "Notìfica",
"moreOptionsButton": "Butone de àteras optziones",
"titleAlias": "Alias de tìtulu"
"titleAlias": "Alias de tìtulu",
"skipTaggedWord": "Iscarta sa প্যারau প্যারau ডে প্যারau"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_ta.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "சொல் திருத்து",
"notification": "அறிவிப்பு",
"moreOptionsButton": "மேலும் விருப்பங்கள் பொத்தான்",
"titleAlias": "தலைப்பு மாற்றுப்பெயர்"
"titleAlias": "தலைப்பு மாற்றுப்பெயர்",
"skipTaggedWord": "குறிச்சொல்லிடப்பட்ட வார்த்தையைத் தவிர்க்கவும்"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "编辑单词",
"notification": "通知",
"moreOptionsButton": "更多选项按钮",
"titleAlias": "标题别名"
"titleAlias": "标题别名",
"skipTaggedWord": "跳过有标签的单词"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_zh_HK.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "編輯字詞",
"notification": "通知",
"moreOptionsButton": "更多選項按鈕",
"titleAlias": "標題別名"
"titleAlias": "標題別名",
"skipTaggedWord": "跳過有標籤的字詞"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"editWord": "編輯字詞",
"notification": "通知",
"moreOptionsButton": "更多選項按鈕",
"titleAlias": "標題別名"
"titleAlias": "標題別名",
"skipTaggedWord": "跳過有標籤的字詞"
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void main() async {
"exportPath",
"notification",
"showMoreOptionsButton",
"skipTaggedWord",
}));

int? groupId = prefs.getInt("currentDictionaryGroupId");
Expand Down
53 changes: 49 additions & 4 deletions lib/pages/main/wordbook.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import "package:ciyue/database/app.dart";
import "package:ciyue/main.dart";
import "package:ciyue/settings.dart";
import "package:ciyue/widget/text_buttons.dart";
import "package:flutter/material.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:go_router/go_router.dart";

VoidCallback? _refreshTagsAndWords;

class MoreOptionsDialog extends StatefulWidget {
const MoreOptionsDialog({super.key});

@override
State<MoreOptionsDialog> createState() => _MoreOptionsDialogState();
}

class TagListDialog extends StatefulWidget {
final List<WordbookTag> tagsDisplay;

Expand Down Expand Up @@ -84,7 +92,18 @@ class WordBookScreen extends StatelessWidget {
await buildTagsList(context, tags);
}
},
)
),
IconButton(
icon: Icon(Icons.more_vert),
onPressed: () async {
showDialog(
context: context,
builder: (BuildContext context) {
return const MoreOptionsDialog();
},
);
},
),
],
);
}
Expand Down Expand Up @@ -180,6 +199,31 @@ class WordViewWithTagsClips extends StatefulWidget {
State<WordViewWithTagsClips> createState() => _WordViewWithTagsClipsState();
}

class _MoreOptionsDialogState extends State<MoreOptionsDialog> {
@override
Widget build(BuildContext context) {
return SimpleDialog(
title: Text(AppLocalizations.of(context)!.more),
children: [
SimpleDialogOption(
child: CheckboxListTile(
value: settings.skipTaggedWord,
onChanged: (value) async {
if (value != null) {
settings.skipTaggedWord = value;
await prefs.setBool("skipTaggedWord", value);
setState(() {});
_refreshTagsAndWords!();
}
},
title: Text(AppLocalizations.of(context)!.skipTaggedWord),
),
),
],
);
}
}

class _TagListDialogState extends State<TagListDialog> {
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -274,8 +318,9 @@ class _WordViewWithTagsClipsState extends State<WordViewWithTagsClips> {
onSelected: (selected) {
setState(() {
selectedTag = selected ? tag.id : null;
final skipTaggedWord = selectedTag == null && settings.skipTaggedWord;
allWords =
wordbookDao.getAllWordsWithTag(tag: selectedTag);
wordbookDao.getAllWordsWithTag(tag: selectedTag, skipTagged: skipTaggedWord);
});
},
));
Expand All @@ -295,15 +340,15 @@ class _WordViewWithTagsClipsState extends State<WordViewWithTagsClips> {
void initState() {
super.initState();

allWords = wordbookDao.getAllWordsWithTag();
allWords = wordbookDao.getAllWordsWithTag(skipTagged: settings.skipTaggedWord);
tags = wordbookTagsDao.getAllTags();

_refreshTagsAndWords = refresh;
}

void refresh() {
setState(() {
allWords = wordbookDao.getAllWordsWithTag();
allWords = wordbookDao.getAllWordsWithTag(skipTagged: settings.skipTaggedWord);
tags = wordbookTagsDao.getAllTags();
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class _Settings {
late bool showSidebarIcon;
late bool showMoreOptionsButton;
late bool notification;
late bool skipTaggedWord;

_Settings() {
autoExport = prefs.getBool("autoExport") ?? false;
Expand All @@ -28,9 +29,8 @@ class _Settings {
searchBarInAppBar = prefs.getBool("searchBarInAppBar") ?? true;
showSidebarIcon = prefs.getBool("showSidebarIcon") ?? true;
showMoreOptionsButton = prefs.getBool("showMoreOptionsButton") ?? true;

language = prefs.getString("language");
language ??= "system";
skipTaggedWord = prefs.getBool("skipTaggedWord") ?? false;
language = prefs.getString("language") ?? "system";

final themeModeString = prefs.getString("themeMode");
switch (themeModeString) {
Expand Down

0 comments on commit cd0fd41

Please sign in to comment.