diff --git a/Android/.idea/caches/gradle_models.ser b/Android/.idea/caches/gradle_models.ser index 081d69d..8269fec 100644 Binary files a/Android/.idea/caches/gradle_models.ser and b/Android/.idea/caches/gradle_models.ser differ diff --git a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/AddCustomTask.java b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/AddCustomTask.java index 4cb788a..fb346d8 100644 --- a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/AddCustomTask.java +++ b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/AddCustomTask.java @@ -213,7 +213,7 @@ else if(CertainRGCustom.isChecked()) { amount = Integer.parseInt(CertainCustomAmount.getText().toString()); } catch (Exception e) { - Toast.makeText(AddCustomTask.this, "Custom time value cannot be empty!", Toast.LENGTH_LONG); + e.printStackTrace(); } int index = CustomUnitspinner.getSelectedItemPosition(); switch(index) { diff --git a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/SocketCommunicator.java b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/SocketCommunicator.java index 371e762..45b16ba 100644 --- a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/SocketCommunicator.java +++ b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/SocketCommunicator.java @@ -1,6 +1,5 @@ package dev.kamilklecha.autoswitchmobile; -import android.os.AsyncTask; import android.os.Handler; import android.os.NetworkOnMainThreadException; import android.util.Log; @@ -10,10 +9,12 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; -import java.io.Serializable; +import java.net.InetSocketAddress; import java.net.Socket; +import java.net.SocketException; +import java.net.SocketTimeoutException; -public class SocketCommunicator implements Serializable { +public class SocketCommunicator { private static final String TAG = "SocketCommunicator"; public Socket socket; @@ -22,42 +23,30 @@ public class SocketCommunicator implements Serializable { private PrintWriter output; final Handler handler = new Handler(); + ConnectWait cw; + public SocketCommunicator(final String SERVER_IP, final ConnectWait cw) { + this.cw = cw; Thread thread = new Thread(new Runnable() { @Override public void run() { try { - socket = new Socket(SERVER_IP, 1234); + InetSocketAddress sockAdr = new InetSocketAddress(SERVER_IP, 1234); + int timeout = 10000; + socket = new Socket(); + socket.connect(sockAdr, timeout); + out = socket.getOutputStream(); output = new PrintWriter(out); - startReceiver(); - - AsyncTask.execute(new Runnable() { - @Override - public void run() { - int i = 0; - if(socket.isConnected()) { - cw.connected(); - } else { - if(i == 20) { - cw.finish(); - } - i++; - try { - i++; - Thread.sleep(250); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - }); - - } catch (IOException e) { + cw.connected(); + } + catch(SocketTimeoutException e) { + //TODO info + Log.e(TAG, "SocketCommunicator: SocketTimeOutException"); e.printStackTrace(); - } catch (Exception e) { + cw.finish(); + } catch (IOException e) { e.printStackTrace(); } } @@ -81,7 +70,7 @@ public void run() { } public void startReceiver() { - final Thread thread = new Thread(new Runnable() { + Thread thread = new Thread(new Runnable() { @Override public void run() { boolean exception = false; @@ -104,6 +93,9 @@ public void run() { // tv.setText("From Server: " + st); } }); + } catch (SocketException e) { + //TODO info + cw.finish(); } catch (IOException e) { e.printStackTrace(); exception = true; @@ -111,7 +103,7 @@ public void run() { Log.e(TAG, "startReceiver: NetworkOnMainThreadException"); e.printStackTrace(); exception = true; - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); exception = true; } diff --git a/Android/app/src/main/res/layout/content_main.xml b/Android/app/src/main/res/layout/content_main.xml index 98a179d..7ecb7e1 100644 --- a/Android/app/src/main/res/layout/content_main.xml +++ b/Android/app/src/main/res/layout/content_main.xml @@ -172,6 +172,7 @@ android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" + android:saveEnabled="false" android:text="@string/home_next_screen" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"