A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add option to hide battery percentage. (#297)

with option to always hide or hide in reader only.

Co-authored-by: Dave Allie <dave@daveallie.com>

authored by

Jonas Diemer
Dave Allie
and committed by
GitHub
88d0d904 97c48713

+25 -7
+3
src/CrossPointSettings.cpp
··· 46 46 serialization::writePod(outputFile, sleepScreenCoverMode); 47 47 serialization::writeString(outputFile, std::string(opdsServerUrl)); 48 48 serialization::writePod(outputFile, textAntiAliasing); 49 + serialization::writePod(outputFile, hideBatteryPercentage); 49 50 outputFile.close(); 50 51 51 52 Serial.printf("[%lu] [CPS] Settings saved to file\n", millis()); ··· 109 110 opdsServerUrl[sizeof(opdsServerUrl) - 1] = '\0'; 110 111 } 111 112 serialization::readPod(inputFile, textAntiAliasing); 113 + if (++settingsRead >= fileSettingsCount) break; 114 + serialization::readPod(inputFile, hideBatteryPercentage); 112 115 if (++settingsRead >= fileSettingsCount) break; 113 116 } while (false); 114 117
+5
src/CrossPointSettings.h
··· 55 55 // Short power button press actions 56 56 enum SHORT_PWRBTN { IGNORE = 0, SLEEP = 1, PAGE_TURN = 2 }; 57 57 58 + // Hide battery percentage 59 + enum HIDE_BATTERY_PERCENTAGE { HIDE_NEVER = 0, HIDE_READER = 1, HIDE_ALWAYS = 2 }; 60 + 58 61 // Sleep screen settings 59 62 uint8_t sleepScreen = DARK; 60 63 // Sleep screen cover mode settings ··· 85 88 uint8_t screenMargin = 5; 86 89 // OPDS browser settings 87 90 char opdsServerUrl[128] = ""; 91 + // Hide battery percentage 92 + uint8_t hideBatteryPercentage = HIDE_NEVER; 88 93 89 94 ~CrossPointSettings() = default; 90 95
+3 -2
src/ScreenComponents.cpp
··· 8 8 #include "Battery.h" 9 9 #include "fontIds.h" 10 10 11 - void ScreenComponents::drawBattery(const GfxRenderer& renderer, const int left, const int top) { 11 + void ScreenComponents::drawBattery(const GfxRenderer& renderer, const int left, const int top, 12 + const bool showPercentage) { 12 13 // Left aligned battery icon and percentage 13 14 const uint16_t percentage = battery.readPercentage(); 14 - const auto percentageText = std::to_string(percentage) + "%"; 15 + const auto percentageText = showPercentage ? std::to_string(percentage) + "%" : ""; 15 16 renderer.drawText(SMALL_FONT_ID, left + 20, top, percentageText.c_str()); 16 17 17 18 // 1 column on left, 2 columns on right, 5 columns of battery body
+1 -1
src/ScreenComponents.h
··· 7 7 8 8 class ScreenComponents { 9 9 public: 10 - static void drawBattery(const GfxRenderer& renderer, int left, int top); 10 + static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true); 11 11 12 12 /** 13 13 * Draw a progress bar with percentage text.
+8 -2
src/activities/home/HomeActivity.cpp
··· 7 7 #include <cstring> 8 8 #include <vector> 9 9 10 + #include "Battery.h" 10 11 #include "CrossPointSettings.h" 11 12 #include "CrossPointState.h" 12 13 #include "MappedInputManager.h" ··· 332 333 const auto labels = mappedInput.mapLabels("", "Confirm", "Up", "Down"); 333 334 renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4); 334 335 335 - const auto batteryX = pageWidth - 25 - renderer.getTextWidth(SMALL_FONT_ID, "100 %"); 336 - ScreenComponents::drawBattery(renderer, batteryX, 10); 336 + const bool showBatteryPercentage = 337 + SETTINGS.hideBatteryPercentage != CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_ALWAYS; 338 + // get percentage so we can align text properly 339 + const uint16_t percentage = battery.readPercentage(); 340 + const auto percentageText = showBatteryPercentage ? std::to_string(percentage) + "%" : ""; 341 + const auto batteryX = pageWidth - 25 - renderer.getTextWidth(SMALL_FONT_ID, percentageText.c_str()); 342 + ScreenComponents::drawBattery(renderer, batteryX, 10, showBatteryPercentage); 337 343 338 344 renderer.displayBuffer(); 339 345 }
+3 -1
src/activities/reader/EpubReaderActivity.cpp
··· 419 419 SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL; 420 420 const bool showChapterTitle = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::NO_PROGRESS || 421 421 SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL; 422 + const bool showBatteryPercentage = 423 + SETTINGS.hideBatteryPercentage == CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_NEVER; 422 424 423 425 // Position status bar near the bottom of the logical screen, regardless of orientation 424 426 const auto screenHeight = renderer.getScreenHeight(); ··· 439 441 } 440 442 441 443 if (showBattery) { 442 - ScreenComponents::drawBattery(renderer, orientedMarginLeft + 1, textY); 444 + ScreenComponents::drawBattery(renderer, orientedMarginLeft + 1, textY, showBatteryPercentage); 443 445 } 444 446 445 447 if (showChapterTitle) {
+2 -1
src/activities/settings/SettingsActivity.cpp
··· 13 13 14 14 // Define the static settings list 15 15 namespace { 16 - constexpr int settingsCount = 18; 16 + constexpr int settingsCount = 19; 17 17 const SettingInfo settingsList[settingsCount] = { 18 18 // Should match with SLEEP_SCREEN_MODE 19 19 SettingInfo::Enum("Sleep Screen", &CrossPointSettings::sleepScreen, {"Dark", "Light", "Custom", "Cover", "None"}), 20 20 SettingInfo::Enum("Sleep Screen Cover Mode", &CrossPointSettings::sleepScreenCoverMode, {"Fit", "Crop"}), 21 21 SettingInfo::Enum("Status Bar", &CrossPointSettings::statusBar, {"None", "No Progress", "Full"}), 22 + SettingInfo::Enum("Hide Battery %", &CrossPointSettings::hideBatteryPercentage, {"Never", "In Reader", "Always"}), 22 23 SettingInfo::Toggle("Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing), 23 24 SettingInfo::Toggle("Text Anti-Aliasing", &CrossPointSettings::textAntiAliasing), 24 25 SettingInfo::Enum("Short Power Button Click", &CrossPointSettings::shortPwrBtn, {"Ignore", "Sleep", "Page Turn"}),