mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 23:57:39 +03:00
Add hide extension option
This commit is contained in:
parent
03cc728f6f
commit
ac1ffd3d2c
@ -14,7 +14,7 @@ CrossPointSettings CrossPointSettings::instance;
|
|||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
||||||
// Increment this when adding new persisted settings fields
|
// Increment this when adding new persisted settings fields
|
||||||
constexpr uint8_t SETTINGS_COUNT = 20;
|
constexpr uint8_t SETTINGS_COUNT = 21;
|
||||||
constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin";
|
constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ bool CrossPointSettings::saveToFile() const {
|
|||||||
serialization::writePod(outputFile, hideBatteryPercentage);
|
serialization::writePod(outputFile, hideBatteryPercentage);
|
||||||
serialization::writePod(outputFile, longPressChapterSkip);
|
serialization::writePod(outputFile, longPressChapterSkip);
|
||||||
serialization::writePod(outputFile, hyphenationEnabled);
|
serialization::writePod(outputFile, hyphenationEnabled);
|
||||||
|
serialization::writePod(outputFile, displayFileExtensions);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
||||||
@ -120,6 +121,8 @@ bool CrossPointSettings::loadFromFile() {
|
|||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readPod(inputFile, hyphenationEnabled);
|
serialization::readPod(inputFile, hyphenationEnabled);
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
|
serialization::readPod(inputFile, displayFileExtensions);
|
||||||
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
|
|||||||
@ -94,6 +94,8 @@ class CrossPointSettings {
|
|||||||
uint8_t hideBatteryPercentage = HIDE_NEVER;
|
uint8_t hideBatteryPercentage = HIDE_NEVER;
|
||||||
// Long-press chapter skip on side buttons
|
// Long-press chapter skip on side buttons
|
||||||
uint8_t longPressChapterSkip = 1;
|
uint8_t longPressChapterSkip = 1;
|
||||||
|
// Display file extensions in the file browser
|
||||||
|
uint8_t displayFileExtensions = 0;
|
||||||
|
|
||||||
~CrossPointSettings() = default;
|
~CrossPointSettings() = default;
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include "ScreenComponents.h"
|
#include "ScreenComponents.h"
|
||||||
#include "fontIds.h"
|
#include "fontIds.h"
|
||||||
#include "util/StringUtils.h"
|
#include "util/StringUtils.h"
|
||||||
|
#include "CrossPointSettings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// Layout constants
|
// Layout constants
|
||||||
@ -375,7 +376,11 @@ void MyLibraryActivity::renderFilesTab() const {
|
|||||||
|
|
||||||
// Draw items
|
// Draw items
|
||||||
for (int i = pageStartIndex; i < fileCount && i < pageStartIndex + pageItems; i++) {
|
for (int i = pageStartIndex; i < fileCount && i < pageStartIndex + pageItems; i++) {
|
||||||
auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(), pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
std::string filename = files[i];
|
||||||
|
if (SETTINGS.displayFileExtensions == 0 && filename.back() != '/') {
|
||||||
|
filename = StringUtils::stripFileExtension(filename);
|
||||||
|
}
|
||||||
|
auto item = renderer.truncatedText(UI_10_FONT_ID, filename.c_str(), pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT, item.c_str(),
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT, item.c_str(),
|
||||||
i != selectorIndex);
|
i != selectorIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "MappedInputManager.h"
|
#include "MappedInputManager.h"
|
||||||
#include "fontIds.h"
|
#include "fontIds.h"
|
||||||
|
|
||||||
const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "System"};
|
const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "Files", "System"};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr int displaySettingsCount = 5;
|
constexpr int displaySettingsCount = 5;
|
||||||
@ -50,6 +50,10 @@ const SettingInfo systemSettings[systemSettingsCount] = {
|
|||||||
{"1 min", "5 min", "10 min", "15 min", "30 min"}),
|
{"1 min", "5 min", "10 min", "15 min", "30 min"}),
|
||||||
SettingInfo::Action("KOReader Sync"), SettingInfo::Action("Calibre Settings"), SettingInfo::Action("Clear Cache"),
|
SettingInfo::Action("KOReader Sync"), SettingInfo::Action("Calibre Settings"), SettingInfo::Action("Clear Cache"),
|
||||||
SettingInfo::Action("Check for updates")};
|
SettingInfo::Action("Check for updates")};
|
||||||
|
|
||||||
|
constexpr int filesSettingsCount = 1;
|
||||||
|
const SettingInfo filesSettings[filesSettingsCount] = {
|
||||||
|
SettingInfo::Toggle("Display File Extensions", &CrossPointSettings::displayFileExtensions)};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void SettingsActivity::taskTrampoline(void* param) {
|
void SettingsActivity::taskTrampoline(void* param) {
|
||||||
@ -144,7 +148,11 @@ void SettingsActivity::enterCategory(int categoryIndex) {
|
|||||||
settingsList = controlsSettings;
|
settingsList = controlsSettings;
|
||||||
settingsCount = controlsSettingsCount;
|
settingsCount = controlsSettingsCount;
|
||||||
break;
|
break;
|
||||||
case 3: // System
|
case 3: // Files
|
||||||
|
settingsList = filesSettings;
|
||||||
|
settingsCount = filesSettingsCount;
|
||||||
|
break;
|
||||||
|
case 4: // System
|
||||||
settingsList = systemSettings;
|
settingsList = systemSettings;
|
||||||
settingsCount = systemSettingsCount;
|
settingsCount = systemSettingsCount;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class SettingsActivity final : public ActivityWithSubactivity {
|
|||||||
int selectedCategoryIndex = 0; // Currently selected category
|
int selectedCategoryIndex = 0; // Currently selected category
|
||||||
const std::function<void()> onGoHome;
|
const std::function<void()> onGoHome;
|
||||||
|
|
||||||
static constexpr int categoryCount = 4;
|
static constexpr int categoryCount = 5;
|
||||||
static const char* categoryNames[categoryCount];
|
static const char* categoryNames[categoryCount];
|
||||||
|
|
||||||
static void taskTrampoline(void* param);
|
static void taskTrampoline(void* param);
|
||||||
|
|||||||
@ -80,4 +80,12 @@ void utf8TruncateChars(std::string& str, const size_t numChars) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string stripFileExtension(const std::string& filename) {
|
||||||
|
size_t last_dot = filename.find_last_of(".");
|
||||||
|
if (last_dot == std::string::npos) {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
return filename.substr(0, last_dot);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace StringUtils
|
} // namespace StringUtils
|
||||||
|
|||||||
@ -25,4 +25,10 @@ size_t utf8RemoveLastChar(std::string& str);
|
|||||||
|
|
||||||
// Truncate string by removing N UTF-8 characters from the end
|
// Truncate string by removing N UTF-8 characters from the end
|
||||||
void utf8TruncateChars(std::string& str, size_t numChars);
|
void utf8TruncateChars(std::string& str, size_t numChars);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip the file extension from a filename.
|
||||||
|
* If there's no extension, it returns the original filename.
|
||||||
|
*/
|
||||||
|
std::string stripFileExtension(const std::string& filename);
|
||||||
} // namespace StringUtils
|
} // namespace StringUtils
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user