ibutton-scene-add-value.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "ibutton-scene-add-value.h"
  2. #include "../ibutton-app.h"
  3. #include "../ibutton-view-manager.h"
  4. #include "../ibutton-event.h"
  5. #include <callback-connector.h>
  6. void iButtonSceneAddValue::on_enter(iButtonApp* app) {
  7. iButtonAppViewManager* view_manager = app->get_view_manager();
  8. ByteInput* byte_input = view_manager->get_byte_input();
  9. auto callback = cbc::obtain_connector(this, &iButtonSceneAddValue::byte_input_callback);
  10. memcpy(this->new_key_data, app->get_key()->get_data(), app->get_key()->get_type_data_size());
  11. byte_input_set_result_callback(
  12. byte_input, callback, NULL, app, this->new_key_data, app->get_key()->get_type_data_size());
  13. byte_input_set_header_text(byte_input, "Enter the key");
  14. view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
  15. }
  16. bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
  17. bool consumed = false;
  18. if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
  19. app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
  20. consumed = true;
  21. }
  22. return consumed;
  23. }
  24. void iButtonSceneAddValue::on_exit(iButtonApp* app) {
  25. iButtonAppViewManager* view_manager = app->get_view_manager();
  26. ByteInput* byte_input = view_manager->get_byte_input();
  27. byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
  28. byte_input_set_header_text(byte_input, {0});
  29. }
  30. void iButtonSceneAddValue::byte_input_callback(void* context) {
  31. iButtonApp* app = static_cast<iButtonApp*>(context);
  32. iButtonEvent event;
  33. event.type = iButtonEvent::Type::EventTypeByteEditResult;
  34. memcpy(app->get_key()->get_data(), this->new_key_data, app->get_key()->get_type_data_size());
  35. app->get_view_manager()->send_event(&event);
  36. }