From 1cd3138fc5a85518ab6017d54d6d47f5eadd407d Mon Sep 17 00:00:00 2001 From: Leon Styhre <leon@leonstyhre.com> Date: Mon, 29 Jan 2024 22:15:09 +0100 Subject: [PATCH] (Android) Added support for the Android-specific themes to the theme downloader --- es-app/src/guis/GuiThemeDownloader.cpp | 132 ++++++++++++++----------- 1 file changed, 74 insertions(+), 58 deletions(-) diff --git a/es-app/src/guis/GuiThemeDownloader.cpp b/es-app/src/guis/GuiThemeDownloader.cpp index f6623e51b..a2fb7706f 100644 --- a/es-app/src/guis/GuiThemeDownloader.cpp +++ b/es-app/src/guis/GuiThemeDownloader.cpp @@ -635,76 +635,92 @@ void GuiThemeDownloader::parseThemesList() } } - if (doc.HasMember("themes") && doc["themes"].IsArray()) { - const rapidjson::Value& themes {doc["themes"]}; - for (int i {0}; i < static_cast<int>(themes.Size()); ++i) { - ThemeEntry themeEntry; - const rapidjson::Value& theme {themes[i]}; +#if defined(__ANDROID__) + const std::vector<std::string> themeKeys {"themes", "themesAndroid"}; +#else + const std::vector<std::string> themeKeys {"themes"}; +#endif - if (theme.HasMember("name") && theme["name"].IsString()) - themeEntry.name = theme["name"].GetString(); + for (auto& themeKey : themeKeys) { + if (doc.HasMember(themeKey.c_str()) && doc[themeKey.c_str()].IsArray()) { + const rapidjson::Value& themes {doc[themeKey.c_str()]}; + for (int i {0}; i < static_cast<int>(themes.Size()); ++i) { + ThemeEntry themeEntry; + const rapidjson::Value& theme {themes[i]}; - if (theme.HasMember("reponame") && theme["reponame"].IsString()) - themeEntry.reponame = theme["reponame"].GetString(); + if (theme.HasMember("name") && theme["name"].IsString()) + themeEntry.name = theme["name"].GetString(); - if (theme.HasMember("url") && theme["url"].IsString()) - themeEntry.url = theme["url"].GetString(); + if (theme.HasMember("reponame") && theme["reponame"].IsString()) + themeEntry.reponame = theme["reponame"].GetString(); - if (theme.HasMember("author") && theme["author"].IsString()) - themeEntry.author = theme["author"].GetString(); + if (theme.HasMember("url") && theme["url"].IsString()) + themeEntry.url = theme["url"].GetString(); - if (theme.HasMember("newEntry") && theme["newEntry"].IsBool()) - themeEntry.newEntry = theme["newEntry"].GetBool(); + if (theme.HasMember("author") && theme["author"].IsString()) + themeEntry.author = theme["author"].GetString(); - if (theme.HasMember("variants") && theme["variants"].IsArray()) { - const rapidjson::Value& variants {theme["variants"]}; - for (int i {0}; i < static_cast<int>(variants.Size()); ++i) - themeEntry.variants.emplace_back(variants[i].GetString()); - } + if (theme.HasMember("newEntry") && theme["newEntry"].IsBool()) + themeEntry.newEntry = theme["newEntry"].GetBool(); - if (theme.HasMember("colorSchemes") && theme["colorSchemes"].IsArray()) { - const rapidjson::Value& colorSchemes {theme["colorSchemes"]}; - for (int i {0}; i < static_cast<int>(colorSchemes.Size()); ++i) - themeEntry.colorSchemes.emplace_back(colorSchemes[i].GetString()); - } - - if (theme.HasMember("aspectRatios") && theme["aspectRatios"].IsArray()) { - const rapidjson::Value& aspectRatios {theme["aspectRatios"]}; - for (int i {0}; i < static_cast<int>(aspectRatios.Size()); ++i) - themeEntry.aspectRatios.emplace_back(aspectRatios[i].GetString()); - } - - if (theme.HasMember("fontSizes") && theme["fontSizes"].IsArray()) { - const rapidjson::Value& fontSizes {theme["fontSizes"]}; - for (int i {0}; i < static_cast<int>(fontSizes.Size()); ++i) - themeEntry.fontSizes.emplace_back(fontSizes[i].GetString()); - } - - if (theme.HasMember("transitions") && theme["transitions"].IsArray()) { - const rapidjson::Value& transitions {theme["transitions"]}; - for (int i {0}; i < static_cast<int>(transitions.Size()); ++i) - themeEntry.transitions.emplace_back(transitions[i].GetString()); - } - - if (theme.HasMember("screenshots") && theme["screenshots"].IsArray()) { - const rapidjson::Value& screenshots {theme["screenshots"]}; - for (int i {0}; i < static_cast<int>(screenshots.Size()); ++i) { - Screenshot screenshotEntry; - if (screenshots[i].HasMember("image") && screenshots[i]["image"].IsString()) - screenshotEntry.image = screenshots[i]["image"].GetString(); - - if (screenshots[i].HasMember("caption") && screenshots[i]["caption"].IsString()) - screenshotEntry.caption = screenshots[i]["caption"].GetString(); - - if (screenshotEntry.image != "" && screenshotEntry.caption != "") - themeEntry.screenshots.emplace_back(screenshotEntry); + if (theme.HasMember("variants") && theme["variants"].IsArray()) { + const rapidjson::Value& variants {theme["variants"]}; + for (int i {0}; i < static_cast<int>(variants.Size()); ++i) + themeEntry.variants.emplace_back(variants[i].GetString()); } - } - mThemes.emplace_back(themeEntry); + if (theme.HasMember("colorSchemes") && theme["colorSchemes"].IsArray()) { + const rapidjson::Value& colorSchemes {theme["colorSchemes"]}; + for (int i {0}; i < static_cast<int>(colorSchemes.Size()); ++i) + themeEntry.colorSchemes.emplace_back(colorSchemes[i].GetString()); + } + + if (theme.HasMember("aspectRatios") && theme["aspectRatios"].IsArray()) { + const rapidjson::Value& aspectRatios {theme["aspectRatios"]}; + for (int i {0}; i < static_cast<int>(aspectRatios.Size()); ++i) + themeEntry.aspectRatios.emplace_back(aspectRatios[i].GetString()); + } + + if (theme.HasMember("fontSizes") && theme["fontSizes"].IsArray()) { + const rapidjson::Value& fontSizes {theme["fontSizes"]}; + for (int i {0}; i < static_cast<int>(fontSizes.Size()); ++i) + themeEntry.fontSizes.emplace_back(fontSizes[i].GetString()); + } + + if (theme.HasMember("transitions") && theme["transitions"].IsArray()) { + const rapidjson::Value& transitions {theme["transitions"]}; + for (int i {0}; i < static_cast<int>(transitions.Size()); ++i) + themeEntry.transitions.emplace_back(transitions[i].GetString()); + } + + if (theme.HasMember("screenshots") && theme["screenshots"].IsArray()) { + const rapidjson::Value& screenshots {theme["screenshots"]}; + for (int i {0}; i < static_cast<int>(screenshots.Size()); ++i) { + Screenshot screenshotEntry; + if (screenshots[i].HasMember("image") && screenshots[i]["image"].IsString()) + screenshotEntry.image = screenshots[i]["image"].GetString(); + + if (screenshots[i].HasMember("caption") && + screenshots[i]["caption"].IsString()) + screenshotEntry.caption = screenshots[i]["caption"].GetString(); + + if (screenshotEntry.image != "" && screenshotEntry.caption != "") + themeEntry.screenshots.emplace_back(screenshotEntry); + } + } + + mThemes.emplace_back(themeEntry); + } } } + std::sort(std::begin(mThemes), std::end(mThemes), [](ThemeEntry a, ThemeEntry b) { + if (Utils::String::toUpper(a.name) < Utils::String::toUpper(b.name)) + return true; + else + return false; + }); + LOG(LogDebug) << "GuiThemeDownloader::parseThemesList(): Parsed " << mThemes.size() << " themes"; }