ibutton-scene-add-value.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. byte_input_set_result_callback(
  11. byte_input,
  12. callback,
  13. NULL,
  14. app,
  15. app->get_key()->get_data(),
  16. app->get_key()->get_type_data_size());
  17. byte_input_set_header_text(byte_input, "Enter the key");
  18. view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
  19. }
  20. bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
  21. bool consumed = false;
  22. if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
  23. app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
  24. consumed = true;
  25. }
  26. return consumed;
  27. }
  28. void iButtonSceneAddValue::on_exit(iButtonApp* app) {
  29. iButtonAppViewManager* view_manager = app->get_view_manager();
  30. ByteInput* byte_input = view_manager->get_byte_input();
  31. byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
  32. byte_input_set_header_text(byte_input, {0});
  33. }
  34. void iButtonSceneAddValue::byte_input_callback(void* context) {
  35. iButtonApp* app = static_cast<iButtonApp*>(context);
  36. iButtonEvent event;
  37. event.type = iButtonEvent::Type::EventTypeByteEditResult;
  38. app->get_view_manager()->send_event(&event);
  39. }