add refresh display theme param for Apply function (#1865)
This commit is contained in:
@ -50,8 +50,8 @@ bool Assets::FindPartition(Assets* assets) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::Apply() {
|
bool Assets::Apply(bool refresh_display_theme) {
|
||||||
return strategy_ ? strategy_->Apply(this) : false;
|
return strategy_ ? strategy_->Apply(this, refresh_display_theme) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::InitializePartition() {
|
bool Assets::InitializePartition() {
|
||||||
@ -211,7 +211,7 @@ bool Assets::LvglStrategy::GetAssetData(Assets* assets, const std::string& name,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::LvglStrategy::Apply(Assets* assets) {
|
bool Assets::LvglStrategy::Apply(Assets* assets, bool refresh_display_theme) {
|
||||||
void* ptr = nullptr;
|
void* ptr = nullptr;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (!assets->GetAssetData("index.json", ptr, size)) {
|
if (!assets->GetAssetData("index.json", ptr, size)) {
|
||||||
@ -332,22 +332,24 @@ bool Assets::LvglStrategy::Apply(Assets* assets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto display = Board::GetInstance().GetDisplay();
|
if (refresh_display_theme) {
|
||||||
ESP_LOGI(TAG, "Refreshing display theme...");
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
|
ESP_LOGI(TAG, "Refreshing display theme...");
|
||||||
|
|
||||||
auto current_theme = display->GetTheme();
|
auto current_theme = display->GetTheme();
|
||||||
if (current_theme != nullptr) {
|
if (current_theme != nullptr) {
|
||||||
display->SetTheme(current_theme);
|
display->SetTheme(current_theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse hide_subtitle configuration
|
// Parse hide_subtitle configuration
|
||||||
cJSON* hide_subtitle = cJSON_GetObjectItem(root, "hide_subtitle");
|
cJSON* hide_subtitle = cJSON_GetObjectItem(root, "hide_subtitle");
|
||||||
if (cJSON_IsBool(hide_subtitle)) {
|
if (cJSON_IsBool(hide_subtitle)) {
|
||||||
bool hide = cJSON_IsTrue(hide_subtitle);
|
bool hide = cJSON_IsTrue(hide_subtitle);
|
||||||
auto lcd_display = dynamic_cast<LcdDisplay*>(display);
|
auto lcd_display = dynamic_cast<LcdDisplay*>(display);
|
||||||
if (lcd_display != nullptr) {
|
if (lcd_display != nullptr) {
|
||||||
lcd_display->SetHideSubtitle(hide);
|
lcd_display->SetHideSubtitle(hide);
|
||||||
ESP_LOGI(TAG, "Set hide_subtitle to %s", hide ? "true" : "false");
|
ESP_LOGI(TAG, "Set hide_subtitle to %s", hide ? "true" : "false");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +413,7 @@ bool Assets::EmoteStrategy::GetAssetData(Assets* assets, const std::string& name
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::EmoteStrategy::Apply(Assets* assets) {
|
bool Assets::EmoteStrategy::Apply(Assets* assets, bool refresh_display_theme) {
|
||||||
Assets::LoadSrmodelsFromIndex(assets);
|
Assets::LoadSrmodelsFromIndex(assets);
|
||||||
|
|
||||||
auto display = Board::GetInstance().GetDisplay();
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public:
|
|||||||
~Assets();
|
~Assets();
|
||||||
|
|
||||||
bool Download(std::string url, std::function<void(int progress, size_t speed)> progress_callback);
|
bool Download(std::string url, std::function<void(int progress, size_t speed)> progress_callback);
|
||||||
bool Apply();
|
bool Apply(bool refresh_display_theme = true);
|
||||||
bool GetAssetData(const std::string& name, void*& ptr, size_t& size);
|
bool GetAssetData(const std::string& name, void*& ptr, size_t& size);
|
||||||
|
|
||||||
inline bool partition_valid() const { return partition_valid_; }
|
inline bool partition_valid() const { return partition_valid_; }
|
||||||
@ -48,7 +48,7 @@ private:
|
|||||||
class AssetStrategy {
|
class AssetStrategy {
|
||||||
public:
|
public:
|
||||||
virtual ~AssetStrategy() = default;
|
virtual ~AssetStrategy() = default;
|
||||||
virtual bool Apply(Assets* assets) = 0;
|
virtual bool Apply(Assets* assets, bool refresh_display_theme = true) = 0;
|
||||||
virtual bool InitializePartition(Assets* assets) = 0;
|
virtual bool InitializePartition(Assets* assets) = 0;
|
||||||
virtual void UnApplyPartition(Assets* assets) = 0;
|
virtual void UnApplyPartition(Assets* assets) = 0;
|
||||||
virtual bool GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) = 0;
|
virtual bool GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) = 0;
|
||||||
@ -56,7 +56,7 @@ private:
|
|||||||
|
|
||||||
class LvglStrategy : public AssetStrategy {
|
class LvglStrategy : public AssetStrategy {
|
||||||
public:
|
public:
|
||||||
bool Apply(Assets* assets) override;
|
bool Apply(Assets* assets, bool refresh_display_theme = true) override;
|
||||||
bool InitializePartition(Assets* assets) override;
|
bool InitializePartition(Assets* assets) override;
|
||||||
void UnApplyPartition(Assets* assets) override;
|
void UnApplyPartition(Assets* assets) override;
|
||||||
bool GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) override;
|
bool GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) override;
|
||||||
@ -70,7 +70,7 @@ private:
|
|||||||
|
|
||||||
class EmoteStrategy : public AssetStrategy {
|
class EmoteStrategy : public AssetStrategy {
|
||||||
public:
|
public:
|
||||||
bool Apply(Assets* assets) override;
|
bool Apply(Assets* assets, bool refresh_display_theme = true) override;
|
||||||
bool InitializePartition(Assets* assets) override;
|
bool InitializePartition(Assets* assets) override;
|
||||||
void UnApplyPartition(Assets* assets) override;
|
void UnApplyPartition(Assets* assets) override;
|
||||||
bool GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) override;
|
bool GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user