- Prevent fatal when server URL is invalid
This commit is contained in:
parent
7120a36091
commit
57c3079c68
|
@ -3,6 +3,7 @@ package net.schueller.peertube.helper;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
import net.schueller.peertube.R;
|
import net.schueller.peertube.R;
|
||||||
|
|
||||||
|
@ -10,7 +11,13 @@ public class APIUrlHelper{
|
||||||
|
|
||||||
public static String getUrl(Context context) {
|
public static String getUrl(Context context) {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
return sharedPref.getString("pref_api_base", context.getResources().getString(R.string.pref_default_api_base_url));
|
|
||||||
|
// validate URL is valid
|
||||||
|
String URL = sharedPref.getString("pref_api_base", context.getResources().getString(R.string.pref_default_api_base_url));
|
||||||
|
if (!URLUtil.isValidUrl(URL)) {
|
||||||
|
return "http://invalid";
|
||||||
|
}
|
||||||
|
return URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUrlWithVersion(Context context) {
|
public static String getUrlWithVersion(Context context) {
|
||||||
|
|
Loading…
Reference in New Issue