Separate history entries
This commit is contained in:
parent
99912333ac
commit
b86e0ae2f2
|
@ -1,7 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:jisho_study_tool/bloc/database/database_bloc.dart';
|
||||
import 'package:jisho_study_tool/models/history/search.dart';
|
||||
import 'package:jisho_study_tool/models/history/kanji_result.dart';
|
||||
|
||||
import './kanji_event.dart';
|
||||
import './kanji_state.dart';
|
||||
|
@ -19,17 +19,16 @@ class KanjiBloc extends Bloc<KanjiEvent, KanjiState> {
|
|||
|
||||
KanjiBloc(this._databaseBloc) : super(KanjiSearch(KanjiSearchType.Initial));
|
||||
|
||||
void addSearchToDB(searchString) {
|
||||
void addSearchToDB(kanji) {
|
||||
if (_databaseBloc.state is DatabaseDisconnected)
|
||||
throw DatabaseNotConnectedException;
|
||||
|
||||
(_databaseBloc.state as DatabaseConnected)
|
||||
.database
|
||||
.box<Search>()
|
||||
.put(Search(
|
||||
query: searchString,
|
||||
.box<KanjiResult>()
|
||||
.put(KanjiResult(
|
||||
kanji: kanji,
|
||||
timestamp: DateTime.now(),
|
||||
type: "kanji"
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'dart:async';
|
|||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jisho_study_tool/models/history/search.dart';
|
||||
import 'package:jisho_study_tool/models/history/search_string.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'package:jisho_study_tool/bloc/database/database_bloc.dart';
|
||||
|
@ -25,11 +25,10 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
|
|||
|
||||
(_databaseBloc.state as DatabaseConnected)
|
||||
.database
|
||||
.box<Search>()
|
||||
.put(Search(
|
||||
.box<SearchString>()
|
||||
.put(SearchString(
|
||||
query: searchString,
|
||||
timestamp: DateTime.now(),
|
||||
type: "search"
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,22 @@
|
|||
|
||||
import 'package:objectbox/objectbox.dart';
|
||||
|
||||
@Entity()
|
||||
class Search {
|
||||
class KanjiResult {
|
||||
int id = 0;
|
||||
|
||||
@Property(type: PropertyType.date)
|
||||
DateTime timestamp;
|
||||
|
||||
String query;
|
||||
String kanji;
|
||||
|
||||
String type;
|
||||
|
||||
Search({
|
||||
this.id,
|
||||
KanjiResult({
|
||||
this.timestamp,
|
||||
this.query,
|
||||
this.type,
|
||||
this.kanji,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "${timestamp.toIso8601String()} [${type.toUpperCase()}] - $query";
|
||||
return "[${timestamp.toIso8601String()}] - $kanji";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
import 'package:objectbox/objectbox.dart';
|
||||
|
||||
import 'package:jisho_study_tool/models/history/word_result.dart';
|
||||
|
||||
@Entity()
|
||||
class SearchString {
|
||||
int id = 0;
|
||||
|
||||
@Property(type: PropertyType.date)
|
||||
DateTime timestamp;
|
||||
|
||||
String query;
|
||||
|
||||
@Backlink()
|
||||
final chosenResults = ToMany<WordResult>();
|
||||
|
||||
SearchString({
|
||||
this.timestamp,
|
||||
this.query,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "[${timestamp.toIso8601String()}] \"$query\"";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
import 'package:objectbox/objectbox.dart';
|
||||
|
||||
import 'package:jisho_study_tool/models/history/search_string.dart';
|
||||
|
||||
@Entity()
|
||||
class WordResult {
|
||||
int id = 0;
|
||||
|
||||
@Property(type: PropertyType.date)
|
||||
DateTime timestamp;
|
||||
|
||||
String word;
|
||||
|
||||
final searchString = ToOne<SearchString>();
|
||||
|
||||
WordResult({
|
||||
this.timestamp,
|
||||
this.word,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "[${timestamp.toIso8601String()}] - $word";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
import 'package:objectbox/objectbox.dart';
|
||||
import 'package:unofficial_jisho_api/api.dart' as jisho;
|
||||
|
||||
@Entity()
|
||||
class SearchResult {
|
||||
int id = 0;
|
||||
final meta = ToOne<JishoResultMeta>();
|
||||
final data = ToMany<JishoResult>();
|
||||
|
||||
// SearchResult(JishoAPIResult result) {
|
||||
// this.data = result.data;
|
||||
// this.meta = result.meta;
|
||||
// }
|
||||
|
||||
// JishoAPIResult toJishoAPIResult() {
|
||||
// return JishoAPIResult(meta: this.meta, data: this.data);
|
||||
// }
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class JishoResultMeta {
|
||||
int id = 0;
|
||||
int status;
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class JishoResult {
|
||||
int id = 0;
|
||||
final attribution = ToOne<JishoAttribution>();
|
||||
bool is_common;
|
||||
final japanese = ToMany<JishoJapaneseWord>();
|
||||
List<String> jlpt;
|
||||
final senses = ToMany<JishoWordSense>();
|
||||
String slug;
|
||||
List<String> tags;
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class JishoAttribution {
|
||||
int id = 0;
|
||||
String dbpedia;
|
||||
String jmdict;
|
||||
bool jmnedict;
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class JishoJapaneseWord {
|
||||
int id = 0;
|
||||
String reading;
|
||||
String word;
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class JishoWordSense {
|
||||
int id = 0;
|
||||
List<String> antonyms;
|
||||
List<String> english_definitions;
|
||||
List<String> info;
|
||||
final links = ToMany<JishoSenseLink>();
|
||||
List<String> parts_of_speech;
|
||||
List<String> restrictions;
|
||||
List<String> see_also;
|
||||
List<dynamic> source;
|
||||
List<String> tags;
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class JishoSenseLink {
|
||||
int id = 0;
|
||||
String text;
|
||||
String url;
|
||||
}
|
|
@ -4,44 +4,336 @@
|
|||
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
|
||||
"entities": [
|
||||
{
|
||||
"id": "1:7471000004971513655",
|
||||
"lastPropertyId": "4:1530573958565295186",
|
||||
"name": "Search",
|
||||
"id": "3:7851566044119418641",
|
||||
"lastPropertyId": "4:2352718426928758061",
|
||||
"name": "JishoAttribution",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:182004738902401315",
|
||||
"id": "1:9162407962473480509",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:647032929519296287",
|
||||
"id": "2:708495477684386",
|
||||
"name": "dbpedia",
|
||||
"type": 9
|
||||
},
|
||||
{
|
||||
"id": "3:6579248575703756688",
|
||||
"name": "jmdict",
|
||||
"type": 9
|
||||
},
|
||||
{
|
||||
"id": "4:2352718426928758061",
|
||||
"name": "jmnedict",
|
||||
"type": 1
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
},
|
||||
{
|
||||
"id": "4:5830034738494786681",
|
||||
"lastPropertyId": "3:1420686825377652298",
|
||||
"name": "JishoJapaneseWord",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:5568051277997102473",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:8794655557751948952",
|
||||
"name": "reading",
|
||||
"type": 9
|
||||
},
|
||||
{
|
||||
"id": "3:1420686825377652298",
|
||||
"name": "word",
|
||||
"type": 9
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
},
|
||||
{
|
||||
"id": "5:814015574151442186",
|
||||
"lastPropertyId": "6:5908719510010444548",
|
||||
"name": "JishoResult",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:4779715838063307925",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:398633124413531447",
|
||||
"name": "attributionId",
|
||||
"type": 11,
|
||||
"flags": 520,
|
||||
"indexId": "1:3741479335507224998",
|
||||
"relationTarget": "JishoAttribution"
|
||||
},
|
||||
{
|
||||
"id": "3:3743357097628620453",
|
||||
"name": "is_common",
|
||||
"type": 1
|
||||
},
|
||||
{
|
||||
"id": "4:2403901886209575067",
|
||||
"name": "jlpt",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "5:9147057123672087105",
|
||||
"name": "slug",
|
||||
"type": 9
|
||||
},
|
||||
{
|
||||
"id": "6:5908719510010444548",
|
||||
"name": "tags",
|
||||
"type": 30
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"id": "1:1762405519516054052",
|
||||
"name": "japanese",
|
||||
"targetId": "4:5830034738494786681"
|
||||
},
|
||||
{
|
||||
"id": "2:5662556255405307520",
|
||||
"name": "senses",
|
||||
"targetId": "8:7499450265299287403"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "6:6175990861942758315",
|
||||
"lastPropertyId": "2:6228403848602783530",
|
||||
"name": "JishoResultMeta",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:2609861734144336951",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:6228403848602783530",
|
||||
"name": "status",
|
||||
"type": 6
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
},
|
||||
{
|
||||
"id": "7:8388739279951258717",
|
||||
"lastPropertyId": "3:6475272726803052671",
|
||||
"name": "JishoSenseLink",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:9038298290884158108",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:3536322409202325005",
|
||||
"name": "text",
|
||||
"type": 9
|
||||
},
|
||||
{
|
||||
"id": "3:6475272726803052671",
|
||||
"name": "url",
|
||||
"type": 9
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
},
|
||||
{
|
||||
"id": "8:7499450265299287403",
|
||||
"lastPropertyId": "8:8987388154341761734",
|
||||
"name": "JishoWordSense",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:3215440847258041904",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:2015550844387658352",
|
||||
"name": "antonyms",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "3:5828592811743363528",
|
||||
"name": "english_definitions",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "4:5593994833762859570",
|
||||
"name": "info",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "5:2972516533060921751",
|
||||
"name": "parts_of_speech",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "6:116167531949398184",
|
||||
"name": "restrictions",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "7:5268205144755091970",
|
||||
"name": "see_also",
|
||||
"type": 30
|
||||
},
|
||||
{
|
||||
"id": "8:8987388154341761734",
|
||||
"name": "tags",
|
||||
"type": 30
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"id": "4:554428283260148269",
|
||||
"name": "links",
|
||||
"targetId": "7:8388739279951258717"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "9:6483665137820532859",
|
||||
"lastPropertyId": "2:8047458152016460696",
|
||||
"name": "SearchResult",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:1744658189464710184",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:8047458152016460696",
|
||||
"name": "metaId",
|
||||
"type": 11,
|
||||
"flags": 520,
|
||||
"indexId": "2:2854883655423126351",
|
||||
"relationTarget": "JishoResultMeta"
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"id": "3:9171394818028481706",
|
||||
"name": "data",
|
||||
"targetId": "5:814015574151442186"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "10:2511293769307589652",
|
||||
"lastPropertyId": "3:7310514284446208088",
|
||||
"name": "KanjiResult",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:4875831913401260727",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:2639524138758004976",
|
||||
"name": "timestamp",
|
||||
"type": 10
|
||||
},
|
||||
{
|
||||
"id": "3:8448353731705407210",
|
||||
"id": "3:7310514284446208088",
|
||||
"name": "kanji",
|
||||
"type": 9
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
},
|
||||
{
|
||||
"id": "11:8718716930258187923",
|
||||
"lastPropertyId": "3:6047999002753663080",
|
||||
"name": "SearchString",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:8056495551508046109",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:5805071287032353000",
|
||||
"name": "timestamp",
|
||||
"type": 10
|
||||
},
|
||||
{
|
||||
"id": "3:6047999002753663080",
|
||||
"name": "query",
|
||||
"type": 9
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
},
|
||||
{
|
||||
"id": "12:8709403319711854658",
|
||||
"lastPropertyId": "4:4071472200738865726",
|
||||
"name": "WordResult",
|
||||
"properties": [
|
||||
{
|
||||
"id": "1:2725285997242709614",
|
||||
"name": "id",
|
||||
"type": 6,
|
||||
"flags": 1
|
||||
},
|
||||
{
|
||||
"id": "2:6271798504226631398",
|
||||
"name": "timestamp",
|
||||
"type": 10
|
||||
},
|
||||
{
|
||||
"id": "3:5467536225310784192",
|
||||
"name": "word",
|
||||
"type": 9
|
||||
},
|
||||
{
|
||||
"id": "4:1530573958565295186",
|
||||
"name": "type",
|
||||
"type": 9
|
||||
"id": "4:4071472200738865726",
|
||||
"name": "searchStringId",
|
||||
"type": 11,
|
||||
"flags": 520,
|
||||
"indexId": "3:5534321127094586184",
|
||||
"relationTarget": "SearchString"
|
||||
}
|
||||
],
|
||||
"relations": []
|
||||
}
|
||||
],
|
||||
"lastEntityId": "1:7471000004971513655",
|
||||
"lastIndexId": "0:0",
|
||||
"lastRelationId": "0:0",
|
||||
"lastEntityId": "12:8709403319711854658",
|
||||
"lastIndexId": "3:5534321127094586184",
|
||||
"lastRelationId": "4:554428283260148269",
|
||||
"lastSequenceId": "0:0",
|
||||
"modelVersion": 5,
|
||||
"modelVersionParserMinimum": 5,
|
||||
"retiredEntityUids": [],
|
||||
"retiredEntityUids": [
|
||||
2061102273968386021,
|
||||
7471000004971513655
|
||||
],
|
||||
"retiredIndexUids": [],
|
||||
"retiredPropertyUids": [],
|
||||
"retiredPropertyUids": [
|
||||
1377817599424560887,
|
||||
182004738902401315,
|
||||
647032929519296287,
|
||||
8448353731705407210,
|
||||
1530573958565295186
|
||||
],
|
||||
"retiredRelationUids": [],
|
||||
"version": 1
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import 'package:jisho_study_tool/models/history/kanji_result.dart';
|
||||
|
||||
class _KanjiSearchItemHeader extends StatelessWidget {
|
||||
final KanjiResult result;
|
||||
|
||||
const _KanjiSearchItemHeader(this.result, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text("[KANJI] ${result.kanji} - ${result.timestamp.toIso8601String()}");
|
||||
}
|
||||
}
|
||||
|
||||
class KanjiSearchItem extends StatelessWidget {
|
||||
final KanjiResult result;
|
||||
|
||||
const KanjiSearchItem(this.result,{Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Slidable(
|
||||
child: ListTile(title: _KanjiSearchItemHeader(result)),
|
||||
actionPane: SlidableScrollActionPane(),
|
||||
secondaryActions: [
|
||||
IconSlideAction(
|
||||
caption: "Favourite",
|
||||
color: Colors.yellow,
|
||||
icon: Icons.star
|
||||
),
|
||||
IconSlideAction(
|
||||
caption: "Delete",
|
||||
color: Colors.red,
|
||||
icon: Icons.delete
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import 'package:jisho_study_tool/models/history/search_string.dart';
|
||||
|
||||
class SearchItemHeader extends StatelessWidget {
|
||||
final SearchString _search;
|
||||
|
||||
const SearchItemHeader(this._search, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
child: Text("[SEARCH] ${_search.query} - ${_search.timestamp.toString()}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SearchItem extends StatelessWidget {
|
||||
final SearchString _search;
|
||||
|
||||
const SearchItem(this._search, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Slidable(
|
||||
actionPane: SlidableScrollActionPane(),
|
||||
secondaryActions: [
|
||||
IconSlideAction(
|
||||
caption: "Delete",
|
||||
color: Colors.red,
|
||||
icon: Icons.delete
|
||||
)
|
||||
],
|
||||
child: ExpansionTile(
|
||||
title: SearchItemHeader(_search),
|
||||
expandedAlignment: Alignment.topCenter,
|
||||
children: [ListTile(title: Text(_search.timestamp.toIso8601String()),)],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ class SearchBar extends StatelessWidget {
|
|||
children: [
|
||||
TextField(
|
||||
onSubmitted: (text) {
|
||||
|
||||
BlocProvider.of<SearchBloc>(context)
|
||||
.add(GetSearchResults(text));
|
||||
},
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:jisho_study_tool/bloc/database/database_bloc.dart';
|
||||
import 'package:jisho_study_tool/models/history/search.dart';
|
||||
import 'package:jisho_study_tool/models/history/kanji_result.dart';
|
||||
import 'package:jisho_study_tool/models/history/search_string.dart';
|
||||
import 'package:jisho_study_tool/view/components/history/kanji_search_item.dart';
|
||||
import 'package:jisho_study_tool/view/components/history/search_item.dart';
|
||||
|
||||
class HistoryView extends StatelessWidget {
|
||||
@override
|
||||
|
@ -13,13 +16,20 @@ class HistoryView extends StatelessWidget {
|
|||
builder: (context, state) {
|
||||
if (state is DatabaseDisconnected)
|
||||
throw DatabaseNotConnectedException();
|
||||
return Text(
|
||||
(state as DatabaseConnected)
|
||||
return ListView(
|
||||
children: (state as DatabaseConnected)
|
||||
.database
|
||||
.box<Search>()
|
||||
.box<SearchString>()
|
||||
.getAll()
|
||||
.map((e) => e.toString())
|
||||
.toString()
|
||||
.map((e) => SearchItem(e) as Widget)
|
||||
.toList()
|
||||
|
||||
+ (state as DatabaseConnected)
|
||||
.database
|
||||
.box<KanjiResult>()
|
||||
.getAll()
|
||||
.map((e) => KanjiSearchItem(e) as Widget)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue