Created
September 30, 2018 06:33
-
-
Save vishvendra01/82d3d06253624da9fc958e46f5c724fb to your computer and use it in GitHub Desktop.
A helper class to show strings from strings.xml in presenters which can be mocked later in tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class StringHelper { | |
private Context mContext; | |
@SuppressLint("StaticFieldLeak") | |
private static StringHelper sInstance; | |
private StringHelper(Context context) { | |
this.mContext = context; | |
} | |
public static void init(Context context) { | |
if (sInstance == null) { | |
sInstance = new StringHelper(context.getApplicationContext()); | |
} | |
} | |
public static StringHelper getInstance() { | |
if (sInstance == null) { | |
throw new IllegalStateException("Initialize instance before getting instance"); | |
} | |
return sInstance; | |
} | |
public String getString(@StringRes int value) { | |
return mContext.getString(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment