Ads fix for different countries.

This commit is contained in:
Dmitry Yunitsky 2014-08-15 17:58:23 +03:00 committed by Alex Zolotarev
parent 619b3963b7
commit dfc97ca7a9

View file

@ -108,8 +108,8 @@ public class AdsManager
{
final List<MenuAd> ads = new ArrayList<>();
final JSONArray menuItemsJson = adsJson.getJSONObject(ROOT_MENU_ITEMS_KEY).
getJSONObject(DEFAULT_KEY).
final String countryCode = Locale.getDefault().getCountry();
final JSONArray menuItemsJson = getJsonObjectByKeyOrDefault(adsJson.getJSONObject(ROOT_MENU_ITEMS_KEY), countryCode).
getJSONArray(MENU_ITEMS_KEY);
final String localeKey = Locale.getDefault().getLanguage();
@ -137,8 +137,9 @@ public class AdsManager
/**
* Loads and caches ad icon. If internet isnt connected tries to reuse cached icon.
*
* @param urlString url of the icon
* @param adId name of cachefile
* @param adId name of cachefile
* @return
*/
private static Bitmap loadAdIcon(String urlString, String adId)
@ -207,6 +208,15 @@ public class AdsManager
return res;
}
private static JSONObject getJsonObjectByKeyOrDefault(JSONObject json, String key) throws JSONException
{
JSONObject res = json.optJSONObject(key);
if (res == null)
res = json.getJSONObject(DEFAULT_KEY);
return res;
}
private static String getJsonAdsFromServer()
{
BufferedReader reader = null;