refactoring code

This commit is contained in:
yannick.blanken@csc-online.eu 2022-07-22 10:16:40 +02:00
parent bd18012f92
commit 5c1c8024cc
3 changed files with 9 additions and 55 deletions

View File

@ -115,17 +115,16 @@ public class DeviceRegistrationFragment extends AbstractFragment {
});
//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);
}
});
@ -144,47 +143,4 @@ public class DeviceRegistrationFragment extends AbstractFragment {
return root;
}
private void checkUserAuth() {
// UIUtils.showDialog(this.getContext(), "A", "mess");
String title = "Error";
String message = "No User is registered";
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(message)
.setTitle(title);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
Intent intent = new Intent(getContext(), RegisterCustomerActivity.class);
startActivity(intent);
}
});
builder.setNegativeButton("Abort", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
mViewModel.getMIsEnabled().postValue(false);
ItemListDialogFragment.newInstance(3).show(getChildFragmentManager(), "dialog");
}
});
// 3. Get the <code><a href="/reference/android/app/AlertDialog.html">AlertDialog</a></code> from <code><a href="/reference/android/app/AlertDialog.Builder.html#create()">create()</a></code>
AlertDialog dialog = builder.create();
dialog.show();
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewModel = new ViewModelProvider(this).get(DeviceRegistrationViewModel.class);
// TODO: Use the ViewModel
}
}

View File

@ -20,7 +20,6 @@ import lombok.var;
public class DeviceRegistrationViewModel
extends AbstractBaseViewModel {
@Getter
private final MutableLiveData<String> mSerialnumber;
@ -39,10 +38,9 @@ public class DeviceRegistrationViewModel
//private IVehOwnAppClient restClient;
public DeviceRegistrationViewModel(LocalStorageClient localStorage,
Context context,
public DeviceRegistrationViewModel(Context context,
CustomerContentDataSource dataSource) {
super(localStorage);
super(context);
mSerialnumber = new MutableLiveData<>();
mIsEnabled = new MutableLiveData<>();
mRegistrationResult = new MutableLiveData<>();
@ -50,7 +48,7 @@ public class DeviceRegistrationViewModel
this.dataSource = dataSource;
mSerialnumber.setValue(localStorage.getLastSerialnumber());
mSerialnumber.setValue(localStorageClient.getLastSerialnumber());
}

View File

@ -69,7 +69,7 @@ public class AppViewModelFactory implements ViewModelProvider.Factory {
return (T) new FragmentDetailVehicleViewModel(context);
}
else if (modelClass.isAssignableFrom(DeviceRegistrationViewModel.class)) {
return (T) new DeviceRegistrationViewModel(localStorage, context, new CustomerContentDataSource());
return (T) new DeviceRegistrationViewModel(context, new CustomerContentDataSource());
}
else if(modelClass.isAssignableFrom(FragmentCustomerRegistrationViewModel.class)){
return (T) new FragmentCustomerRegistrationViewModel(localStorage, context, new CustomerContentDataSource());