forked from organicmaps/organicmaps
[android] Added getting the translated string for rating names
This commit is contained in:
parent
b13b6f50bf
commit
428bfc3556
3 changed files with 38 additions and 5 deletions
|
@ -69,10 +69,10 @@ public class UGC
|
|||
{
|
||||
return new ArrayList<Rating>(){
|
||||
{
|
||||
add(new Rating("service", 3.3f));
|
||||
add(new Rating("food", 4.4f));
|
||||
add(new Rating("quality", 2.0f));
|
||||
add(new Rating("cleaning", 3.9f));
|
||||
add(new Rating("cuisine", 3.3f));
|
||||
add(new Rating("service", 4.4f));
|
||||
add(new Rating("atmosphere", 2.0f));
|
||||
add(new Rating("experience", 3.9f));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.ugc;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -9,6 +10,7 @@ import android.widget.RatingBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -79,7 +81,10 @@ class UGCRatingAdapter extends RecyclerView.Adapter<UGCRatingAdapter.ViewHolder>
|
|||
|
||||
public void bind(UGC.Rating rating)
|
||||
{
|
||||
mName.setText(rating.getName());
|
||||
@StringRes
|
||||
int nameId = Utils.getStringIdByKey(mName.getContext(), rating.getName());
|
||||
if (nameId != Utils.INVALID_ID)
|
||||
mName.setText(nameId);
|
||||
mBar.setRating(rating.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.DimenRes;
|
||||
|
@ -22,6 +23,7 @@ import android.text.SpannableStringBuilder;
|
|||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.AbsoluteSizeSpan;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -46,6 +48,8 @@ import java.util.Map;
|
|||
|
||||
public class Utils
|
||||
{
|
||||
@StringRes
|
||||
public static final int INVALID_ID = 0;
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
private static final String TAG = "Utils";
|
||||
|
||||
|
@ -425,6 +429,30 @@ public class Utils
|
|||
return text;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public static int getStringIdByKey(@NonNull Context context, @NonNull String key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Resources res = context.getResources();
|
||||
@StringRes
|
||||
int nameId = res.getIdentifier(key, "string", context.getPackageName());
|
||||
if (nameId == INVALID_ID || nameId == View.NO_ID)
|
||||
throw new Resources.NotFoundException("String id '" + key + "' is not found");
|
||||
return nameId;
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
LOGGER.e(TAG, "Failed to get string with id '" + key + "'", e);
|
||||
if (BuildConfig.BUILD_TYPE.equals("debug") || BuildConfig.BUILD_TYPE.equals("beta"))
|
||||
{
|
||||
Toast.makeText(context, "Add string id for '" + key + "'!",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
return INVALID_ID;
|
||||
}
|
||||
|
||||
private static class OnZipCompletedCallback implements LoggerFactory.OnZipCompletedListener
|
||||
{
|
||||
@NonNull
|
||||
|
|
Loading…
Add table
Reference in a new issue