diff --git a/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/activities/DeviceSettings.java b/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/activities/DeviceSettings.java index 33b5a35..ee033cc 100644 --- a/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/activities/DeviceSettings.java +++ b/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/activities/DeviceSettings.java @@ -529,14 +529,12 @@ public void afterTextChanged(Editable s) { if (url.split("://").length >= 2) { String nUrl = url.split("://")[1]; if (nUrl.contains(":")) { - Log.e("DS", "PORT D"); b.setEnabled(false); return; } else b.setEnabled(true); } else { if (url.contains(":")) { - Log.e("DS", "PORT D"); b.setEnabled(false); return; } else @@ -640,13 +638,11 @@ public void afterTextChanged(Editable s) { if (url.contains("://") && url.split("://").length >= 2) { String nUrl = url.split("://")[1]; if (nUrl.contains(":")) { - Log.e("DS", "PORT D2"); b.setEnabled(false); } else b.setEnabled(true); } else { if (url.contains(":")) { - Log.e("DS", "PORT D"); b.setEnabled(false); } else b.setEnabled(true); diff --git a/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/setup/activities/SetupStartScreen.java b/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/setup/activities/SetupStartScreen.java index 3c46bfd..af9b7f0 100644 --- a/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/setup/activities/SetupStartScreen.java +++ b/app/src/main/java/com/developerfromjokela/motioneyeclient/ui/setup/activities/SetupStartScreen.java @@ -421,20 +421,13 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { @Override public void afterTextChanged(Editable s) { String url = s.toString(); - if (validIP(url)) { - device.setDeviceUrl(url); - Log.e("SetupStartScreen", "Valid IP"); - continue_btn.setEnabled(true); - } else { - Log.e("SetupStartScreen", "Invalid IP"); + if (!url.contains(":/") && url.contains(":")) { - continue_btn.setEnabled(false); - } - if (url.contains(":")) { final String[] portparts = url.split(":"); if (portparts.length == 2) { + device.setDeviceUrl(portparts[0]); local_port.setText(portparts[portparts.length - 1]); new Handler().postDelayed(new Runnable() { @@ -447,19 +440,41 @@ public void run() { } }, 1000); } - if (validIP(portparts[0])) { - device.setDeviceUrl(url); - Log.e("SetupStartScreen", "Valid IP"); - continue_btn.setEnabled(true); - } else { - Log.e("SetupStartScreen", "Invalid IP"); + } else if (url.contains("://")) { + if (url.split("://").length >= 2) { + String nURL = url.split("://")[1]; + final String[] portparts = nURL.split(":"); + if (portparts.length == 2) { + if (portparts[1].equals("/")) + return; + device.setDeviceUrl(url.split("://")[0] + "://" + portparts[0]); + local_port.setText(portparts[portparts.length - 1]); + String finalUrl = url; + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + local_hostname.setText(finalUrl.split("://")[0] + "://" + portparts[0]); + local_hostname.setSelection(local_hostname.getText().length()); + + Log.e("Setup", "Set Local Port " + portparts[1]); + } + }, 1000); + } + continue_btn.setEnabled(URLUtil.isValidUrl(url)); - continue_btn.setEnabled(false); } - } + + if (!URLUtil.isValidUrl(url)) { + url = "http://" + url; + if (URLUtil.isValidUrl(url)) + device.setDeviceUrl(url); + + continue_btn.setEnabled(URLUtil.isValidUrl(url)); + } else + continue_btn.setEnabled(true); } }); ddns_hostname.addTextChangedListener(new TextWatcher() { @@ -476,40 +491,65 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { @Override public void afterTextChanged(Editable s) { String url = s.toString(); - if (!isValidURL(url) && url.length() > 2) { - if (isValidURL("http://" + url)) { - device.setDdnsURL("http://" + url); - continue_btn.setEnabled(true); + if (!url.contains(":/") && url.contains(":")) { - } else { - continue_btn.setEnabled(false); - - } - } else { - device.setDdnsURL(url); - continue_btn.setEnabled(true); - } - if (url.contains(":")) { final String[] portparts = url.split(":"); - if (portparts.length == 3) { - device.setDdnsURL(url); - - ddns_port.setText(portparts[portparts.length - 1]); + if (portparts.length == 2) { device.setDdnsURL(portparts[0]); - + ddns_port.setText(portparts[portparts.length - 1]); new Handler().postDelayed(new Runnable() { @Override public void run() { ddns_hostname.setText(portparts[0]); ddns_hostname.setSelection(ddns_hostname.getText().length()); + Log.e("Setup", "Set Local Port 1" + portparts[1]); } - }, 900); + }, 1000); + } + + + } else if (url.contains("://")) { + if (url.split("://").length >= 2) { + String nURL = url.split("://")[1]; + final String[] portparts = nURL.split(":"); + if (portparts.length == 2) { + if (portparts[1].equals("/")) + return; + device.setDdnsURL(url.split("://")[0] + "://" + portparts[0]); + ddns_port.setText(portparts[portparts.length - 1]); + String finalUrl = url; + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + ddns_hostname.setText(finalUrl.split("://")[0] + "://" + portparts[0]); + ddns_hostname.setSelection(ddns_hostname.getText().length()); + + Log.e("Setup", "Set Local Port 2" + portparts[1]); + } + }, 1000); + } + continue_btn.setEnabled(URLUtil.isValidUrl(url)); + + } + } + if (!isValidURL(url) && url.length() > 2) { + + if (isValidURL("http://" + url)) { + device.setDdnsURL("http://" + url); + continue_btn.setEnabled(true); + + } else { + continue_btn.setEnabled(false); + } + } else { + device.setDdnsURL(url); + continue_btn.setEnabled(true); } } });