diff --git a/docs/changelog/v0.3.0.md b/docs/changelog/v0.3.0.md index bf29c30..621aaed 100644 --- a/docs/changelog/v0.3.0.md +++ b/docs/changelog/v0.3.0.md @@ -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 📝 diff --git a/lib/components/history/history_entry_tile.dart b/lib/components/history/history_entry_tile.dart index e8f9450..5713697 100644 --- a/lib/components/history/history_entry_tile.dart +++ b/lib/components/history/history_entry_tile.dart @@ -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( + builder: (context, themeState) => CircleBadge( + color: themeState.theme.menuGreyNormal.background, + child: Text('${entry.timestampCount}'), + ), + ), + ), ], ), ), diff --git a/lib/models/history/history_entry.dart b/lib/models/history/history_entry.dart index bfce3df..a5b012e 100644 --- a/lib/models/history/history_entry.dart +++ b/lib/models/history/history_entry.dart @@ -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 diff --git a/migrations/0001_history.sql b/migrations/0001_history.sql index 5d32c46..cd645e0 100644 --- a/migrations/0001_history.sql +++ b/migrations/0001_history.sql @@ -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"