#include "NetworkModeSelectionActivity.h" #include #include #include "MappedInputManager.h" #include "components/UITheme.h" #include "components/UiAppHelpers.h" namespace fui = freeink::ui; namespace { constexpr StrId menuItems[NetworkModeSelectionActivity::MENU_ITEM_COUNT] = { StrId::STR_JOIN_NETWORK, StrId::STR_CALIBRE_WIRELESS, StrId::STR_CREATE_HOTSPOT, #if FREEINK_CAP_USB_MSC StrId::STR_USB_DRIVE, #endif }; constexpr StrId menuDescs[NetworkModeSelectionActivity::MENU_ITEM_COUNT] = { StrId::STR_JOIN_DESC, StrId::STR_CALIBRE_DESC, StrId::STR_HOTSPOT_DESC, #if FREEINK_CAP_USB_MSC StrId::STR_USB_DRIVE_DESC, #endif }; constexpr UIIcon menuIcons[NetworkModeSelectionActivity::MENU_ITEM_COUNT] = { UIIcon::Wifi, UIIcon::Library, UIIcon::Hotspot, #if FREEINK_CAP_USB_MSC UIIcon::Usb, #endif }; } // namespace NetworkModeSelectionActivity::NetworkModeSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput) : UiListActivity("NetworkModeSelection", renderer, mappedInput) { // Entirely static, so built once here rather than every buildScreen() call. for (int i = 0; i < MENU_ITEM_COUNT; i++) { fui::ListItem item; item.label = I18N.get(menuItems[i]); item.subtitle = I18N.get(menuDescs[i]); item.icon = listIconFor(menuIcons[i], 32); // subtitle rows carry the larger icon item.actionValue = static_cast(i); rowItems_[i] = item; } } int NetworkModeSelectionActivity::listCount() const { return MENU_ITEM_COUNT; } const char* NetworkModeSelectionActivity::headerTitle() const { return tr(STR_FILE_TRANSFER); } void NetworkModeSelectionActivity::activateIndex(const int index) { // Selection leaves this screen; a lingering flash would gray an unrelated // element on the next render. app.clearTapFlash(); nav.selected = index; onModeSelected(static_cast(index)); } void NetworkModeSelectionActivity::buildScreen(UiScreen& screen) { const auto& metrics = UITheme::getInstance().getMetrics(); // Content below the GUI.drawHeader band, above the button hints. screen.setContentMarginFromScreen(fui::Insets{static_cast(metrics.topPadding + metrics.headerHeight), 0, static_cast(metrics.buttonHintsHeight), 0}); screen.spacer(static_cast(metrics.verticalSpacing)); // rowItems_ was built once in the constructor and is reused here on every // repaint. fui::ListProps props; props.items = rowItems_; props.count = static_cast(MENU_ITEM_COUNT); props.action = ACTION_ROW; props.inputMask = fui::InputTouch; // physical buttons stay in loop() props.subtitleText = screen.theme().smallText; props.subtitleText.maxLines = 2; syncListViewport(screen, props); screen.list(props); } void NetworkModeSelectionActivity::onModeSelected(NetworkMode mode) { setResult(NetworkModeResult{mode}); finish(); } void NetworkModeSelectionActivity::onCancel() { ActivityResult result; result.isCancelled = true; setResult(std::move(result)); finish(); }