Optimized Theme value replacement

This commit is contained in:
Rsl1122 2019-08-30 14:28:58 +03:00
parent 0650f3e338
commit 074289c239
9 changed files with 43 additions and 41 deletions

View File

@ -27,14 +27,16 @@ import java.io.IOException;
*/
public class RedirectResponse extends Response {
private String direct;
public RedirectResponse(String direct) {
super.setHeader("HTTP/1.1 302 Found");
super.setContent(direct);
this.direct = direct;
}
@Override
public void send(HttpExchange exchange, Locale locale, Theme theme) throws IOException {
responseHeaders.set("Location", getContent());
responseHeaders.set("Location", direct);
super.send(exchange, locale, theme);
}
}

View File

@ -21,11 +21,13 @@ import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.storage.file.PlanFiles;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.djrapitops.plan.system.settings.theme.ThemeVal.*;
@ -92,33 +94,31 @@ public class Theme implements SubSystem {
}
public String replaceThemeColors(String resourceString) {
String replaced = resourceString;
ThemeVal[] themeVariables = new ThemeVal[]{
return replaceVariables(resourceString,
RED, PINK, PURPLE,
DEEP_PURPLE, INDIGO, BLUE, LIGHT_BLUE, CYAN, TEAL, GREEN, LIGHT_GREEN, LIME,
YELLOW, AMBER, ORANGE, DEEP_ORANGE, BROWN, GREY, BLUE_GREY, BLACK, WHITE,
GRAPH_PUNCHCARD, GRAPH_PLAYERS_ONLINE, GRAPH_TPS_HIGH, GRAPH_TPS_MED, GRAPH_TPS_LOW,
GRAPH_CPU, GRAPH_RAM, GRAPH_CHUNKS, GRAPH_ENTITIES, GRAPH_WORLD_PIE, GRAPH_GM_PIE,
GRAPH_ACTIVITY_PIE, GRAPH_SERVER_PREF_PIE, FONT_STYLESHEET, FONT_FAMILY
};
GRAPH_CPU, GRAPH_RAM, GRAPH_CHUNKS, GRAPH_ENTITIES, GRAPH_WORLD_PIE, FONT_STYLESHEET, FONT_FAMILY
);
}
private String replaceVariables(String resourceString, ThemeVal... themeVariables) {
List<String> replace = new ArrayList<>();
List<String> with = new ArrayList<>();
for (ThemeVal variable : themeVariables) {
String value = getColor(variable);
String defaultValue = variable.getDefaultValue();
if (Verify.equalsOne(value, defaultValue)) {
if (defaultValue.equals(value)) {
continue;
}
if (value.contains("url")) {
String[] colorAndUrl = value.split(" ");
if (colorAndUrl.length >= 2) {
replaced = replaced.replace("background: " + defaultValue, "background: " + colorAndUrl[1]);
replaced = replaced.replace(defaultValue, colorAndUrl[0]);
return replaced;
replace.add(defaultValue);
with.add(value);
}
} else {
replaced = replaced.replace(defaultValue, value);
}
}
return replaced.replace("${defaultTheme}", getValue(ThemeVal.THEME_DEFAULT));
replace.add("${defaultTheme}");
with.add(getValue(ThemeVal.THEME_DEFAULT));
return StringUtils.replaceEach(resourceString, replace.toArray(new String[0]), with.toArray(new String[0]));
}
private String getThemeValue(ThemeVal color) {

View File

@ -23,10 +23,10 @@ package com.djrapitops.plan.system.settings.theme;
*/
public enum ThemeVal {
THEME_DEFAULT("DefaultColor", "light-green"),
THEME_DEFAULT("DefaultColor", "plan"),
FONT_STYLESHEET("Font.FontStyleSheet", "https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext"),
FONT_FAMILY("Font.FontFamily", "\"Roboto\", sans-serif"),
FONT_STYLESHEET("Font.FontStyleSheet", "https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext"),
FONT_FAMILY("Font.FontFamily", "\"Nunito\""),
RED("Colors.red", "#E91E63"),
PINK("Colors.pink", "#F44336"),

View File

@ -1,11 +1,11 @@
# Default Theme bar color when user has not chosen a color
DefaultColor: "teal"
DefaultColor: "plan"
Font:
# Location of the FontStyleSheet, eg. https://fonts.googleapis.com/css?family=Quicksand:300,400
FontStyleSheet: https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext
FontStyleSheet: https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext
# Name of the Font for CSS eg "'Quicksand', sans-serif"
FontFamily: '"Roboto", sans-serif'
FontFamily: '"Nunito"'
# Color codes for each theme element color
# These affect icons & backgrounds of all elements of this color.

View File

@ -1,11 +1,11 @@
# Default Theme bar color when user has not chosen a color
DefaultColor: "green"
DefaultColor: "plan"
Font:
# Location of the FontStyleSheet, eg. https://fonts.googleapis.com/css?family=Quicksand:300,400
FontStyleSheet: https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext
FontStyleSheet: https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext
# Name of the Font for CSS eg "'Quicksand', sans-serif"
FontFamily: '"Roboto", sans-serif'
FontFamily: '"Nunito"'
# Color codes for each theme element color
# These affect icons & backgrounds of all elements of this color.

View File

@ -1,11 +1,11 @@
# Default Theme bar color when user has not chosen a color
DefaultColor: "indigo"
DefaultColor: "plan"
Font:
# Location of the FontStyleSheet, eg. https://fonts.googleapis.com/css?family=Quicksand:300,400
FontStyleSheet: https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext
FontStyleSheet: https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext
# Name of the Font for CSS eg "'Quicksand', sans-serif"
FontFamily: '"Roboto", sans-serif'
FontFamily: '"Nunito"'
# Color codes for each theme element color
# These affect icons & backgrounds of all elements of this color.

View File

@ -1,11 +1,11 @@
# Default Theme bar color when user has not chosen a color
DefaultColor: "brown"
DefaultColor: "plan"
Font:
# Location of the FontStyleSheet, eg. https://fonts.googleapis.com/css?family=Quicksand:300,400
FontStyleSheet: https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext
FontStyleSheet: https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext
# Name of the Font for CSS eg "'Quicksand', sans-serif"
FontFamily: '"Roboto", sans-serif'
FontFamily: '"Nunito"'
# Color codes for each theme element color
# These affect icons & backgrounds of all elements of this color.

View File

@ -1,11 +1,11 @@
# Default Theme bar color when user has not chosen a color
DefaultColor: "light-green"
DefaultColor: "plan"
Font:
# Location of the FontStyleSheet, eg. https://fonts.googleapis.com/css?family=Quicksand:300,400
FontStyleSheet: https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext
FontStyleSheet: https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext
# Name of the Font for CSS eg "'Quicksand', sans-serif"
FontFamily: '"Roboto", sans-serif'
FontFamily: '"Nunito"'
# Color codes for each theme element color
# These affect icons & backgrounds of all elements of this color.

View File

@ -1,11 +1,11 @@
# Default Theme bar color when user has not chosen a color
DefaultColor: "light-green"
DefaultColor: "plan"
Font:
# Location of the FontStyleSheet, eg. https://fonts.googleapis.com/css?family=Quicksand:300,400
FontStyleSheet: https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext
FontStyleSheet: https://fonts.googleapis.com/css?family=Nunito:400,700,800,900&display=swap&subset=latin-ext
# Name of the Font for CSS eg "'Quicksand', sans-serif"
FontFamily: '"Roboto", sans-serif'
FontFamily: '"Nunito"'
# Color codes for each theme element color
# These affect icons & backgrounds of all elements of this color.