refactoring code

This commit is contained in:
yannick.blanken@csc-online.eu 2022-07-22 10:10:10 +02:00
parent 07172607dc
commit fb3081aed4
4 changed files with 138 additions and 119 deletions

View File

@ -28,6 +28,9 @@ public abstract class AbstractFragment extends Fragment {
//region Helper
protected String getText(@NonNull TextInputLayout item) {
return getText(item.getEditText());
}
protected String getText(@NonNull EditText item) {
return item.getText().toString();
}

View File

@ -58,7 +58,7 @@ public class DeviceRegistrationFragment extends AbstractFragment {
mViewModel = new ViewModelProvider(this, new AppViewModelFactory(getContext()))
.get(DeviceRegistrationViewModel.class);
binding.editSerialNumber.addTextChangedListener(new TextWatcher() {
binding.tfSerialnumber.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -83,15 +83,17 @@ public class DeviceRegistrationFragment extends AbstractFragment {
binding.btnStore.setEnabled(customerDevice != null);
if (customerDevice != null) {
setText(binding.editSerialNumber, customerDevice.getSerialNumber());
setText(binding.editDeviceNumber, customerDevice.getDeviceNumber());
setText(binding.editName, customerDevice.getName());
setText(binding.tfCustomerDeviceSerialnumber, customerDevice.getSerialNumber());
setText(binding.tfCustomerDeviceNumber, customerDevice.getDeviceNumber());
setText(binding.tfCustomerDeviceName, customerDevice.getName());
setText(binding.tfCustomerDeviceManufacture, customerDevice.getManufacture());
binding.imgDevice.setImageBitmap(customerDevice.getBitmap());
} else {
clearText(binding.editSerialNumber);
clearText(binding.editDeviceNumber);
clearText(binding.editName);
clearText(binding.tfCustomerDeviceSerialnumber);
clearText(binding.tfCustomerDeviceName);
clearText(binding.tfCustomerDeviceNumber);
clearText(binding.tfCustomerDeviceManufacture);
//ToDo set -NO IMAGE- IMAGE
}
});
@ -105,36 +107,22 @@ public class DeviceRegistrationFragment extends AbstractFragment {
});
binding.btnFindBySerialNumber.setOnClickListener(v -> {
CustomerDevice item = new CustomerDevice();
// item.setName(binding.editSerialNumber.getText().toString());
item.setSerialNumber(binding.editSerialNumber.getText().toString());
mViewModel.getMCustomerDevice().postValue(item);
/*
mViewModel.storeDevice();
//mViewModel.doRegisterDevice();
if (result_code != null)
{
getActivity().setResult(result_code);
getActivity().finish();
}
*/
mViewModel.findDeviceBySerialnumber(getText(binding.tfSerialnumber));
});
//return inflater.inflate(R.layout.device_registration_fragment, container, false);
//ToDo refactore
mViewModel.getMIsEnabled().observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && !aBoolean) {
binding.btnFindBySerialNumber.setEnabled(false);
binding.editSerialNumber.setEnabled(false);
binding.progressLoading.setVisibility(mViewModel.getMSerialnumber().getValue() == null ? View.VISIBLE : View.INVISIBLE);
// binding.editSerialNumber.setEnabled(false);
// binding.progressLoading.setVisibility(mViewModel.getMSerialnumber().getValue() == null ? View.VISIBLE : View.INVISIBLE);
} else {
binding.progressLoading.setVisibility(View.INVISIBLE);
binding.editSerialNumber.setEnabled(true);
binding.editSerialNumber.setEnabled(true);
// binding.progressLoading.setVisibility(View.INVISIBLE);
// binding.editSerialNumber.setEnabled(true);
// binding.editSerialNumber.setEnabled(true);
}
});

View File

