Last hope
This commit is contained in:
parent
6266e01a0d
commit
241a9ac5f6
@ -36,6 +36,7 @@ public class UserRepositoryImplementation implements UserRepository, LoginReposi
|
|||||||
userApi.getByLogin(login).enqueue(new CallToConsumer<>(
|
userApi.getByLogin(login).enqueue(new CallToConsumer<>(
|
||||||
callback,
|
callback,
|
||||||
userDto -> {
|
userDto -> {
|
||||||
|
if (userDto != null) {
|
||||||
final String resultLogin = userDto.login;
|
final String resultLogin = userDto.login;
|
||||||
final String id = userDto.id;
|
final String id = userDto.id;
|
||||||
final String name = userDto.name;
|
final String name = userDto.name;
|
||||||
@ -48,10 +49,10 @@ public class UserRepositoryImplementation implements UserRepository, LoginReposi
|
|||||||
userDto.photoUrl,
|
userDto.photoUrl,
|
||||||
userDto.position
|
userDto.position
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class LoginFragment extends Fragment {
|
|||||||
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error ->
|
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error ->
|
||||||
binding.error.setVisibility(Utils.visibleOrGone(error != null)));
|
binding.error.setVisibility(Utils.visibleOrGone(error != null)));
|
||||||
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||||
binding.login.setClickable(state.isButtonActive());
|
binding.login.setEnabled(state.isButtonActive());
|
||||||
if (state.isButtonActive()) {
|
if (state.isButtonActive()) {
|
||||||
binding.login.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.main_button, getContext().getTheme()));
|
binding.login.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.main_button, getContext().getTheme()));
|
||||||
binding.login.setTextColor(ResourcesCompat.getColor(getResources(), R.color.white, 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) {
|
if (status.getStatusCode() == 401) {
|
||||||
mutableErrorLiveData.postValue("There is no such login or incorrect");
|
mutableErrorLiveData.postValue("There is no such login or incorrect");
|
||||||
}
|
} else if (status.getStatusCode() == 200) {
|
||||||
if (status.getStatusCode() == 200) {
|
|
||||||
mutableOpenProfileLiveData.postValue(null);
|
mutableOpenProfileLiveData.postValue(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ import android.view.View;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentResultListener;
|
import androidx.fragment.app.FragmentResultListener;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
@ -40,22 +40,18 @@ public class QrResultFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
||||||
resultQr = QrScanDestination.INSTANCE.getDataIfExist(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 -> {
|
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||||
Log.d("status", resultQr != null ? resultQr : "None");
|
|
||||||
if (resultQr == null) {
|
if (resultQr == null) {
|
||||||
binding.result.setText(R.string.door_closed);
|
binding.result.setText(R.string.door_closed);
|
||||||
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.warn_button, getContext().getTheme()));
|
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.result.setText(R.string.door_opened);
|
||||||
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.main_button, getContext().getTheme()));
|
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.result.setText(R.string.error);
|
||||||
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.warn_button, getContext().getTheme()));
|
binding.close.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.warn_button, getContext().getTheme()));
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/login"
|
android:text="@string/login"
|
||||||
android:clickable="false"
|
android:enabled="false"
|
||||||
android:background="@drawable/inactive_button" />
|
android:background="@drawable/inactive_button" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
tools:layout="@layout/fragment_user">
|
tools:layout="@layout/fragment_user">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_userFragment_to_loginFragment"
|
android:id="@+id/action_userFragment_to_loginFragment"
|
||||||
app:destination="@id/loginFragment" />
|
app:destination="@id/loginFragment"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_userFragment_to_qrResultFragment"
|
android:id="@+id/action_userFragment_to_qrResultFragment"
|
||||||
app:destination="@id/qrResultFragment" />
|
app:destination="@id/qrResultFragment" />
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<string name="to_main_menu">Close</string>
|
<string name="to_main_menu">Close</string>
|
||||||
<string name="door_opened">Success</string>
|
<string name="door_opened">Success</string>
|
||||||
<string name="door_closed">Operation was cancelled</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="close_button">Close</string>
|
||||||
<string name="logout_text">Logout</string>
|
<string name="logout_text">Logout</string>
|
||||||
<string name="last_visit">"Last visit:"</string>
|
<string name="last_visit">"Last visit:"</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user