Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
updated strings, improved more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Feb 9, 2018
1 parent 8659075 commit c99fcd4
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasePreferenceData> items = getItems(sections.get(position));

Expand Down
57 changes: 51 additions & 6 deletions app/src/main/java/com/james/status/data/PreferenceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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;
import android.view.ViewGroup;
import android.widget.TextView;

import com.james.status.R;
import com.james.status.data.PreferenceData;

public class BasePreferenceData<T> implements View.OnClickListener {

Expand Down Expand Up @@ -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;
Expand All @@ -139,7 +122,7 @@ public String getSubtitle() {
}

@Nullable
public com.james.status.data.PreferenceData getPreference() {
public PreferenceData getPreference() {
return identifier;
}

Expand All @@ -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);
}
}
}
}
15 changes: 11 additions & 4 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="app_name">Status</string>
<string name="app_desc">تم التصميم حالة الشريط بتصميم الماتريال. لاحاجة لإستخدام أذن الروت.</string>

<string name="action_settings">الإعدادات</string>
<string name="action_setup">التثبيت</string>
<string name="action_access_grant">منح الوصول</string>
Expand Down Expand Up @@ -55,6 +58,7 @@
<string name="msg_battery_optimizations_switch_enable">قم بتشغيل التبديل إلى جانب \"حالة \". قد تحتاج إلى قم بالتمرير لأسفل … الكثير..</string>
<string name="msg_accessibility_switch_enable">يرجى تشغيل الخدمة بعنوان \"حالة الخدمة \". قد تحتاج إلى التمرير لأسفل حتى تصبح مرئية.</string>
<string name="msg_missing_storage_permission">يرجى منح إذن الوصول إلى وحدة التخزين الخارجية لاستخدام هذه الوظيفة.</string>
<string name="msg_show_individual_screens">عرض %1$d الشاشات الفردية…</string>

<string name="service_name">حالة الخدمة</string>
<string name="service_name_general">خدمة الوصول</string>
Expand Down Expand Up @@ -338,6 +342,8 @@
<string name="ryo_desc">قام بإنشاء الترجمة الإسبانية لهذا التطبيق.</string>
<string name="opnay_desc">مطور الأندرويد، ترجمة التطبيق إلى الكورية :D</string>
<string name="majida_desc">قام بإنشاء الترجمة الصينية لهذا التطبيق.</string>

<string name="alsidi_name">مروان ال-سيدي</string>
<string name="alsidi_desc">ترجمة التطبيق إلى اللغة العربية</string>

<string name="about_icons">مصادر أيقونة</string>
Expand Down Expand Up @@ -381,13 +387,14 @@

<!-- Untranslatable Strings -->
<string name="opnay_name">Kim Inseop</string>
<string name="alsidi_name">Marwan ALsidi</string>

<!-- Untranslated Strings -->
<string name="app_name">Status</string>
<string name="icons8_icons">Icons8</string>
<string name="app_desc">A material design status bar replacement. No root needed.</string>
<string name="msg_show_individual_screens">Show %1$d individual screens…</string>
<string name="section_colors">Colors</string>
<string name="section_icons">Icons</string>
<string name="section_animations">Animations</string>
<string name="section_notifications">Notifications</string>
<string name="section_other">Other</string>

<string-array name="faq">
<item>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@
<string name="action_github">GitHub</string>
<string name="icons8_icons">Icons8</string>
<string name="alsidi_desc">Translated the app into Arabic.</string>
<string name="section_colors">Colors</string>
<string name="section_icons">Icons</string>
<string name="section_animations">Animations</string>
<string name="section_notifications">Notifications</string>
<string name="section_other">Other</string>
<string-array name="faq">
<item>
<b>Why can\'t the status bar be transparent?</b>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<string name="action_twitter">Twitter</string>
<string name="action_github">GitHub</string>
<string name="icons8_icons">Icons8</string>
<string name="section_colors">Colors</string>
<string name="section_icons">Icons</string>
<string name="section_animations">Animations</string>
<string name="section_notifications">Notifications</string>
<string name="section_other">Other</string>
<string-array name="faq">
<item>
<b>Why can\'t the status bar be transparent?</b>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@
<string name="action_github">GitHub</string>
<string name="icons8_icons">Icons8</string>
<string name="alsidi_desc">Translated the app into Arabic.</string>
<string name="section_colors">Colors</string>
<string name="section_icons">Icons</string>
<string name="section_animations">Animations</string>
<string name="section_notifications">Notifications</string>
<string name="section_other">Other</string>
<string-array name="faq">
<item>
<b>Why can\'t the status bar be transparent?</b>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
<string name="tab_apps">Apps</string>
<string name="tab_help">Help</string>

<string name="section_colors">Colors</string>
<string name="section_icons">Icons</string>
<string name="section_animations">Animations</string>
<string name="section_notifications">Notifications</string>
<string name="section_other">Other</string>

<string name="preference_show_clock">Show Clock</string>
<string name="preference_24h">Use 24 Hour Time Format</string>
<string name="preference_24h_desc">The clock will show in a 24 hour time format if this is turned on.</string>
Expand Down

0 comments on commit c99fcd4

Please sign in to comment.