Skip to content
Snippets Groups Projects
Commit 5552afdf authored by Julian Catoni's avatar Julian Catoni
Browse files

Added url validity check

parent cfe2d160
Branches
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
......@@ -44,6 +45,8 @@ import org.openhab.habdroid.util.CacheManager;
import org.openhab.habdroid.util.Constants;
import org.openhab.habdroid.util.Util;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.BitSet;
import static org.openhab.habdroid.util.Util.getHostFromUrl;
......@@ -248,11 +251,14 @@ public class PreferencesActivity extends AppCompatActivity {
R.string.settings_current_default_sitemap, currentDefaultSitemapLabel));
}
openLichtUrl.setOnPreferenceChangeListener((preference, newValue) -> {
if (!newValue.toString().isEmpty()) {
try {
new URL(newValue.toString()).toURI();
preference.setSummary(newValue.toString());
return true;
}
} catch (Exception e) {
Toast.makeText(this.getActivity(), "URL not valid. Don't forget to add http(s):// at the beginning!", Toast.LENGTH_LONG).show();
return false;
}
});
updateOpenLichtUrlPreference(openLichtUrl);
updateConnectionSummary(Constants.SUBSCREEN_LOCAL_CONNECTION,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment