forked from organicmaps/organicmaps
[android] Added safe getting the string for whats new title
This commit is contained in:
parent
27d20e2633
commit
2374f66c9b
2 changed files with 24 additions and 6 deletions
|
@ -8,7 +8,6 @@ import android.support.annotation.ArrayRes;
|
|||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
@ -107,11 +106,8 @@ public abstract class BaseNewsFragment extends BaseMwmDialogFragment
|
|||
|
||||
String[] titles = new String[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
@StringRes
|
||||
int id = res.getIdentifier(keys[i], "string", getContext().getPackageName());
|
||||
titles[i] = res.getString(id);
|
||||
}
|
||||
titles[i] = Utils.getStringValueByKey(getContext(), keys[i]);
|
||||
|
||||
return titles;
|
||||
}
|
||||
|
||||
|
|
|
@ -468,6 +468,28 @@ public class Utils
|
|||
return INVALID_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string value for the specified key. If the value is not found then its key will be
|
||||
* returned.
|
||||
*
|
||||
* @return string value or its key if there is no string for the specified key.
|
||||
*/
|
||||
@NonNull
|
||||
public static String getStringValueByKey(@NonNull Context context, @NonNull String key)
|
||||
{
|
||||
@StringRes
|
||||
int id = getStringIdByKey(context, key);
|
||||
try
|
||||
{
|
||||
return context.getString(id);
|
||||
}
|
||||
catch (Resources.NotFoundException e)
|
||||
{
|
||||
LOGGER.e(TAG, "Failed to get value for string '" + key + "'", e);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getDeviceName()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue