diff --git a/app/src/main/java/net/programmierecke/radiodroid2/FragmentTabs.java b/app/src/main/java/net/programmierecke/radiodroid2/FragmentTabs.java index eb48e3fa..3cb4c6cc 100644 --- a/app/src/main/java/net/programmierecke/radiodroid2/FragmentTabs.java +++ b/app/src/main/java/net/programmierecke/radiodroid2/FragmentTabs.java @@ -114,26 +114,36 @@ public void onPause() { tabLayout.setVisibility(View.GONE); } - private void setupViewPager(ViewPager viewPager) { + private String getCountryCode() { Context ctx = getContext(); String countryCode = null; if (ctx != null) { TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); countryCode = tm.getNetworkCountryIso(); - if (countryCode == null) { - countryCode = tm.getSimCountryIso(); + Log.d("MAIN", "Network country code: '" + countryCode + "'"); + if (countryCode != null && countryCode.length() == 2) { + return countryCode; + } + countryCode = tm.getSimCountryIso(); + Log.d("MAIN", "Sim country code: '" + countryCode + "'"); + if (countryCode != null && countryCode.length() == 2) { + return countryCode; } - if (countryCode != null) { - if (countryCode.length() == 2) { - Log.d("MAIN", "Found countrycode " + countryCode); - addresses[IDX_LOCAL] = "json/stations/bycountrycodeexact/" + countryCode + "?order=clickcount&reverse=true"; - }else{ - Log.e("MAIN", "countrycode length != 2"); - } - }else{ - Log.e("MAIN", "device countrycode and sim countrycode are null"); + String locale = ctx.getResources().getConfiguration().locale.getCountry(); + Log.d("MAIN", "Locale: '" + locale + "'"); + if (countryCode != null && countryCode.length() == 2) { + return countryCode; } } + return null; + } + + private void setupViewPager(ViewPager viewPager) { + String countryCode = getCountryCode(); + if (countryCode != null){ + addresses[IDX_LOCAL] = "json/stations/bycountrycodeexact/" + countryCode + "?order=clickcount&reverse=true"; + } + fragments[IDX_LOCAL] = new FragmentStations(); fragments[IDX_TOP_CLICK] = new FragmentStations(); fragments[IDX_TOP_VOTE] = new FragmentStations();