Final commit #2
This commit is contained in:
parent
7ae4445969
commit
2971b29a7c
@ -15,7 +15,7 @@ public class PushQrUseCase {
|
||||
}
|
||||
public void execute(@NonNull QrEntity qrEntity, Consumer<Status<Boolean>> callback) {
|
||||
repository.pushQr(qrEntity, status -> {
|
||||
boolean isOpened = status.getStatusCode() == 200 || status.getStatusCode() == 401;
|
||||
boolean isOpened = status.getStatusCode() == 200 || status.getStatusCode() == 400 || status.getStatusCode() == 401;
|
||||
callback.accept(
|
||||
new Status<>(
|
||||
status.getStatusCode(),
|
||||
|
@ -95,12 +95,10 @@ public class UserFragment extends Fragment {
|
||||
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
|
||||
@Override
|
||||
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
||||
if (QrScanDestination.INSTANCE.getDataIfExist(result) != null) {
|
||||
getParentFragmentManager().setFragmentResult(RESPONSE_KEY, result);
|
||||
if (getView() != null)
|
||||
Navigation.findNavController(getView()).navigate(
|
||||
R.id.action_userFragment_to_qrResultFragment);
|
||||
}
|
||||
getParentFragmentManager().setFragmentResult(RESPONSE_KEY, result);
|
||||
if (getView() != null)
|
||||
Navigation.findNavController(getView()).navigate(
|
||||
R.id.action_userFragment_to_qrResultFragment);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3,6 +3,7 @@ package ru.myitschool.work.ui.qr.result;
|
||||
import static ru.myitschool.work.core.Constants.RESPONSE_KEY;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -31,6 +32,8 @@ public class QrResultFragment extends Fragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (savedInstanceState != null)
|
||||
resultQr = savedInstanceState.getString(QrScanDestination.REQUEST_KEY);
|
||||
binding = FragmentQrResultBinding.bind(view);
|
||||
viewModel = new ViewModelProvider(this).get(QrResultViewModel.class);
|
||||
|
||||
@ -46,13 +49,15 @@ public class QrResultFragment extends Fragment {
|
||||
});
|
||||
|
||||
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||
if (state.getErrorMessage() == null && state.isOpened()) {
|
||||
Log.d("status", resultQr != null ? resultQr : "None");
|
||||
if (resultQr == null) {
|
||||
binding.result.setText(R.string.door_closed);
|
||||
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.warn_button, getContext().getTheme()));
|
||||
} else if (state.getErrorMessage() == null && state.isOpened()) {
|
||||
binding.result.setText(R.string.door_opened);
|
||||
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.main_button, getContext().getTheme()));
|
||||
} else if (state.getErrorMessage() != null) {
|
||||
} else if (state.getErrorMessage() != null || !state.isOpened()) {
|
||||
binding.result.setText(R.string.error);
|
||||
} else if (resultQr == null) {
|
||||
binding.result.setText(R.string.door_closed);
|
||||
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.warn_button, getContext().getTheme()));
|
||||
}
|
||||
});
|
||||
@ -65,6 +70,12 @@ public class QrResultFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(QrScanDestination.REQUEST_KEY, resultQr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
binding = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user