Skip to content

Commit

Permalink
dict selection, enter buttons, minor fixes
Browse files Browse the repository at this point in the history
definition: added enter button
match: added enter button and pushed selection from list into strat on tap
settings: added dictionary selection
  • Loading branch information
gryffyn committed Jul 30, 2021
1 parent 1b85ba1 commit d53771b
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ app.*.map.json
# other stuff
deploy.sh
deploy_release.sh
/ci/

# Exceptions to above rules.
!**/ios/**/default.mode1v3
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dict2229
[![Actions Status: CI\_test](https://github.com/gryffyn/dict2229/workflows/CI_test/badge.svg)](https://github.com/gryffyn/dict2229/actions?query=workflow%3A"CI_test")

a client for the RFC 2229 DICT protocol.

Expand Down
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ GeneratedPluginRegistrant.java
# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
default_keyring.jks
1 change: 0 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.gryffyn.dict2229"
minSdkVersion 16
targetSdkVersion 30
Expand Down
11 changes: 8 additions & 3 deletions lib/dialogs/listDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ class ListDialog extends StatelessWidget {
},
itemBuilder: (BuildContext context, int index) {
String key = text.keys.elementAt(index);
return ListTile(
title: Text(key),
subtitle: Text(stripParen(text[key])),
return InkWell(
onTap: () {
Navigator.pop(context, key);
},
child: ListTile(
title: Text(key),
subtitle: Text(stripParen(text[key])),
)
);
},
),
Expand Down
46 changes: 0 additions & 46 deletions lib/dialogs/listDialogTap.dart

This file was deleted.

7 changes: 6 additions & 1 deletion lib/dict.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class Dict {
];
dicts[parts[0]] = parts[1];
}
return dicts;
Map<dynamic,dynamic> allDicts = {
"*": "\"all dictionaries\"",
"!": "\"first match from all dicts\"",
};
allDicts.addAll(dicts);
return allDicts;
}

