Homefragment wurde überarbeitet

This commit is contained in:
JG-Cody 2024-02-25 20:23:13 +01:00
parent a35b38306d
commit b5af4d57f6
2 changed files with 78 additions and 242 deletions

View File

@ -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;

View File

@ -1,164 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="match_parent"
android:clickable="true"
android:hapticFeedbackEnabled="true"
tools:context=".ui.home.HomeFragment">
<Button
android:id="@+id/shutdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/button_round"
android:hapticFeedbackEnabled="true"
android:text="@string/shutdown"
app:backgroundTint="@null"
app:icon="@drawable/power_settings_new_24px"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/reboot" />
<Button
android:id="@+id/reboot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_round"
android:hapticFeedbackEnabled="true"
android:text="@string/reboot"
app:backgroundTint="@null"
app:icon="@drawable/restart_alt_24px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ipInput" />
<ImageView
android:id="@+id/Background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#80FFFFFF"
android:scaleType="centerCrop"
android:padding="25dp"
android:src="@drawable/background_red_blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
tools:context=".ui.home.HomeFragment">
<TextView
android:id="@+id/text_home"
android:layout_width="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:gravity="center_horizontal"
android:text="@string/Welcome_to_your_HOMEAUTOMATION_APP"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/reboot"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.25" />
<TextView
android:id="@+id/login_data"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAlignment="center"
android:textColor="#00FF00"
android:textSize="14sp"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/text_home" />
<EditText
android:id="@+id/ipInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:backgroundTint="@color/mtrl_btn_text_color_selector"
android:ems="10"
android:hint="@string/login_ipaddress"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/login_data" />
<EditText
android:id="@+id/loginuserInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/mtrl_btn_text_color_selector"
android:ems="10"
android:hint="@string/login_username"
android:inputType="textEmailAddress"
android:singleLine="false"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/ipInput" />
<EditText
android:id="@+id/loginpasswordInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/mtrl_btn_text_color_selector"
android:ems="10"
android:hint="@string/login_password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/loginuserInput"
app:passwordToggleEnabled="true"/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/loginButton"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="25dp"
android:layout_marginTop="20dp"
android:background="@drawable/button_round"
android:drawableLeft="@drawable/login_24px"
android:drawableTint="?android:attr/textColor"
android:hapticFeedbackEnabled="true"
android:text="@string/login"
app:backgroundTint="@null"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/loginpasswordInput" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout4" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/logoutButton"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="25dp"
android:layout_marginTop="20dp"
android:background="@drawable/button_round"
android:drawableRight="@drawable/logout_24px"
android:drawableTint="?android:attr/textColor"
android:hapticFeedbackEnabled="true"
android:text="@string/logout"
app:backgroundTint="@null"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/loginpasswordInput" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout4" />
<ImageView
android:id="@+id/togglepassword"
android:layout_width="wrap_content"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-30dp"
android:src="@drawable/visibility_black_24dp"
app:tint="?android:attr/textColor"
app:layout_constraintBottom_toBottomOf="@+id/loginpasswordInput"
app:layout_constraintStart_toEndOf="@+id/loginpasswordInput"
app:layout_constraintTop_toBottomOf="@+id/loginuserInput" />
android:layout_marginTop="50dp"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/text_home">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ipInput"
android:layout_width="match_parent"
android:layout_height="55dp"
android:ems="10"
android:hint="@string/login_ipaddress"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout2">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/loginuserInput"
android:layout_width="match_parent"
android:layout_height="55dp"
android:ems="10"
android:hint="@string/login_username"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.426"
app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout3"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/loginpasswordInput"
android:layout_width="match_parent"
android:layout_height="55dp"
android:ems="10"
android:hint="@string/login_password"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>