Skip to content

Commit

Permalink
simplified port selection (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jul 10, 2020
1 parent f7c2971 commit 325f5dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ private void setOrientationIcon() {
// generate and show new link according to user inputs
private void linkGeneration() {
hostnameIPAddressString = hostnameIPAddress.getText().toString();
portInt = Integer.parseInt(port.getText().toString());

if (!port.getText().toString().isEmpty()) {
editor.putInt("portInt", Integer.parseInt(port.getText().toString()));
} else {
editor.putInt("portInt", 9001);
}

link = "http://" + hostnameIPAddress.getText().toString() + ":" + portInt;
linkView.setText(link);
}
Expand All @@ -201,7 +207,7 @@ private void setConnectButtonClickListener(final View v) {
@Override
public void onClick(View view) {
// if both input fields are not empty
if (!hostnameIPAddress.getText().toString().isEmpty() && !port.getText().toString().isEmpty()) {
if (!hostnameIPAddress.getText().toString().isEmpty()) {
// if connect button was not clicked before
if (linkView.getText().toString().isEmpty()) {
// generate new link
Expand All @@ -227,7 +233,13 @@ public void onClick(View view) {

// store values if user wants to
if (portCheck.isChecked()) {
editor.putInt("portInt", portInt);
// check if user entered hostname
if (!port.getText().toString().isEmpty()) {
editor.putInt("portInt", portInt);
} else {
port.setText(String.valueOf(9001));
editor.putInt("portInt", 9001);
}
editor.putBoolean("portCheck", true).apply();
} else {
editor.putInt("portInt", 0);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<string name="app_name" translatable="false">LogViewer for openHAB</string>

<string name="error_fill_out">Fill out both</string>
<string name="error_fill_out">Fill out the hostname</string>
<string name="connecting">Connecting…</string>
<string name="lock_button_1">View Lock deactivated</string>
<string name="lock_button_2">View Lock activated</string>
Expand Down Expand Up @@ -76,7 +76,7 @@
<string name="hostname_ipaddress_view">Hostname / IP address</string>
<string name="hostname_ipaddress">e.g. 192.168.178.10</string>
<string name="port_view">Port</string>
<string name="port">default is 9001</string>
<string name="port">leave empty for 9001</string>
<string name="checks">Remember\ninput</string>
<string name="connect_button_1">Check</string>
<string name="connect_button_2">Connect</string>
Expand Down

0 comments on commit 325f5dd

Please sign in to comment.