Future<List<Definition>> define(String word, [String database = '*']) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class _NavigationState extends State<Navigation> {

setDefault(Box box) {
if (!box.containsKey('addr')) {
box.put('addr', 'port.neveris.one');
box.put('addr', 'dict.neveris.one');
}
if (!box.containsKey('port')) {
box.put('port', '2628');
Expand Down
86 changes: 55 additions & 31 deletions lib/pages/definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import 'package:dict2229/utils.dart';
import 'package:hive/hive.dart';

class PageDefinition extends StatefulWidget {
PageDefinition({Key? key, this.word = ""}) : super(key: key);
String word;
PageDefinition({Key? key}) : super(key: key);

@override
_PageDefinition createState() => _PageDefinition();
Expand All @@ -34,21 +33,33 @@ class _PageDefinition extends State<PageDefinition> {
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addPostFrameCallback((_) =>
FocusScope.of(context).requestFocus(_focusNode));
WidgetsBinding.instance!.addPostFrameCallback(
(_) => FocusScope.of(context).requestFocus(_focusNode));
}

List<TextSpan> buildText(Definition key) {
if (key.sourceName == "") {
return <TextSpan>[
TextSpan(text: key.title, style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(
text: key.title, style: TextStyle(fontWeight: FontWeight.bold)),
];
}
return <TextSpan>[
TextSpan(text: key.title + "\n", style: TextStyle(fontWeight: FontWeight.bold)),
return <TextSpan>[
TextSpan(
text: key.title + "\n",
style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: key.body + "\n\n"),
TextSpan(text: key.sourceName + "\n", style: TextStyle(fontStyle: FontStyle.italic, fontWeight: FontWeight.bold, fontSize: DefaultTextStyle.of(context).style.fontSize!*0.7)),
TextSpan(text: key.sourceDesc + "\n", style: TextStyle(fontStyle: FontStyle.italic, fontSize: DefaultTextStyle.of(context).style.fontSize!*0.7)),
TextSpan(
text: key.sourceName + "\n",
style: TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
fontSize: DefaultTextStyle.of(context).style.fontSize! * 0.7)),
TextSpan(
text: key.sourceDesc + "\n",
style: TextStyle(
fontStyle: FontStyle.italic,
fontSize: DefaultTextStyle.of(context).style.fontSize! * 0.7)),
];
}

Expand All @@ -58,32 +69,45 @@ class _PageDefinition extends State<PageDefinition> {
body: Column(
children: [
Padding(
padding: EdgeInsets.only(left: 12, top: 16, right: 12),
child: TextField(
autofocus: true,
focusNode: _focusNode,
decoration: InputDecoration(
isDense: true,
hintText: 'word to define',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
onSubmitted: (text) {
if (this.widget.word != "") {
getDef(this.widget.word);
} else {
getDef(text);
}
},
),
),
padding: EdgeInsets.only(left: 12, top: 16, right: 12),
child: Row(
children: [
Expanded(
child: TextField(
autofocus: true,
focusNode: _focusNode,
decoration: InputDecoration(
isDense: true,
hintText: 'word to define',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
onChanged: (text) {
setState(() {
input = text;
});
},
onSubmitted: (text) {
getDef(text);
},
),
),
IconButton(
onPressed: () {
getDef(input);
},
icon: Icon(Icons.send_rounded, color: Colors.pink,),
),
],
)),
// TODO List dictionaries and allow choice
Expanded(
child: Padding(
padding: EdgeInsets.all(12),
child: ListView.separated(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
keyboardDismissBehavior:
ScrollViewKeyboardDismissBehavior.onDrag,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: out.length,
Expand All @@ -106,4 +130,4 @@ class _PageDefinition extends State<PageDefinition> {
),
);
}
}
}
63 changes: 36 additions & 27 deletions lib/pages/match.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import 'package:dict2229/dialogs/listDialog.dart';
import 'package:dict2229/dialogs/matchDialog.dart';
import 'package:dict2229/dict.dart';
import 'package:dict2229/pages/definition.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:dict2229/utils.dart';
import 'package:hive/hive.dart';
Expand All @@ -27,10 +25,6 @@ class _PageMatch extends State<PageMatch> {

void getDef(String text) async {
var box = Hive.box('prefs');
// TODO shared prefs
// final prefs = await SharedPreferences.getInstance();
// final address = prefs.getString('io.gryffyn.dict2229.server_url') ?? "";
// final port = prefs.getInt('io.gryffyn.dict2229.port') ?? 0;
var dict = Dict.newDict(box.get('addr'), int.tryParse(box.get('port'))!);
var definition = await dict.match(parenthesize(text), box.get('strat'), box.get('dict'));
setState(() {
Expand Down Expand Up @@ -67,11 +61,12 @@ class _PageMatch extends State<PageMatch> {
var dict = Dict.newDict(box.get('addr'), int.tryParse(box.get('port'))!);
var strats = await dict.getStrategies();
showDialog(
context: context,
builder: (BuildContext context) => ListDialog(
title: "Strategies",
text: strats,
));
context: context,
builder: (BuildContext context) => ListDialog(
title: "Strategies",
text: strats,
)).then((value) => setStrat(value));
_focusNode.requestFocus();
}

defineMatch(String match, String dict) {
Expand Down Expand Up @@ -107,23 +102,37 @@ class _PageMatch extends State<PageMatch> {
children: [
Padding(
padding: EdgeInsets.only(left: 12, top: 16, right: 12),
child: TextField(
autofocus: true,
focusNode: _focusNode,
decoration: InputDecoration(
isDense: true,
hintText: 'string to match',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
child: Row(
children: [
Expanded(
child: TextField(
autofocus: true,
focusNode: _focusNode,
decoration: InputDecoration(
isDense: true,
hintText: 'string to match',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
onChanged: (text) {
setSearch(text);
},
onSubmitted: (text) {
getDef(text);
},
),
),
),
onChanged: (text) {
setSearch(text);
},
onSubmitted: (text) {
getDef(text);
},
),
IconButton(
onPressed: () {
if (search != "") {
getDef(search);
}
},
icon: Icon(Icons.send_rounded, color: Colors.pink),
),
],
)
),
Padding(
padding: EdgeInsets.only(left: 12, top: 8, right: 12),
Expand Down
Loading

0 comments on commit d53771b

Please sign in to comment.