refactoring code

This commit is contained in:
yannick.blanken@csc-online.eu 2022-07-22 09:58:23 +02:00
parent e73f9ba122
commit 07172607dc
1 changed files with 10 additions and 9 deletions

View File

@ -9,9 +9,11 @@ import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import eu.csc.vehown.data.model.CustomerDevice;
import eu.csc.vehown.databinding.FragmentDeviceRegistrationBinding;
import eu.csc.vehown.ui.base.AbstractFragment;
@ -47,18 +49,14 @@ public class DeviceRegistrationFragment extends AbstractFragment {
binding = FragmentDeviceRegistrationBinding.inflate(inflater, container, false);
View root = binding.getRoot();
Bundle args = getArguments();
if (args != null && args.containsKey(CUSTOM_RESULT_CODE)) {
result_code = args.getInt(CUSTOM_RESULT_CODE);
//} else {
}
mViewModel = new ViewModelProvider(this, new AppViewModelFactory(getContext()))
.get(DeviceRegistrationViewModel.class);
mViewModel = new ViewModelProvider(this).get(DeviceRegistrationViewModel.class);
binding.editSerialNumber.addTextChangedListener(new TextWatcher() {
@Override
@ -76,18 +74,21 @@ public class DeviceRegistrationFragment extends AbstractFragment {
mViewModel.getMSerialnumber().postValue(s.toString());
}
});
mViewModel.getMSerialnumber().observe(getViewLifecycleOwner(), s -> binding.btnFindBySerialNumber.setEnabled(s != null && !s.equals("")));
mViewModel.getMSerialnumber()
.observe(getViewLifecycleOwner(),
s -> binding.btnFindBySerialNumber.setEnabled(s != null && !s.equals("")));
mViewModel.getMCustomerDevice().observe(getViewLifecycleOwner(), customerDevice -> {
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.editSerialNumber, customerDevice.getSerialNumber());
setText(binding.editDeviceNumber, customerDevice.getDeviceNumber());
setText(binding.editName, customerDevice.getName());
binding.imgDevice.setImageBitmap(customerDevice.getBitmap());
}else{
} else {
clearText(binding.editSerialNumber);
clearText(binding.editDeviceNumber);
clearText(binding.editName);