Skip to content

Commit

Permalink
Helping checkbox stay clicked #57
Browse files Browse the repository at this point in the history
  • Loading branch information
wmamos committed Feb 26, 2023
1 parent a96e2c8 commit d1849b1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.neptune.app;//comment

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.content.Intent;
import android.view.View;

import com.google.gson.JsonParseException;
import com.neptune.app.Backend.ConnectionManager;
import com.neptune.app.Backend.Server;

import java.io.IOException;
import java.util.UUID;


Expand All @@ -29,6 +33,7 @@ public class DeviceActivity extends AppCompatActivity {
private TextView notificationsTextView;
private TextView clipboardTextView;
private TextView fileTextView;
private CheckBox notificationsCheckbox;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -55,6 +60,43 @@ protected void onCreate(Bundle savedInstanceState) {
fileTextView = findViewById(R.id.fileTextView);
fileTextView.setText("Allow " + serverFriendlyName + " to send files.");

notificationsCheckbox = findViewById(R.id.notificationsCheckbox);
if(server.syncNotifications) {
notificationsCheckbox.setChecked(true);
}
notificationsCheckbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(server.syncNotifications) {
server.syncNotifications = false;
}
else {
server.syncNotifications = true;
}

try {
server.save();
} catch (JsonParseException e) {
e.printStackTrace();
if (server != null)
server.delete();
runOnUiThread(() -> showErrorMessage("Failed to pair device", e.getMessage()));

} catch (IOException e) {
e.printStackTrace();
if (server != null)
server.delete();
runOnUiThread(() -> showErrorMessage("Failed to pair device", e.getMessage()));

}/* catch (ConnectionManager.FailedToPair e) {
e.printStackTrace();
if (server != null)
server.delete();
runOnUiThread(() -> showErrorMessage("Failed to pair device", e.getMessage()));
}*/
}
});

//Sets the EditText containing the IP address of the server to the correct IP Address.
ipAddress = findViewById(R.id.editIPAddress);
ipAddress.setText(server.ipAddress.getIPAddress());
Expand Down Expand Up @@ -164,4 +206,14 @@ public boolean onSupportNavigateUp() {
return true;
}

public void showErrorMessage(String title, String message) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle(title);
alertBuilder.setMessage(message);
alertBuilder.setPositiveButton("Ok", (dialog, which) -> {
// do stuff here?
});

alertBuilder.create().show();
}
}
4 changes: 2 additions & 2 deletions Client/Android/app/src/main/res/layout/activity_device.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
app:layout_constraintVertical_bias="1.0" />

<CheckBox
android:id="@+id/checkBox"
android:id="@+id/notificationsCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="128dp"
Expand All @@ -88,7 +88,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.279"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
app:layout_constraintTop_toBottomOf="@+id/notificationsCheckbox" />

<CheckBox
android:id="@+id/checkBox2"
Expand Down

0 comments on commit d1849b1

Please sign in to comment.