Last hope

This commit is contained in:
A1pha 2024-12-08 12:00:23 +03:00
parent 6266e01a0d
commit 241a9ac5f6
8 changed files with 26 additions and 27 deletions

@ -36,21 +36,22 @@ public class UserRepositoryImplementation implements UserRepository, LoginReposi
userApi.getByLogin(login).enqueue(new CallToConsumer<>(
callback,
userDto -> {
final String resultLogin = userDto.login;
final String id = userDto.id;
final String name = userDto.name;
if (resultLogin != null && id != null && name != null) {
return new UserEntity(
id,
resultLogin,
name,
userDto.lastVisit,
userDto.photoUrl,
userDto.position
);
} else {
return null;
if (userDto != null) {
final String resultLogin = userDto.login;
final String id = userDto.id;
final String name = userDto.name;
if (resultLogin != null && id != null && name != null) {
return new UserEntity(
id,
resultLogin,
name,
userDto.lastVisit,
userDto.photoUrl,
userDto.position
);
}
}
return null;
}
));
}

@ -52,7 +52,7 @@ public class LoginFragment extends Fragment {
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error ->
binding.error.setVisibility(Utils.visibleOrGone(error != null)));
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
binding.login.setClickable(state.isButtonActive());
binding.login.setEnabled(state.isButtonActive());
if (state.isButtonActive()) {
binding.login.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.main_button, getContext().getTheme()));
binding.login.setTextColor(ResourcesCompat.getColor(getResources(), R.color.white, getContext().getTheme()));

@ -53,8 +53,7 @@ public class LoginViewModel extends ViewModel {
}
if (status.getStatusCode() == 401) {
mutableErrorLiveData.postValue("There is no such login or incorrect");
}
if (status.getStatusCode() == 200) {
} else if (status.getStatusCode() == 200) {
mutableOpenProfileLiveData.postValue(null);
}
});

@ -8,6 +8,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentResultListener;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;

@ -40,22 +40,18 @@ public class QrResultFragment extends Fragment {
@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
resultQr = QrScanDestination.INSTANCE.getDataIfExist(result);
if (getContext() != null && Utils.getLogin(getContext()) != null) {
viewModel.update(Utils.getLogin(getContext()), resultQr);
}
viewModel.update(Utils.getLogin(getContext()), resultQr);
}
});
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
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()) {
} else if (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 || !state.isOpened()) {
} else {
binding.result.setText(R.string.error);
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.warn_button, getContext().getTheme()));
}

@ -40,7 +40,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:clickable="false"
android:enabled="false"
android:background="@drawable/inactive_button" />
<TextView

@ -12,7 +12,9 @@
tools:layout="@layout/fragment_user">
<action
android:id="@+id/action_userFragment_to_loginFragment"
app:destination="@id/loginFragment" />
app:destination="@id/loginFragment"
app:popUpTo="@id/nav_graph"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_userFragment_to_qrResultFragment"
app:destination="@id/qrResultFragment" />

@ -9,7 +9,7 @@
<string name="to_main_menu">Close</string>
<string name="door_opened">Success</string>
<string name="door_closed">Operation was cancelled</string>
<string name="error">Something went wrong</string>
<string name="error">Something wrong</string>
<string name="close_button">Close</string>
<string name="logout_text">Logout</string>
<string name="last_visit">"Last visit:"</string>