From c99fcd45bc92012726ab44c53f7793123bef5d2f Mon Sep 17 00:00:00 2001 From: James Fenn <18jafenn90@gmail.com> Date: Fri, 9 Feb 2018 17:16:43 -0500 Subject: [PATCH] updated strings, improved more stuff --- .../adapters/PreferenceSectionAdapter.java | 2 +- .../com/james/status/data/PreferenceData.java | 57 +++++++++++++++++-- .../data/preference/BasePreferenceData.java | 54 ++++++++---------- app/src/main/res/values-ar/strings.xml | 15 +++-- app/src/main/res/values-es/strings.xml | 5 ++ app/src/main/res/values-ko/strings.xml | 5 ++ app/src/main/res/values-zh/strings.xml | 5 ++ app/src/main/res/values/strings.xml | 6 ++ 8 files changed, 108 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/james/status/adapters/PreferenceSectionAdapter.java b/app/src/main/java/com/james/status/adapters/PreferenceSectionAdapter.java index 293210d..f57d198 100644 --- a/app/src/main/java/com/james/status/adapters/PreferenceSectionAdapter.java +++ b/app/src/main/java/com/james/status/adapters/PreferenceSectionAdapter.java @@ -45,7 +45,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, int position) { - holder.title.setText(sections.get(position).name().replace('_', ' ')); + holder.title.setText(sections.get(position).getName(context)); ArrayList items = getItems(sections.get(position)); diff --git a/app/src/main/java/com/james/status/data/PreferenceData.java b/app/src/main/java/com/james/status/data/PreferenceData.java index a441de6..41be915 100644 --- a/app/src/main/java/com/james/status/data/PreferenceData.java +++ b/app/src/main/java/com/james/status/data/PreferenceData.java @@ -97,16 +97,34 @@ else if (defaultStringValue != null) else return TYPE_UNKNOWN; } + public boolean getDefaultBoolean() { + if (getType() == TYPE_BOOLEAN) + return defaultBooleanValue; + else throw new TypeMismatchException(this, TYPE_BOOLEAN); + } + + public int getDefaultInt() { + if (getType() == TYPE_INT) + return defaultIntValue; + else throw new TypeMismatchException(this, TYPE_INT); + } + + public String getDefaultString() { + if (getType() == TYPE_STRING) + return defaultStringValue; + else throw new TypeMismatchException(this, TYPE_STRING); + } + public boolean getBooleanValue(Context context) { - return getBooleanValue(context, defaultBooleanValue); + return getBooleanValue(context, getDefaultBoolean()); } public int getIntValue(Context context) { - return getIntValue(context, defaultIntValue); + return getIntValue(context, getDefaultInt()); } public String getStringValue(Context context) { - return getStringValue(context, defaultStringValue); + return getStringValue(context, getDefaultString()); } public boolean getBooleanValue(Context context, boolean defaultValue) { @@ -149,15 +167,21 @@ public String getStringValue(Context context, @NonNull String defaultValue) { } public void setValue(Context context, boolean value) { - PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(name, value).apply(); + if (getType() == TYPE_BOOLEAN) + PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(name, value).apply(); + else throw new TypeMismatchException(this, TYPE_BOOLEAN); } public void setValue(Context context, int value) { - PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(name, value).apply(); + if (getType() == TYPE_INT) + PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(name, value).apply(); + else throw new TypeMismatchException(this, TYPE_INT); } public void setValue(Context context, String value) { - PreferenceManager.getDefaultSharedPreferences(context).edit().putString(name, value).apply(); + if (getType() == TYPE_STRING) + PreferenceManager.getDefaultSharedPreferences(context).edit().putString(name, value).apply(); + else throw new TypeMismatchException(this, TYPE_STRING); } public static boolean toFile(Context context, File file) { @@ -232,4 +256,25 @@ else if (value instanceof Set) public static String getBackupsDir() { return Environment.getExternalStorageDirectory() + "/status/backups"; } + + public static class TypeMismatchException extends RuntimeException { + + public TypeMismatchException(PreferenceData data, int expectedType) { + super("Wrong type used for \"" + data.name() + "\": expected " + getTypeString(data.getType()) + ", got " + getTypeString(expectedType)); + } + + private static String getTypeString(int type) { + switch (type) { + case TYPE_BOOLEAN: + return "boolean"; + case TYPE_INT: + return "int"; + case TYPE_STRING: + return "string"; + default: + return "unknown"; + } + } + + } } diff --git a/app/src/main/java/com/james/status/data/preference/BasePreferenceData.java b/app/src/main/java/com/james/status/data/preference/BasePreferenceData.java index 7f21a39..9227ae2 100644 --- a/app/src/main/java/com/james/status/data/preference/BasePreferenceData.java +++ b/app/src/main/java/com/james/status/data/preference/BasePreferenceData.java @@ -3,6 +3,7 @@ import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -10,6 +11,7 @@ import android.widget.TextView; import com.james.status.R; +import com.james.status.data.PreferenceData; public class BasePreferenceData implements View.OnClickListener { @@ -85,41 +87,22 @@ public static class Identifier { @Nullable private String title, subtitle; - private com.james.status.data.PreferenceData identifier; + private PreferenceData identifier; private SectionIdentifier sectionIdentifier; public Identifier(@Nullable String title) { this.title = title; } - public Identifier(@Nullable String title, @Nullable String subtitle) { - this.title = title; - this.subtitle = subtitle; - } - - public Identifier(@Nullable String title, SectionIdentifier sectionIdentifier) { - this.title = title; - this.sectionIdentifier = sectionIdentifier; - } - public Identifier(@Nullable String title, @Nullable String subtitle, SectionIdentifier sectionIdentifier) { - this.title = title; - this.subtitle = subtitle; - this.sectionIdentifier = sectionIdentifier; + this(null, title, subtitle, sectionIdentifier); } - public Identifier(com.james.status.data.PreferenceData identifier, @Nullable String title, @Nullable String subtitle) { - this.title = title; - this.subtitle = subtitle; - } - - public Identifier(com.james.status.data.PreferenceData identifier, @Nullable String title, SectionIdentifier sectionIdentifier) { - this.identifier = identifier; - this.title = title; - this.sectionIdentifier = sectionIdentifier; + public Identifier(PreferenceData identifier, @Nullable String title, SectionIdentifier sectionIdentifier) { + this(identifier, title, null, sectionIdentifier); } - public Identifier(com.james.status.data.PreferenceData identifier, @Nullable String title, @Nullable String subtitle, SectionIdentifier sectionIdentifier) { + public Identifier(PreferenceData identifier, @Nullable String title, @Nullable String subtitle, SectionIdentifier sectionIdentifier) { this.identifier = identifier; this.title = title; this.subtitle = subtitle; @@ -139,7 +122,7 @@ public String getSubtitle() { } @Nullable - public com.james.status.data.PreferenceData getPreference() { + public PreferenceData getPreference() { return identifier; } @@ -149,11 +132,22 @@ public SectionIdentifier getSection() { } public enum SectionIdentifier { - COLORS, - ICONS, - ANIMATIONS, - NOTIFICATIONS, - OTHER + COLORS(R.string.section_colors), + ICONS(R.string.section_icons), + ANIMATIONS(R.string.section_animations), + NOTIFICATIONS(R.string.section_notifications), + OTHER(R.string.section_other); + + @StringRes + private int nameRes; + + SectionIdentifier(@StringRes int nameRes) { + this.nameRes = nameRes; + } + + public String getName(Context context) { + return context.getString(nameRes); + } } } } diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index d724f65..b0e3b5f 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1,5 +1,8 @@ + Status + تم التصميم حالة الشريط بتصميم الماتريال. لاحاجة لإستخدام أذن الروت. + الإعدادات التثبيت منح الوصول @@ -55,6 +58,7 @@ قم بتشغيل التبديل إلى جانب \"حالة \". قد تحتاج إلى قم بالتمرير لأسفل … الكثير.. يرجى تشغيل الخدمة بعنوان \"حالة الخدمة \". قد تحتاج إلى التمرير لأسفل حتى تصبح مرئية. يرجى منح إذن الوصول إلى وحدة التخزين الخارجية لاستخدام هذه الوظيفة. + عرض %1$d الشاشات الفردية… حالة الخدمة خدمة الوصول @@ -338,6 +342,8 @@ قام بإنشاء الترجمة الإسبانية لهذا التطبيق. مطور الأندرويد، ترجمة التطبيق إلى الكورية :D قام بإنشاء الترجمة الصينية لهذا التطبيق. + + مروان ال-سيدي ترجمة التطبيق إلى اللغة العربية مصادر أيقونة @@ -381,13 +387,14 @@ Kim Inseop - Marwan ALsidi - Status Icons8 - A material design status bar replacement. No root needed. - Show %1$d individual screens… + Colors + Icons + Animations + Notifications + Other diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index b1fd192..ec7b497 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -374,6 +374,11 @@ GitHub Icons8 Translated the app into Arabic. + Colors + Icons + Animations + Notifications + Other Why can\'t the status bar be transparent? diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index a869a60..ad39e9f 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -394,6 +394,11 @@ Twitter GitHub Icons8 + Colors + Icons + Animations + Notifications + Other Why can\'t the status bar be transparent? diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index e12ca0e..f37f4be 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -390,6 +390,11 @@ GitHub Icons8 Translated the app into Arabic. + Colors + Icons + Animations + Notifications + Other Why can\'t the status bar be transparent? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 19e35d8..afc76b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -87,6 +87,12 @@ Apps Help + Colors + Icons + Animations + Notifications + Other + Show Clock Use 24 Hour Time Format The clock will show in a 24 hour time format if this is turned on.