Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'hotfix-v1.2.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDario committed May 21, 2021
2 parents cb51ec1 + c407129 commit 8c35b35
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 104 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

# Da Kanji - changelog

## v 1.2.1
Fixed:
- deleting strokes sometimes disabled drawing

## v 1.2.0 - アニメ

new Features:
- *extremely* fast startup
- inference in separate thread therefore no UI jank on low end devices
Expand Down
18 changes: 12 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ Future<void> init() async {


void setupGetIt() {
GetIt.I.registerSingleton<Settings>(Settings());
GetIt.I<Settings>().load();
GetIt.I.registerSingleton<DrawingInterpreter>(DrawingInterpreter());
GetIt.I.registerSingleton<Strokes>(Strokes());
GetIt.I.registerSingleton<Lookup>(Lookup());
GetIt.I.registerSingleton<KanjiBuffer>(KanjiBuffer());
// services to load from disk
GetIt.I.registerSingleton<About>(About());
GetIt.I<About>().init();
GetIt.I.registerSingleton<Changelog>(Changelog());
GetIt.I<Changelog>().init();
GetIt.I.registerSingleton<Settings>(Settings());
GetIt.I<Settings>().load();

// inference services
GetIt.I.registerSingleton<DrawingInterpreter>(DrawingInterpreter());

// draw screen services
GetIt.I.registerSingleton<KanjiBuffer>(KanjiBuffer());

// screen independent
GetIt.I.registerSingleton(DrawerListener());
GetIt.I.registerSingleton<Lookup>(Lookup());
}

/// The starting widget of the app
Expand Down
98 changes: 58 additions & 40 deletions lib/provider/Strokes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class Strokes with ChangeNotifier{
Path _path;
/// How many strokes are there
int _strokeCount;
/// Is the animation to delete the last stroke currently running
bool _deletingLastStroke;
/// Is the animation to delete all strokes currently running
bool _deletingAllStrokes;
/// should the delete last stroke animation start
bool _playDeleteLastStrokeAnimation = false;
/// should the delete all strokes animation start
bool _playDeleteAllStrokesAnimation = false;



get path {
Expand All @@ -24,12 +25,44 @@ class Strokes with ChangeNotifier{

notifyListeners();
}

get playDeleteLastStrokeAnimation {
return _playDeleteLastStrokeAnimation;
}

set playDeleteLastStrokeAnimation (bool play){
// do not play an animation if there are no strokes
if(strokeCount > 0 && play){
_playDeleteLastStrokeAnimation = true;
notifyListeners();
}
else{
_playDeleteLastStrokeAnimation = false;
}
}

get playDeleteAllStrokesAnimation {
return _playDeleteAllStrokesAnimation;
}

set playDeleteAllStrokesAnimation (bool play){
// do not play an animation if there are no strokes
if(strokeCount > 0 && play){
_playDeleteAllStrokesAnimation = true;
notifyListeners();
}
else{
_playDeleteAllStrokesAnimation = false;
}
}

/// Start a new sub stroke at ([x], [y])
void moveTo(double x, double y){
_path.moveTo(x, y);
notifyListeners();
notifyListeners();
}

/// Draw a line from the current position to the position ([x], [y]).
void lineTo(double x, double y){
_path.lineTo(x, y);
notifyListeners();
Expand All @@ -39,14 +72,6 @@ class Strokes with ChangeNotifier{
return _strokeCount;
}

get deletingLastStroke{
return _deletingLastStroke;
}

get deletingAllStrokes{
return _deletingAllStrokes;
}

void incrementStrokeCount(){
_strokeCount++;
}
Expand All @@ -58,22 +83,18 @@ class Strokes with ChangeNotifier{
Strokes() {
_path = Path();
_strokeCount = 0;
_deletingLastStroke = false;
_deletingAllStrokes = false;
}

/// Deletes all drawn strokes.
void deleteAllStrokes(){
_path.reset();
_strokeCount = 0;

_deletingAllStrokes = false;

notifyListeners();

/// Deletes all drawn strokes WITHOUT notifying listeners.
void removeAllStrokes(){
if(strokeCount > 0){
_path.reset();
_strokeCount = 0;
}
}

/// Deletes the last stroke of all drawn strokes.
void deleteLastStroke(){
/// Deletes the last stroke of all drawn strokes WITHOUT notifying listeners.
void removeLastStroke(){

if(strokeCount > 0){
// get all strokes except for the last one
Expand All @@ -86,27 +107,24 @@ class Strokes with ChangeNotifier{
_path = newPath;

decrementStrokeCount();

_deletingLastStroke = false;

notifyListeners();
}
}

/// Run the delete last strokes animation and delete the last stroke
/// at the end.
void deleteLastStrokeAnimation() {
if(!_deletingAllStrokes){
_deletingLastStroke = true;
/// Deletes all drawn strokes and notifies all listeners.
void deleteAllStrokes(){
if(strokeCount > 0){
removeAllStrokes();
notifyListeners();
}
}

/// Run the delete all strokes animation and delete all strokes at the end.
void deleteAllStrokesAnimation() {
_deletingLastStroke = false;
_deletingAllStrokes = true;
notifyListeners();
/// Deletes the last stroke of all drawn strokes and notifies all listeners.
void deleteLastStroke(){

if(strokeCount > 0){
removeAllStrokes();
notifyListeners();
}
}

}
47 changes: 33 additions & 14 deletions lib/view/HomeScreen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:da_kanji_mobile/provider/Changelog.dart';
import 'package:da_kanji_mobile/view/ChangelogScreen.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

Expand All @@ -7,6 +7,7 @@ import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';

import 'package:da_kanji_mobile/provider/Settings.dart';
import 'package:da_kanji_mobile/provider/Changelog.dart';



Expand Down Expand Up @@ -65,19 +66,37 @@ class _HomeScreenState extends State<HomeScreen> {
width: MediaQuery.of(context).size.width * 3/4,
height: MediaQuery.of(context).size.height * 2/4,
),
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(
Color.fromARGB(100, 150, 150, 150)
)
),
onPressed: () async {
GetIt.I<Settings>().save();
Navigator.pushNamedAndRemoveUntil(
context, "/home", (Route<dynamic> route) => false);
},
child: Text("close")
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(
Color.fromARGB(100, 150, 150, 150)
)
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => ChangelogScreen()),
),
child: Text("Complete log")
),
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(
Color.fromARGB(100, 150, 150, 150)
)
),
onPressed: () async {
GetIt.I<Settings>().save();
Navigator.pushNamedAndRemoveUntil(
context, "/home", (Route<dynamic> route) => false);
},
child: Text("close")
),
],
)
]
)
Expand Down
39 changes: 24 additions & 15 deletions lib/view/drawing/DrawScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _DrawScreenState extends State<DrawScreen> with TickerProviderStateMixin {
/// the size of the canvas widget
double _canvasSize;


@override
void initState() {
super.initState();
Expand Down Expand Up @@ -80,13 +81,14 @@ class _DrawScreenState extends State<DrawScreen> with TickerProviderStateMixin {
currentScreen: Screens.drawing,
animationAtStart: !widget.openedByDrawer,
child: Center(
child: ChangeNotifierProvider.value(
value: GetIt.I<Strokes>(),
child: ChangeNotifierProvider(
create: (context) => Strokes(),
child: Column(
children: [
// the canvas to draw on
Consumer<Strokes>(
builder: (context, strokes, child){
builder: (context, strokes, __){

return DrawingCanvas(
width: _canvasSize,
height: _canvasSize,
Expand All @@ -99,7 +101,6 @@ class _DrawScreenState extends State<DrawScreen> with TickerProviderStateMixin {
onFinishedDrawing: (Uint8List image) async {
GetIt.I<DrawingInterpreter>().runInference(image);
},

onDeletedLastStroke: (Uint8List image) {
if(strokes.strokeCount > 0)
GetIt.I<DrawingInterpreter>().runInference(image);
Expand All @@ -110,7 +111,7 @@ class _DrawScreenState extends State<DrawScreen> with TickerProviderStateMixin {
GetIt.I<DrawingInterpreter>().clearPredictions();
},
);
}
},
),
Spacer(),
// undo/clear button and kanjiBuffer,
Expand All @@ -119,11 +120,15 @@ class _DrawScreenState extends State<DrawScreen> with TickerProviderStateMixin {
child: Row(
children: [
// undo
IconButton(
key: SHOWCASE_DRAWING[1].key,
icon: Icon(Icons.undo),
onPressed: () {
GetIt.I<Strokes>().deleteLastStrokeAnimation();
Consumer<Strokes>(
builder: (context, strokes, __) {
return IconButton(
key: SHOWCASE_DRAWING[1].key,
icon: Icon(Icons.undo),
onPressed: () {
strokes.playDeleteLastStrokeAnimation = true;
}
);
}
),
// multi character search input
Expand All @@ -146,11 +151,15 @@ class _DrawScreenState extends State<DrawScreen> with TickerProviderStateMixin {
),
),
// clear
IconButton(
key: SHOWCASE_DRAWING[2].key,
icon: Icon(Icons.clear),
onPressed: () {
GetIt.I<Strokes>().deleteAllStrokesAnimation();
Consumer<Strokes>(
builder: (contxt, strokes, _) {
return IconButton(
key: SHOWCASE_DRAWING[2].key,
icon: Icon(Icons.clear),
onPressed: () {
strokes.playDeleteAllStrokesAnimation = true;
}
);
}
),
]
Expand Down
Loading

0 comments on commit 8c35b35

Please sign in to comment.