Skip to content

Commit

Permalink
Added PCSettings json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
km2442 committed Jun 25, 2019
1 parent 356045a commit fa1e428
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
import android.widget.Toast;
import android.widget.ToggleButton;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class PCSettings extends AppCompatActivity {

private static final String TAG = "PCSettings";
ProgressBar loadingBar;
ConstraintLayout settingsLayout;

Expand Down Expand Up @@ -58,13 +62,24 @@ protected void onCreate(Bundle savedInstanceState) {
btnSave = (Button) findViewById(R.id.PCSettings_SaveSettings);
btnCancel = (Button) findViewById(R.id.PCSettings_Cancel);

btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

try {
getSettings();
} catch (InterruptedException e) {
e.printStackTrace();
}
loadingBar.setVisibility(View.INVISIBLE);
settingsLayout.setVisibility(View.VISIBLE);
try {
prepareSettingsUI();
} catch (JSONException e) {
e.printStackTrace();
}

}

void getSettings() throws InterruptedException {
Expand All @@ -79,26 +94,39 @@ 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() {
Toast.makeText(PCSettings.this, response, Toast.LENGTH_SHORT).show();
}
});
setJson(response);
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
// Thread thread = new Thread(new Runnable() {
// @Override
// public void run() {
// Socket s = Hub.sc.socket;
// BufferedReader input = null;
// try {
// input = new BufferedReader(new InputStreamReader(s.getInputStream()));
// } catch (IOException e) {
thread.join();
}

void saveSettings() {

}

void prepareSettingsUI() throws JSONException {
JSONObject obj = new JSONObject(json);
if(obj.has("Type") && obj.getString("Type").equals("Settings")) {
toggleLanguage.setSelection(obj.getInt("Language"));
toggleTheme.setSelection(obj.getInt("Theme"));
toggleTray.setChecked(obj.getBoolean("TrayVisible"));
toggleStatistics.setChecked(obj.getBoolean("Statistics"));
toggleMultiInstance.setChecked(obj.getBoolean("MultiInstance"));
toggleLogging.setChecked(obj.getBoolean("Logs"));
toggleWarningHide.setChecked(obj.getBoolean("HideWarning"));
toggleTestMode.setChecked(obj.getBoolean("TestMode"));

loadingBar.setVisibility(View.INVISIBLE);
settingsLayout.setVisibility(View.VISIBLE);
btnSave.setEnabled(true);
}
else {
Toast.makeText(PCSettings.this, "Can't acquire Settings from PC!", Toast.LENGTH_LONG).show();
finish();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.kamilklecha.autoswitchmobile;

import android.os.Handler;
import android.util.Log;

import java.io.IOException;
Expand All @@ -22,7 +21,6 @@ public Socket getSocket() {

private OutputStream out;
private PrintWriter output;
final Handler handler = new Handler();

ConnectWait cw;

Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/main/res/layout/activity_pcsettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="Is Tray Icon visible?"
android:text="Enable Tray Icon?"
android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@id/textView20"
Expand Down

0 comments on commit fa1e428

Please sign in to comment.