Skip to content

Commit

Permalink
Added saving pc settings
Browse files Browse the repository at this point in the history
  • Loading branch information
km2442 committed Jun 25, 2019
1 parent fa1e428 commit a860c5c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit a860c5c

Please sign in to comment.