Skip to content

Commit

Permalink
fallback to locale for countrycode if sim not available
Browse files Browse the repository at this point in the history
  • Loading branch information
segler-alex committed Sep 28, 2023
1 parent bafa5f3 commit d6f527a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions app/src/main/java/net/programmierecke/radiodroid2/FragmentTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d6f527a

Please sign in to comment.