From 5073875f703333f1d807be0add8305fa73135b58 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Tue, 18 Dec 2018 21:07:03 +0100 Subject: [PATCH] - URL validation --- .../schueller/peertube/activity/SettingsActivity.java | 9 +++++++++ app/src/main/res/values/strings.xml | 1 + 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java index 33755b3..f4070fd 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java @@ -10,7 +10,10 @@ import android.preference.Preference; import android.support.v7.app.ActionBar; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; +import android.util.Patterns; import android.view.MenuItem; +import android.widget.Toast; + import net.schueller.peertube.R; import java.util.List; @@ -34,6 +37,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity { private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = (preference, value) -> { String stringValue = value.toString(); + // check URL is valid + if (preference.getKey().equals("pref_api_base") && !Patterns.WEB_URL.matcher(stringValue).matches()) { + Toast.makeText(preference.getContext(), R.string.invalid_url, Toast.LENGTH_LONG).show(); + return false; + } + preference.setSummary(stringValue); return true; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ceebec..9a0fbc8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,5 +59,6 @@ More Share PeerTube + Invalid Url!