From a860c5c65c9397d6657d76c1e481aacc9d663098 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Jun 2019 17:32:00 +0200 Subject: [PATCH] Added saving pc settings --- .../autoswitchmobile/AddCustomTask.java | 2 + .../autoswitchmobile/PCSettings.java | 53 +++++++++++++++++-- .../kamilklecha/autoswitchmobile/Packet.java | 15 +++++- 3 files changed, 66 insertions(+), 4 deletions(-) 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 fb346d8..2c4b939 100644 --- a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/AddCustomTask.java +++ b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/AddCustomTask.java @@ -238,12 +238,14 @@ else if(CertainRGCustom.isChecked()) { else if(!err) Toast.makeText(AddCustomTask.this, "Selected value must NOT be 0!", Toast.LENGTH_LONG).show(); } else if(MainRadioTime.isChecked()) { + p.dt = Calendar.getInstance(); p.dt.set(1900,1,1, hourT, minuteT); Hub.cui.sendMsg(p); Toast.makeText(AddCustomTask.this, "Task added", Toast.LENGTH_LONG).show(); finish(); } else if(MainRadioDateTime.isChecked()) { + p.dt = Calendar.getInstance(); p.dt.set(yearDT, monthDT, dayDT, hourDT, minuteDT); Hub.cui.sendMsg(p); Toast.makeText(AddCustomTask.this, "Task added", Toast.LENGTH_LONG).show(); diff --git a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/PCSettings.java b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/PCSettings.java index 9f6c478..abb6000 100644 --- a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/PCSettings.java +++ b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/PCSettings.java @@ -43,7 +43,7 @@ public void setJson(String json) { String json = ""; @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pcsettings); @@ -62,6 +62,17 @@ protected void onCreate(Bundle savedInstanceState) { btnSave = (Button) findViewById(R.id.PCSettings_SaveSettings); btnCancel = (Button) findViewById(R.id.PCSettings_Cancel); + btnSave.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + saveSettings(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -86,7 +97,6 @@ void getSettings() throws InterruptedException { Packet p = new Packet(); p.Exec = "GetSettings"; Hub.cui.sendMsg(p); - final Handler handler = new Handler(Looper.getMainLooper()); Thread thread = new Thread(new Runnable() { @Override @@ -104,8 +114,45 @@ public void run() { thread.join(); } - void saveSettings() { + void saveSettings() throws InterruptedException { + Packet p = new Packet(); + p.Exec = "SetSettings"; + p.PCSettings = new SettingsPC(); + p.PCSettings.Language = toggleLanguage.getSelectedItemPosition(); + p.PCSettings.Theme = toggleTheme.getSelectedItemPosition(); + p.PCSettings.TrayVisible = toggleTray.isChecked(); + p.PCSettings.Statistics = toggleStatistics.isChecked(); + p.PCSettings.MultiInstance = toggleMultiInstance.isChecked(); + p.PCSettings.Logs = toggleLogging.isChecked(); + p.PCSettings.HideWarning = toggleWarningHide.isChecked(); + p.PCSettings.TestMode = toggleTestMode.isChecked(); + + final Handler handler = new Handler(Looper.getMainLooper()); + Hub.cui.sendMsg(p); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + BufferedReader in = new BufferedReader(new InputStreamReader(Hub.sc.socket.getInputStream())); + final String response = in.readLine(); + handler.post(new Runnable() { + @Override + public void run() { + if(response.equals("Settings Setted")) { + Toast.makeText(PCSettings.this, response, Toast.LENGTH_LONG).show(); + finish(); + } + else Toast.makeText(PCSettings.this, "Error while saving settings!", Toast.LENGTH_LONG).show(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + thread.start(); + thread.join(); } void prepareSettingsUI() throws JSONException { diff --git a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/Packet.java b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/Packet.java index 4cb719b..c103195 100644 --- a/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/Packet.java +++ b/Android/app/src/main/java/dev/kamilklecha/autoswitchmobile/Packet.java @@ -10,6 +10,19 @@ public class Packet implements Serializable { String Action; String TimeMode; Integer seconds; - Calendar dt = Calendar.getInstance(); + Calendar dt; Boolean force; + SettingsPC PCSettings; +} + +class SettingsPC implements Serializable { + public + int Language; + int Theme; + boolean TrayVisible; + boolean Statistics; + boolean MultiInstance; + boolean Logs; + boolean HideWarning; + boolean TestMode; }