diff --git a/app/src/main/java/com/example/onetap_ssh/ui/home/HomeFragment.java b/app/src/main/java/com/example/onetap_ssh/ui/home/HomeFragment.java index cb5dadb..b8a324c 100644 --- a/app/src/main/java/com/example/onetap_ssh/ui/home/HomeFragment.java +++ b/app/src/main/java/com/example/onetap_ssh/ui/home/HomeFragment.java @@ -83,23 +83,15 @@ public class HomeFragment extends Fragment { passwordInput = (EditText) root.findViewById(R.id.loginpasswordInput); ipInput = (EditText) root.findViewById(R.id.ipInput); loginButton = (Button) root.findViewById(R.id.loginButton); - reboot_Button = (Button) root.findViewById(R.id.reboot); - shutdown_Button = (Button) root.findViewById(R.id.shutdown); - togglepassword = (ImageView) root.findViewById(R.id.togglepassword); SharedPreferences t = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); if (user == null || ip == null) { loginButton.setVisibility(View.VISIBLE); - togglepassword.setVisibility(View.VISIBLE); - reboot_Button.setVisibility(View.GONE); - shutdown_Button.setVisibility(View.GONE); } else { loginButton.setVisibility(View.INVISIBLE); - togglepassword.setVisibility(View.INVISIBLE); ipInput.setVisibility(View.GONE); userInput.setVisibility(View.GONE); passwordInput.setVisibility(View.GONE); - reboot_Button.setVisibility(View.VISIBLE); - shutdown_Button.setVisibility(View.VISIBLE); + } loginButton.setOnClickListener(new View.OnClickListener() { @Override @@ -221,12 +213,9 @@ public class HomeFragment extends Fragment { ipInput.setVisibility(View.VISIBLE); userInput.setVisibility(View.VISIBLE); passwordInput.setVisibility(View.VISIBLE); - reboot_Button.setVisibility(View.GONE); - shutdown_Button.setVisibility(View.GONE); + } else { logoutButton.setVisibility(View.VISIBLE); - reboot_Button.setVisibility(View.VISIBLE); - shutdown_Button.setVisibility(View.VISIBLE); backgroundoverlay_bottom.setVisibility(View.VISIBLE); } logoutButton.setOnClickListener(new View.OnClickListener() { @@ -242,126 +231,6 @@ public class HomeFragment extends Fragment { requireActivity().finish(); } }); - reboot_Button = (Button) root.findViewById(R.id.reboot); - reboot_Button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (MainActivity.button_vibration) { - Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); - assert vr != null; - vr.vibrate(100); - } - - AlertDialog mDialog = new AlertDialog.Builder(getContext()) - .setTitle(getString(R.string.restart_server)) - .setMessage(getString(R.string.are_you_sure)) - - // Specifying a listener allows you to take an action before dismissing the dialog. - // The dialog is automatically dismissed when a dialog button is clicked. - .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - if (MainActivity.button_vibration) { - Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); - assert vr != null; - vr.vibrate(100); - } - try { - - Toast.makeText(getContext(), R.string.rebooting, Toast.LENGTH_SHORT).show(); - SSH_connection.executeRemoteCommand(ip, user, password, "reboot"); - } catch (Exception ignored) { - } - - // Continue with delete operation - } - }) - - // A null listener allows the button to dismiss the dialog and take no further action. - .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (MainActivity.button_vibration) { - Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); - assert vr != null; - vr.vibrate(100); - } - } - }).create(); - Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round); - mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id - mDialog.show(); - - - } - }); - shutdown_Button = (Button) root.findViewById(R.id.shutdown); - shutdown_Button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (MainActivity.button_vibration) { - Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); - assert vr != null; - vr.vibrate(100); - } - - AlertDialog mDialog = new AlertDialog.Builder(getContext()) - .setTitle(getString(R.string.shutdown_server)) - .setMessage(getString(R.string.are_you_sure)) - - // Specifying a listener allows you to take an action before dismissing the dialog. - // The dialog is automatically dismissed when a dialog button is clicked. - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - if (MainActivity.button_vibration) { - Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); - assert vr != null; - vr.vibrate(100); - } - try { - - Toast.makeText(getContext(), R.string.shutting_down, Toast.LENGTH_SHORT).show(); - SSH_connection.executeRemoteCommand(ip, user, password, "shutdown now"); - } catch (Exception ignored) { - } - - // Continue with delete operation - } - }) - - // A null listener allows the button to dismiss the dialog and take no further action. - .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (MainActivity.button_vibration) { - Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); - assert vr != null; - vr.vibrate(100); - } - } - }).create(); - Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round); - mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id - mDialog.show(); - - } - }); - - - if (togglepassword.getVisibility() == View.VISIBLE) { - togglepassword.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if (isPasswordVisible) { - passwordInput.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); - isPasswordVisible = false; - } else { - passwordInput.setTransformationMethod(PasswordTransformationMethod.getInstance()); - isPasswordVisible = true; - } - return false; - } - }); - } return root; diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index dd7f410..c9b7e93 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -1,164 +1,131 @@ - -