From 7c0acdf71ba7f34c5fdeadfb5649881948495930 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 10 Feb 2020 17:20:21 +0300 Subject: [PATCH] [update] PuzzleImageView clean/remove buttons --- settings.gradle | 3 --- src/haxe/ru/m/puzzlez/PuzzlezTheme.hx | 1 + src/haxe/ru/m/puzzlez/source/FileSource.hx | 4 ++-- src/haxe/ru/m/puzzlez/view/GameListFrame.hx | 9 +++++---- src/haxe/ru/m/puzzlez/view/ImageListFrame.hx | 15 +++++++++++++-- src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx | 6 +++--- src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx | 8 ++++++++ src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml | 8 +++++++- 8 files changed, 39 insertions(+), 15 deletions(-) delete mode 100644 settings.gradle diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index c0a8ac7..0000000 --- a/settings.gradle +++ /dev/null @@ -1,3 +0,0 @@ -include ':android' - - diff --git a/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx b/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx index bac60d9..c24d5c8 100644 --- a/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx +++ b/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx @@ -23,6 +23,7 @@ class PuzzlezTheme extends Theme { "font.color" => Color.fromString("red"), ], "text")); registerButton("close", "times-circle-solid.svg", false, 0xcc5500); + registerButton("close-red", "times-circle-solid.svg", false, 0xcc0000); } private function registerButton(name:String, resource:String, solid:Bool = false, color:Color = null):Void { diff --git a/src/haxe/ru/m/puzzlez/source/FileSource.hx b/src/haxe/ru/m/puzzlez/source/FileSource.hx index b8a8c39..71cf633 100644 --- a/src/haxe/ru/m/puzzlez/source/FileSource.hx +++ b/src/haxe/ru/m/puzzlez/source/FileSource.hx @@ -20,7 +20,7 @@ class FileSource implements IImageSource { } public function getList(?type:Dynamic):Promise> { - return Promise.promise([for (name in Reflect.fields(listData.data)) new ImageId(id, name)]); + return Promise.promise([for (key in Reflect.fields(listData.data)) ImageId.fromString(key)]); } public function loadImage(id:ImageId, preview:Bool = false):Promise { @@ -42,7 +42,7 @@ class FileSource implements IImageSource { var fileData = SharedObject.getLocal(imageId); fileData.setProperty("image", data.toHex()); fileData.flush(); - listData.setProperty(name, true); + listData.setProperty(imageId, true); listData.flush(); return imageId; } diff --git a/src/haxe/ru/m/puzzlez/view/GameListFrame.hx b/src/haxe/ru/m/puzzlez/view/GameListFrame.hx index f18d52e..91ebce7 100644 --- a/src/haxe/ru/m/puzzlez/view/GameListFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/GameListFrame.hx @@ -29,15 +29,16 @@ import ru.m.puzzlez.view.PuzzleImageView; switcher.change(GameFrame.ID, storage.read(id)); } - private function onAction(id:ImageId, action:Action):Void { + private function onAction(imageId:ImageId, action:Action):Void { switch action { - case REMOVE: - ConfirmView.confirm("Delete?").then(function(result) { + case CLEAN: + ConfirmView.confirm("Delete state?").then(function(result) { if (result) { - storage.delete(id); + storage.delete(imageId); images.data = storage.listIds(); } }); + case _: } } diff --git a/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx b/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx index b064c5d..b474d12 100644 --- a/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx @@ -56,16 +56,27 @@ import ru.m.puzzlez.view.PuzzleImageView; case REMOVE: var fileSource:FileSource = Std.instance(source.source, FileSource); if (fileSource != null) { - ConfirmView.confirm("Delete?").then(function(result) { + ConfirmView.confirm("Delete image?").then(function(result) { if (result) { fileSource.remove(imageId); - loading.promise = fileSource.getList().then(function(result) images.data = result); + refresh(); } }); } + case CLEAN: + ConfirmView.confirm("Delete state?").then(function(result) { + if (result) { + gameStorage.delete(imageId); + refresh(); + } + }); } } + private function refresh():Void { + loading.promise = source.source.getList().then(function(result) images.data = result); + } + private function start(imageId:ImageId):Void { var state = gameStorage.read(imageId); if (state != null) { diff --git a/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx b/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx index 50562f8..5acecbc 100644 --- a/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx +++ b/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx @@ -22,8 +22,8 @@ class LoadingWrapper { private function set_promise(value:Promise):Promise { state = LOADING; value - .then(function(_) state = NONE) - .catchError(function(error) state = ERROR(error)); + .then(function(_) state = NONE); + //.catchError(function(error) state = ERROR(error)); return value; } @@ -39,7 +39,7 @@ class LoadingWrapper { overlay = loadingView; case ERROR(error): cast(errorView, TextView).text = Std.string(error); - overlay = errorView; + //overlay = errorView; } } return state; diff --git a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx index 33b9f7c..7169a69 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx +++ b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx @@ -7,10 +7,12 @@ import haxework.view.group.GroupView; import haxework.view.ImageView; import ru.m.puzzlez.core.GameUtil; import ru.m.puzzlez.core.Id; +import ru.m.puzzlez.source.FileSource; import ru.m.puzzlez.storage.GameStorage; import ru.m.puzzlez.storage.ImageStorage; enum Action { + CLEAN; REMOVE; } @@ -38,6 +40,7 @@ enum Action { @:view("image") var imageView:ImageView; @:view("label") var labelView:LabelView; + @:view("clean") var cleanButton:ButtonView; @:view("remove") var removeButton:ButtonView; @:provide static var imageStorage:ImageStorage; @:provide static var gameStorage:GameStorage; @@ -45,6 +48,8 @@ enum Action { public function new() { super(); + cleanButton.visible = false; + removeButton.visible = false; loading = new LoadingWrapper(this); } @@ -63,6 +68,9 @@ enum Action { if (state != null) { var progress = GameUtil.calcProgress(state); result.text = '${progress.complete}/${progress.total}'; + result.cleanButton.visible = true; + } else if (imageId.source == FileSource.ID) { + result.removeButton.visible = true; } return result; } diff --git a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml index 1df16e3..1a376fd 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml +++ b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml @@ -12,5 +12,11 @@ views: $type: haxework.view.form.ButtonView propagation: false geometry.hAlign: right - style: button.close.small + style: button.close-red.small +onPress: ~emit(Action.REMOVE) + - id: clean + $type: haxework.view.form.ButtonView + propagation: false + geometry.hAlign: right + style: button.close.small + +onPress: ~emit(Action.CLEAN)