history: show search counts in a side bubble

This commit is contained in:
2025-07-07 22:30:16 +02:00
parent 83f15718c1
commit 4dcfb15db8
4 changed files with 35 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ A large update with some significant additions and fixes.
- Added a toggle in settings for enabling/disabling history tracking
- Display the number of history searches on the history page
- Embed the changelog in the app
- Added search count bubbles to the history entries
## Bugfixes 🐞
@@ -17,7 +18,6 @@ A large update with some significant additions and fixes.
- Remove word search duplicates
- Fix version number in the info page.
- Fix a broken query for adding items to library lists.
- Fix a broken query for library lists.
## Other 📝

View File

@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:mugiten/bloc/theme/theme_bloc.dart';
import 'package:mugiten/components/search/search_results_body/parts/circle_badge.dart';
import '../../models/history/history_entry.dart';
import '../../routing/routes.dart';
@@ -92,14 +95,24 @@ class HistoryEntryTile extends StatelessWidget {
child: Text(formatTime(entry.lastTimestamp)),
),
DefaultTextStyle.merge(
style: japaneseFont.textStyle,
child: entry.isKanji
? KanjiBox.headline4(
context: context,
kanji: entry.kanji!,
)
: Expanded(child: Text(entry.word!)),
),
style: japaneseFont.textStyle,
child: entry.isKanji
? KanjiBox.headline4(
context: context,
kanji: entry.kanji!,
)
: Expanded(child: Text(entry.word!))),
if (entry.isKanji) Expanded(child: SizedBox.shrink()),
if ((entry.timestampCount ?? 0) > 1)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: BlocBuilder<ThemeBloc, ThemeState>(
builder: (context, themeState) => CircleBadge(
color: themeState.theme.menuGreyNormal.background,
child: Text('${entry.timestampCount}'),
),
),
),
],
),
),

View File

@@ -10,6 +10,7 @@ class HistoryEntry {
final String? kanji;
final String? word;
final DateTime lastTimestamp;
final int? timestampCount;
/// Whether this item is a kanji search or a word search
bool get isKanji => word == null;
@@ -18,12 +19,14 @@ class HistoryEntry {
required this.id,
required this.kanji,
required this.lastTimestamp,
this.timestampCount,
}) : word = null;
HistoryEntry.withWord({
required this.id,
required this.word,
required this.lastTimestamp,
this.timestampCount,
}) : kanji = null;
/// Reconstruct a HistoryEntry object with data from the database
@@ -43,6 +46,9 @@ class HistoryEntry {
lastTimestamp: DateTime.fromMillisecondsSinceEpoch(
dbObject['timestamp']! as int,
),
timestampCount: dbObject.containsKey('timestampCount')
? dbObject['timestampCount']! as int
: null,
)
: HistoryEntry.withKanji(
id: dbObject['entryId']! as int,
@@ -50,6 +56,9 @@ class HistoryEntry {
lastTimestamp: DateTime.fromMillisecondsSinceEpoch(
dbObject['timestamp']! as int,
),
timestampCount: dbObject.containsKey('timestampCount')
? dbObject['timestampCount']! as int
: null,
);
// TODO: There is a lot in common with

View File

@@ -26,7 +26,10 @@ CREATE TABLE "Mugiten_HistoryEntryTimestamp" (
CREATE INDEX "Mugiten_HistoryEntryTimestamp_byTimestamp" ON "Mugiten_HistoryEntryTimestamp"("timestamp");
CREATE VIEW "Mugiten_HistoryEntry_orderedByTimestamp" AS
SELECT * FROM "Mugiten_HistoryEntryTimestamp"
SELECT
*,
COUNT("timestamp") AS "timestampCount"
FROM "Mugiten_HistoryEntryTimestamp"
LEFT JOIN "Mugiten_HistoryEntryWord" USING ("entryId")
LEFT JOIN "Mugiten_HistoryEntryKanji" USING ("entryId")
GROUP BY "entryId"