--- /dev/null
+package com.folioreader;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import org.json.JSONObject;
+
+/**
+ * Created by mahavir on 4/12/16.
+ */
+public class Config implements Parcelable {
+ public static final String INTENT_CONFIG = "config";
+ public static final String CONFIG_FONT = "font";
+ public static final String CONFIG_FONT_SIZE = "font_size";
+ public static final String CONFIG_MARGIN_SIZE = "margin_size";
+ public static final String CONFIG_INTERLINE_SIZE = "interline_size";
+ public static final String CONFIG_IS_NIGHTMODE = "is_night_mode";
+ public static final String CONFIG_THEMECOLOR = "theme_color";
+ public static final String CONFIG_ICON_COLOR = "icon_color";
+ public static final String CONFIG_TOOLBAR_COLOR = "toolbar_color";
+ public static final String CONFIG_IS_TTS = "is_tts";
+ public static final String INTENT_PORT = "port";
+ private int font;
+ private int fontSize;
+ private int marginSize;
+ private int interlineSize;
+ private boolean nightMode;
+ private int themeColor;
+ private int iconColor;
+ private int toolbarColor;
+ private boolean showTts;
+
+ // public Config(int font, int fontSize, boolean nightMode, int themeColor, int iconColor, int toolbarColor, boolean showTts) {
+ // this.font = font;
+ // this.fontSize = fontSize;
+ // this.nightMode = nightMode;
+ // this.themeColor = themeColor;
+ // this.iconColor = iconColor;
+ // this.toolbarColor = toolbarColor;
+ // this.showTts = showTts;
+ // }
+
+ private Config(ConfigBuilder configBuilder) {
+ font = configBuilder.mFont;
+ fontSize = configBuilder.mFontSize;
+ marginSize = configBuilder.mMarginSize;
+ interlineSize = configBuilder.mInterlineSize;
+ nightMode = configBuilder.mNightMode;
+ themeColor = configBuilder.mThemeColor;
+ iconColor = configBuilder.iconColor;
+ toolbarColor = configBuilder.toolbarColor;
+ showTts = configBuilder.mShowTts;
+ }
+
+ public Config(JSONObject jsonObject) {
+ font = jsonObject.optInt(CONFIG_FONT);
+ fontSize = jsonObject.optInt(CONFIG_FONT_SIZE);
+ marginSize = jsonObject.optInt(CONFIG_MARGIN_SIZE);
+ interlineSize = jsonObject.optInt(CONFIG_INTERLINE_SIZE);
+ nightMode = jsonObject.optBoolean(CONFIG_IS_NIGHTMODE);
+ themeColor = jsonObject.optInt(CONFIG_THEMECOLOR);
+ iconColor = jsonObject.optInt(CONFIG_ICON_COLOR);
+ toolbarColor = jsonObject.optInt(CONFIG_TOOLBAR_COLOR);
+ showTts = jsonObject.optBoolean(CONFIG_IS_TTS);
+ }
+
+ private Config() {
+ fontSize = 2;
+ marginSize = 1;
+ interlineSize = 1;
+ font = 3;
+ nightMode = false;
+ themeColor = R.color.app_green;
+ showTts = true;
+ }
+
+ private Config(Parcel in) {
+ readFromParcel(in);
+ }
+
+
+ public int getFont() {
+ return font;
+ }
+
+ public void setFont(int font) {
+ this.font = font;
+ }
+
+ public int getFontSize() {
+ return fontSize;
+ }
+
+ public void setFontSize(int fontSize) {
+ this.fontSize = fontSize;
+ }
+
+ public int getMarginSize() {
+ return marginSize;
+ }
+
+ public void setMarginSize(int marginSize) {
+ this.marginSize = marginSize;
+ }
+
+ public int getInterlineSize() {
+ return interlineSize;
+ }
+
+ public void setInterlineSize(int interlineSize) {
+ this.interlineSize = interlineSize;
+ }
+
+ public boolean isNightMode() {
+ return nightMode;
+ }
+
+ public void setNightMode(boolean nightMode) {
+ this.nightMode = nightMode;
+ }
+
+
+ public int getThemeColor() {
+ return themeColor;
+ }
+
+ public void setThemeColor(int themeColor) {
+ this.themeColor = themeColor;
+ }
+
+ public boolean isShowTts() {
+ return showTts;
+ }
+
+ public void setShowTts(boolean showTts) {
+ this.showTts = showTts;
+ }
+
+ public int getIconColor() {
+ return iconColor;
+ }
+
+ public int getToolbarColor() {
+ return toolbarColor;
+ }
+
+ @Override
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Config)) {
+ return false;
+ }
+
+ Config config = (Config) o;
+
+ return font == config.font && fontSize == config.fontSize && marginSize == config.marginSize && interlineSize == config.interlineSize && nightMode == config.nightMode &&
+ toolbarColor == config.toolbarColor && iconColor == config.iconColor;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = font;
+ result = 31 * result + fontSize;
+ result = 31 * result + marginSize;
+ result = 31 * result + interlineSize;
+ result = 31 * result + (nightMode ? 1 : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "Config{"
+ + "font=" + font
+ + ", fontSize=" + fontSize
+ + ", marginSize=" + marginSize
+ + ", interlineSize=" + interlineSize
+ + ", nightMode=" + nightMode
+ + '}';
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(font);
+ dest.writeInt(fontSize);
+ dest.writeInt(marginSize);
+ dest.writeInt(interlineSize);
+ dest.writeInt(nightMode ? 1 : 0);
+ dest.writeInt(themeColor);
+ dest.writeInt(showTts ? 1 : 0);
+ dest.writeInt(toolbarColor);
+ dest.writeInt(iconColor);
+ }
+
+ private void readFromParcel(Parcel in) {
+ font = in.readInt();
+ fontSize = in.readInt();
+ marginSize = in.readInt();
+ interlineSize = in.readInt();
+ nightMode = in.readInt() == 1;
+ themeColor = in.readInt();
+ showTts = in.readInt() == 1;
+ toolbarColor = in.readInt();
+ iconColor = in.readInt();
+ }
+
+ public static final Creator<Config> CREATOR = new Creator<Config>() {
+ @Override
+ public Config createFromParcel(Parcel in) {
+ return new Config(in);
+ }
+
+ @Override
+ public Config[] newArray(int size) {
+ return new Config[size];
+ }
+ };
+
+ public static class ConfigBuilder {
+ private int mFont = 3;
+ private int mFontSize = 2;
+ private int mMarginSize = 1;
+ private int mInterlineSize = 1;
+ private boolean mNightMode = false;
+ private int mThemeColor = R.color.settings_icons;
+ private boolean mShowTts = true;
+ private int iconColor = R.color.toolbar_icons;
+ private int toolbarColor = R.color.toolbar_background;
+
+ public ConfigBuilder font(int font) {
+ mFont = font;
+ return this;
+ }
+
+ public ConfigBuilder fontSize(int fontSize) {
+ mFontSize = fontSize;
+ return this;
+ }
+
+ public ConfigBuilder marginSize(int marginSize) {
+ mMarginSize = marginSize;
+ return this;
+ }
+
+ public ConfigBuilder interlineSize(int interlineSize) {
+ mInterlineSize = interlineSize;
+ return this;
+ }
+
+ public ConfigBuilder nightmode(boolean nightMode) {
+ mNightMode = nightMode;
+ return this;
+ }
+
+ public ConfigBuilder themeColor(int themeColor) {
+ mThemeColor = themeColor;
+ return this;
+ }
+
+ public ConfigBuilder setShowTts(boolean showTts) {
+ mShowTts = showTts;
+ return this;
+ }
+
+
+ public Config build() {
+ return new Config(this);
+ }
+ }
+}
+
+