Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ Please preserve the xml tags and the utf8 encoding.
<string name="radio_stream_require_wifi">WLAN Verbindung benötigt</string>
<string name="radio_stream_require_wifi_desc">Falls aktiviert, wird der Radiowecker nur mit einer WLAN-Verbindung gestartet.</string>
<string name="radio_stream_search">Suchen</string>
<string name="radio_stream_unreachable_server">Der Server ist nicht erreichbar.</string>
<string name="radio_stream_unreachable_url">Der Sender ist nicht erreichbar.</string>
<string name="rate">Bewertung abgeben</string>
<string name="rate_summary">Über eine Bewertung der App würden wir uns freuen.</string>
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ OR
<string name="radio_stream_require_wifi">require WiFi connection</string>
<string name="radio_stream_require_wifi_desc">If on, alarms will play web radio streams only with an established WiFi connection.</string>
<string name="radio_stream_search">Search</string>
<string name="radio_stream_unreachable_server">The Server is not reachable.</string>
<string name="radio_stream_unreachable_url">The URL is not reachable.</string>
<string name="reactivate_on_ambient_light_value">Illuminance threshold</string>
<string name="reactivate_on_ambient_light_value_summary">The screen is reactivated if the threshold value of illuminance is exceeded.</string>
Expand Down
15 changes: 15 additions & 0 deletions src/com/firebirdberlin/nightdream/ui/RadioStreamDialog.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.firebirdberlin.nightdream.ui;


import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
Expand All @@ -19,6 +21,7 @@
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.widget.ContentLoadingProgressBar;

Expand All @@ -28,6 +31,7 @@
import com.firebirdberlin.radiostreamapi.StationRequestTask;
import com.firebirdberlin.radiostreamapi.models.Country;
import com.firebirdberlin.radiostreamapi.models.RadioStation;
import com.google.android.material.snackbar.Snackbar;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -196,6 +200,7 @@ public void onRequestFinished(List<RadioStation> stations) {

@Override
public void onCountryRequestFinished(List<Country> countries) {
Log.d(TAG,"onCountryRequestFinished()");
// sort countries alphabetically
Collections.sort(countries, (lhs, rhs) -> {
if (lhs.name == null) {
Expand All @@ -207,6 +212,16 @@ public void onCountryRequestFinished(List<Country> countries) {
return lhs.name.compareTo(rhs.name);
});

if (countries.size() == 0) {
Activity activity = (Activity) ((ContextWrapper) context).getBaseContext();
Snackbar snackbarCountriesError = Snackbar
.make((View) activity.findViewById(android.R.id.content), R.string.radio_stream_unreachable_server, Snackbar.LENGTH_LONG);
snackbarCountriesError.setTextColor(context.getResources().getColor(R.color.material_red));
snackbarCountriesError.show();

//Toast.makeText(context, R.string.radio_stream_unreachable_server, Toast.LENGTH_LONG).show();
}

updateCountryNameToCodeMap(countries);
updateCountrySpinner(countries, preferredCountry);
}
Expand Down
11 changes: 10 additions & 1 deletion src/com/firebirdberlin/radiostreamapi/RadioBrowserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public class RadioBrowserApi {
private static int CONNECT_TIMEOUT = 10000;

private static String getRandomServer() {
Log.d(TAG, "getRandomServer()");
List<String> servers = new ArrayList<>();

try {
// add all round robin servers one by one to select them separately
InetAddress[] list = InetAddress.getAllByName("all.api.radio-browser.info");
Expand All @@ -51,7 +53,13 @@ private static String getRandomServer() {
} catch (UnknownHostException e) {
e.printStackTrace();
}
return servers.get(new Random().nextInt(servers.size()));

if (servers.size() > 0) {
return servers.get(new Random().nextInt(servers.size()));
}
else {
return "";
}
}

public static List<RadioStation> fetchStations(String queryString, String countryCode) {
Expand Down Expand Up @@ -144,6 +152,7 @@ private static String getCountriesPath() {
}

private static Uri.Builder getPathBuilder(String endpoint) {
Log.d(TAG, "getPathBuilder()");
String server = getRandomServer();
Log.d(TAG, server);
return Uri.parse("https://" + server).buildUpon()
Expand Down