2022-01-05 16:10:18 +00:00
|
|
|
#include "accessor_view_manager.h"
|
|
|
|
#include "accessor_event.h"
|
2021-04-28 12:13:25 +00:00
|
|
|
#include <callback-connector.h>
|
|
|
|
|
|
|
|
AccessorAppViewManager::AccessorAppViewManager() {
|
2022-07-20 10:56:33 +00:00
|
|
|
event_queue = furi_message_queue_alloc(10, sizeof(AccessorEvent));
|
2021-04-28 12:13:25 +00:00
|
|
|
|
|
|
|
view_dispatcher = view_dispatcher_alloc();
|
|
|
|
auto callback = cbc::obtain_connector(this, &AccessorAppViewManager::previous_view_callback);
|
|
|
|
|
|
|
|
// allocate views
|
|
|
|
submenu = submenu_alloc();
|
|
|
|
add_view(ViewType::Submenu, submenu_get_view(submenu));
|
|
|
|
|
|
|
|
popup = popup_alloc();
|
|
|
|
add_view(ViewType::Popup, popup_get_view(popup));
|
|
|
|
|
|
|
|
gui = static_cast<Gui*>(furi_record_open("gui"));
|
|
|
|
view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen);
|
|
|
|
|
|
|
|
// set previous view callback for all views
|
|
|
|
view_set_previous_callback(submenu_get_view(submenu), callback);
|
|
|
|
view_set_previous_callback(popup_get_view(popup), callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
AccessorAppViewManager::~AccessorAppViewManager() {
|
|
|
|
// remove views
|
|
|
|
view_dispatcher_remove_view(
|
|
|
|
view_dispatcher, static_cast<uint32_t>(AccessorAppViewManager::ViewType::Submenu));
|
|
|
|
view_dispatcher_remove_view(
|
|
|
|
view_dispatcher, static_cast<uint32_t>(AccessorAppViewManager::ViewType::Popup));
|
|
|
|
|
|
|
|
// free view modules
|
|
|
|
submenu_free(submenu);
|
|
|
|
popup_free(popup);
|
|
|
|
|
|
|
|
// free dispatcher
|
|
|
|
view_dispatcher_free(view_dispatcher);
|
|
|
|
|
|
|
|
// free event queue
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_message_queue_free(event_queue);
|
2021-04-28 12:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccessorAppViewManager::switch_to(ViewType type) {
|
|
|
|
view_dispatcher_switch_to_view(view_dispatcher, static_cast<uint32_t>(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
Submenu* AccessorAppViewManager::get_submenu() {
|
|
|
|
return submenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
Popup* AccessorAppViewManager::get_popup() {
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccessorAppViewManager::receive_event(AccessorEvent* event) {
|
2022-07-20 10:56:33 +00:00
|
|
|
if(furi_message_queue_get(event_queue, event, 100) != FuriStatusOk) {
|
2021-04-28 12:13:25 +00:00
|
|
|
event->type = AccessorEvent::Type::Tick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccessorAppViewManager::send_event(AccessorEvent* event) {
|
2022-07-20 10:56:33 +00:00
|
|
|
FuriStatus result = furi_message_queue_put(event_queue, event, 0);
|
|
|
|
furi_check(result == FuriStatusOk);
|
2021-04-28 12:13:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 13:37:10 +00:00
|
|
|
uint32_t AccessorAppViewManager::previous_view_callback(void*) {
|
2021-04-28 12:13:25 +00:00
|
|
|
if(event_queue != NULL) {
|
|
|
|
AccessorEvent event;
|
|
|
|
event.type = AccessorEvent::Type::Back;
|
|
|
|
send_event(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return VIEW_IGNORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccessorAppViewManager::add_view(ViewType view_type, View* view) {
|
|
|
|
view_dispatcher_add_view(view_dispatcher, static_cast<uint32_t>(view_type), view);
|
2022-05-06 13:37:10 +00:00
|
|
|
}
|