@ -1,121 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<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:id="@+id/frameLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
tools:context=".ui.registration.device.DeviceRegistrationFragment">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tfSerialnumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
android:hint="@string/serial_number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/tvSerialNumber"
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="@dimen/fontS"
android:text="@string/serial_number"
android:labelFor="@id/editSerialNumber"/>
android:enabled="true" />
</com.google.android.material.textfield.TextInputLayout>
<EditText
android:id="@+id/editSerialNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvSerialNumber"
android:layout_toStartOf="@+id/btnFindBySerialNumber"
android:layout_marginTop="5dp"
android:inputType="text"
android:autofillHints="@string/serial_number"
android:ems="15"
tools:ignore="TextFields"/>
<Button
android:id="@+id/btnFindBySerialNumber"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvSerialNumber"
android:layout_alignParentEnd="true"
android:enabled="false"
android:text="@string/find_device"/>
android:id="@+id/btnFindBySerialNumber"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
<ProgressBar
android:id="@+id/progressLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"
android:layout_alignStart="@id/btnFindBySerialNumber"
android:layout_alignEnd="@id/btnFindBySerialNumber"
android:layout_alignTop="@id/btnFindBySerialNumber"
android:layout_alignBottom="@id/btnFindBySerialNumber"/>
android:text="@string/find_device"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
<TextView
android:id="@+id/tvDeviceNumber"
app:layout_constraintTop_toBottomOf="@+id/tfSerialnumber" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tfCustomerDeviceSerialnumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/serial_number"
app:layout_constraintTop_toBottomOf="@+id/btnFindBySerialNumber">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editSerialNumber"
android:layout_marginTop="5dp"
android:textSize="@dimen/fontS"
android:text="@string/device_number"
android:labelFor="@id/editDeviceNumber"
/>
android:enabled="false" />
<EditText
android:id="@+id/editDeviceNumber"
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tfCustomerDeviceNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_devicenumber"
app:layout_constraintTop_toBottomOf="@+id/tfCustomerDeviceSerialnumber">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDeviceNumber"
android:inputType="text"
android:autofillHints="@string/device_number"
android:enabled="false"
android:ems="15"
tools:ignore="TextFields"/>
android:enabled="false" />
<TextView
android:id="@+id/tvName"
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tfCustomerDeviceManufacture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_manufacture"
app:layout_constraintTop_toBottomOf="@+id/tfCustomerDeviceNumber">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editDeviceNumber"
android:layout_marginTop="5dp"
android:textSize="@dimen/fontS"
android:text="@string/name"
android:labelFor="@id/editName"
/>
android:enabled="false" />
<EditText
android:id="@+id/editName"
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tfCustomerDeviceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
app:layout_constraintTop_toBottomOf="@+id/tfCustomerDeviceManufacture">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvName"
android:inputType="text"
android:autofillHints="@string/variant"
android:enabled="false"
android:ems="15"/>
android:enabled="false" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/imgDevice"
android:layout_width="@dimen/systemImageWidth0"
android:layout_height="@dimen/systemImageWidth0"
android:layout_below="@+id/editName"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginBottom="15dp"
android:contentDescription="@string/image"/>
android:id="@+id/imgDevice"
android:layout_width="@dimen/systemImageWidth0"
android:layout_height="@dimen/systemImageWidth0"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="15dp"
android:contentDescription="@string/image"
app:layout_constraintTop_toBottomOf="@+id/tfCustomerDeviceName" />
<LinearLayout
android:id="@+id/llLocalButtons"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_below="@+id/imgDevice"
android:layout_width="match_parent">
android:id="@+id/llLocalButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@+id/imgDevice">
<Button
android:id="@+id/btnStore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/store"
style="?android:attr/buttonBarButtonStyle"
android:enabled="true"/>
android:id="@+id/btnStore"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:text="@string/store" />
<!--Button
android:id="@+id/btnUnDo"
@ -137,4 +146,21 @@
</LinearLayout>
</RelativeLayout>
<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="32dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="64dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/btnFindBySerialNumber"
app:layout_constraintStart_toStartOf="@+id/btnFindBySerialNumber"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.3" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -169,5 +169,7 @@
<string name="title_register_customer">Register</string>
<string name="title_customer_profile">Profile</string>
<string name="title_logs">Logs</string>
<string name="hint_manufacture">Manufacture</string>
<string name="hint_devicenumber">Devicenumber</string>
</resources>