|
|
@@ -2,49 +2,93 @@
|
|
|
#include "../helpers/hex_viewer_custom_event.h"
|
|
|
#include "../views/hex_viewer_scene_1.h"
|
|
|
|
|
|
-void hex_viewer_scene_1_callback(HexViewerCustomEvent event, void* context) {
|
|
|
- furi_assert(context);
|
|
|
- HexViewer* app = context;
|
|
|
- view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
|
|
+void hex_viewer_scene_scene_1_callback(void* context) {
|
|
|
+ HexViewer* app = (HexViewer*)context;
|
|
|
+ view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_RENAME_CUSTOM_EVENT);
|
|
|
}
|
|
|
|
|
|
void hex_viewer_scene_scene_1_on_enter(void* context) {
|
|
|
furi_assert(context);
|
|
|
HexViewer* app = context;
|
|
|
- hex_viewer_scene_1_set_callback(app->hex_viewer_scene_1, hex_viewer_scene_1_callback, app);
|
|
|
- view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdScene1);
|
|
|
+
|
|
|
+ TextInput* text_input = app->text_input;
|
|
|
+
|
|
|
+ text_input_set_header_text(text_input, "Go to percent (0..100)");
|
|
|
+ text_input_set_result_callback(
|
|
|
+ text_input,
|
|
|
+ hex_viewer_scene_scene_1_callback,
|
|
|
+ app,
|
|
|
+ app->percent_buf,
|
|
|
+ HEX_VIEWER_PERCENT_INPUT,
|
|
|
+ false);
|
|
|
+
|
|
|
+ // ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
|
|
+ // IBUTTON_APP_FOLDER, IBUTTON_APP_FILENAME_EXTENSION, ibutton->key_name);
|
|
|
+ // text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
|
|
+
|
|
|
+ view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene1);
|
|
|
+
|
|
|
+
|
|
|
+ // if(success) {
|
|
|
+ // //
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if(success) {
|
|
|
+ // // Load page to do something with result
|
|
|
+ // //scene_manager_next_scene(app->scene_manager, HexViewerViewIdMenu);
|
|
|
+ // //scene_manager_previous_scene(app->scene_manager); // temp for showcase
|
|
|
+ // scene_manager_search_and_switch_to_previous_scene(
|
|
|
+ // app->scene_manager, HexViewerViewIdStartscreen);
|
|
|
+ // } else {
|
|
|
+ // // This is basically if someone quites the browser
|
|
|
+ // scene_manager_previous_scene(app->scene_manager);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
|
|
|
- HexViewer* app = context;
|
|
|
+ HexViewer* app = (HexViewer*)context;
|
|
|
bool consumed = false;
|
|
|
-
|
|
|
+
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
- switch(event.event) {
|
|
|
- case HexViewerCustomEventScene1Left:
|
|
|
- case HexViewerCustomEventScene1Right:
|
|
|
- break;
|
|
|
- case HexViewerCustomEventScene1Up:
|
|
|
- case HexViewerCustomEventScene1Down:
|
|
|
- break;
|
|
|
- case HexViewerCustomEventScene1Back:
|
|
|
- notification_message(app->notification, &sequence_reset_red);
|
|
|
- notification_message(app->notification, &sequence_reset_green);
|
|
|
- notification_message(app->notification, &sequence_reset_blue);
|
|
|
- if(!scene_manager_search_and_switch_to_previous_scene(
|
|
|
- app->scene_manager, HexViewerSceneMenu)) {
|
|
|
- scene_manager_stop(app->scene_manager);
|
|
|
- view_dispatcher_stop(app->view_dispatcher);
|
|
|
- }
|
|
|
- consumed = true;
|
|
|
- break;
|
|
|
+ if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
|
|
|
+
|
|
|
+ float percent = atof(app->percent_buf);
|
|
|
+ percent = MIN(percent, 100.0);
|
|
|
+ percent = MAX(percent, 0);
|
|
|
+ percent = percent / 100;
|
|
|
+
|
|
|
+ uint32_t line_count = model->file_size / HEX_VIEWER_BYTES_PER_LINE;
|
|
|
+ if(model->file_size % HEX_VIEWER_BYTES_PER_LINE != 0) line_count += 1;
|
|
|
+ uint32_t scrollable_lines = line_count - HEX_VIEWER_LINES_ON_SCREEN;
|
|
|
+ uint32_t target_line = (uint32_t)(percent * scrollable_lines);
|
|
|
+
|
|
|
+ // uint32_t first_line_on_screen = model->file_offset / HEX_VIEWER_BYTES_PER_LINE;
|
|
|
+ // if(line_count > HEX_VIEWER_LINES_ON_SCREEN) {
|
|
|
+ // uint8_t width = canvas_width(canvas);
|
|
|
+ // elements_scrollbar_pos(
|
|
|
+ // canvas,
|
|
|
+ // width,
|
|
|
+ // 0,
|
|
|
+ // ROW_HEIGHT * HEX_VIEWER_LINES_ON_SCREEN,
|
|
|
+ // first_line_on_screen, // TODO
|
|
|
+ // line_count - (HEX_VIEWER_LINES_ON_SCREEN - 1));
|
|
|
+ // }
|
|
|
+
|
|
|
+ uint32_t new_file_offset = target_line * HEX_VIEWER_BYTES_PER_LINE;
|
|
|
+ if(app->model->file_size > new_file_offset) {
|
|
|
+ app->model->file_offset = new_file_offset;
|
|
|
+ if(!hex_viewer_read_file(app)) break; // TODO Do smth
|
|
|
+ }
|
|
|
+
|
|
|
+ scene_manager_search_and_switch_to_previous_scene(
|
|
|
+ app->scene_manager, HexViewerViewIdStartscreen);
|
|
|
+
|
|
|
+ consumed = true;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return consumed;
|
|
|
}
|
|
|
|
|
|
void hex_viewer_scene_scene_1_on_exit(void* context) {
|
|
|
- HexViewer* app = context;
|
|
|
- UNUSED(app);
|
|
|
-}
|
|
|
+ UNUSED(context);
|
|
|
+}
|