diff options
author | cyBerta <richy@cyborgsociety.org> | 2013-11-23 16:34:16 +0100 |
---|---|---|
committer | Sean Leonard <meanderingcode@aetherislands.net> | 2013-11-29 19:15:03 -0800 |
commit | e1dd058c2fbf489d97c3d376e89960efaa7b6789 (patch) | |
tree | f03cefaadf9f235e5eca19443a5b8f803bd2c2fc /src | |
parent | ecd01db4ca5c0000d671e888ebdf97c3fdbd51cc (diff) |
url check improved
Diffstat (limited to 'src')
-rw-r--r-- | src/se/leap/bitmaskclient/NewProviderDialog.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/se/leap/bitmaskclient/NewProviderDialog.java b/src/se/leap/bitmaskclient/NewProviderDialog.java index f77cb6d4..a0b8a763 100644 --- a/src/se/leap/bitmaskclient/NewProviderDialog.java +++ b/src/se/leap/bitmaskclient/NewProviderDialog.java @@ -22,6 +22,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -38,7 +39,7 @@ import android.widget.Toast; public class NewProviderDialog extends DialogFragment { final public static String TAG = "newProviderDialog"; - + public interface NewProviderDialogInterface { public void saveAndSelectProvider(String url_provider, boolean danger_on); } @@ -71,13 +72,15 @@ public class NewProviderDialog extends DialogFragment { View new_provider_dialog_view = inflater.inflate(R.layout.new_provider_dialog, null); final EditText url_input_field = (EditText)new_provider_dialog_view.findViewById(R.id.new_provider_url); final CheckBox danger_checkbox = (CheckBox)new_provider_dialog_view.findViewById(R.id.danger_checkbox); - builder.setView(new_provider_dialog_view) .setMessage(R.string.introduce_new_provider) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String entered_url = url_input_field.getText().toString().trim(); if(!entered_url.startsWith("https://")) { + if (entered_url.startsWith("http://")){ + entered_url = entered_url.substring("http://".length()); + } entered_url = "https://".concat(entered_url); } boolean danger_on = danger_checkbox.isChecked(); @@ -86,7 +89,8 @@ public class NewProviderDialog extends DialogFragment { Toast.makeText(getActivity().getApplicationContext(), R.string.valid_url_entered, Toast.LENGTH_LONG).show(); } else { url_input_field.setText(""); - Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show(); + danger_checkbox.setChecked(false); + Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show();; } } }) @@ -105,6 +109,7 @@ public class NewProviderDialog extends DialogFragment { * @return true if it's not empty nor contains only the protocol. */ boolean validURL(String entered_url) { - return !entered_url.isEmpty() && entered_url.matches("http[s]?://.+") && !entered_url.replaceFirst("http[s]?://", "").isEmpty(); + //return !entered_url.isEmpty() && entered_url.matches("http[s]?://.+") && !entered_url.replaceFirst("http[s]?://", "").isEmpty(); + return android.util.Patterns.WEB_URL.matcher(entered_url).matches(); } } |