QR problem appeared
This commit is contained in:
parent
5e0bc5d73a
commit
ce36d38d01
@ -1,5 +1,5 @@
|
|||||||
package ru.myitschool.work.core
|
package ru.myitschool.work.core
|
||||||
// БЕРИТЕ И ИЗМЕНЯЙТЕ ХОСТ ТОЛЬКО ЗДЕСЬ И НЕ БЕРИТЕ ИЗ ДРУГИХ МЕСТ. ФАЙЛ ПЕРЕМЕЩАТЬ НЕЛЬЗЯ
|
// БЕРИТЕ И ИЗМЕНЯЙТЕ ХОСТ ТОЛЬКО ЗДЕСЬ И НЕ БЕРИТЕ ИЗ ДРУГИХ МЕСТ. ФАЙЛ ПЕРЕМЕЩАТЬ НЕЛЬЗЯ
|
||||||
object Constants {
|
object Constants {
|
||||||
const val SERVER_ADDRESS = "http://localhost:8090"
|
const val SERVER_ADDRESS = "http://192.168.1.2:8080"
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ public interface UserApi {
|
|||||||
@GET("api/{login}/info")
|
@GET("api/{login}/info")
|
||||||
Call<UserDto> getByLogin(@Path("login") String login);
|
Call<UserDto> getByLogin(@Path("login") String login);
|
||||||
@GET("api/{login}/auth")
|
@GET("api/{login}/auth")
|
||||||
Call<Void> isExist(@Path("username") String login);
|
Call<Void> isExist(@Path("login") String login);
|
||||||
@PATCH("api/{login}/open/")
|
@PATCH("api/{login}/open/")
|
||||||
Call<Void> openDoor(@Path("login") String login, @Body QrDto qrDto);
|
Call<Void> openDoor(@Path("login") String login, @Body QrDto qrDto);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ public class LoginFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getView() == null) return;
|
if (getView() == null) return;
|
||||||
|
Log.d("process", "navigated");
|
||||||
Navigation.findNavController(getView()).navigate(
|
Navigation.findNavController(getView()).navigate(
|
||||||
R.id.action_loginFragment_to_userFragment);
|
R.id.action_loginFragment_to_userFragment);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package ru.myitschool.work.ui.login;
|
package ru.myitschool.work.ui.login;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -52,11 +52,12 @@ public class LoginViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
isUserExistUseCase.execute(currentLogin, status -> {
|
isUserExistUseCase.execute(currentLogin, status -> {
|
||||||
if (status.getValue() == null || status.getErrors() != null) {
|
if (status.getValue() == null || status.getErrors() != null) {
|
||||||
|
Log.e("errors", status.getErrors().getLocalizedMessage());
|
||||||
mutableErrorLiveData.postValue("Something went wrong. Try again later");
|
mutableErrorLiveData.postValue("Something went wrong. Try again later");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status.getStatusCode() == 401) {
|
if (status.getStatusCode() == 401) {
|
||||||
mutableErrorLiveData.postValue("Логина не существует или неверный");
|
mutableErrorLiveData.postValue("There is no such login or incorrect");
|
||||||
}
|
}
|
||||||
if (status.getStatusCode() == 200) {
|
if (status.getStatusCode() == 200) {
|
||||||
mutableOpenProfileLiveData.postValue(null);
|
mutableOpenProfileLiveData.postValue(null);
|
||||||
|
@ -8,7 +8,6 @@ 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.FragmentResultListener;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
|
||||||
@ -17,7 +16,6 @@ import com.squareup.picasso.Picasso;
|
|||||||
import ru.myitschool.work.R;
|
import ru.myitschool.work.R;
|
||||||
import ru.myitschool.work.databinding.FragmentUserBinding;
|
import ru.myitschool.work.databinding.FragmentUserBinding;
|
||||||
import ru.myitschool.work.domain.entities.UserEntity;
|
import ru.myitschool.work.domain.entities.UserEntity;
|
||||||
import ru.myitschool.work.ui.qr.scan.QrScanDestination;
|
|
||||||
import ru.myitschool.work.utils.Utils;
|
import ru.myitschool.work.utils.Utils;
|
||||||
|
|
||||||
public class UserFragment extends Fragment {
|
public class UserFragment extends Fragment {
|
||||||
@ -34,37 +32,6 @@ public class UserFragment extends Fragment {
|
|||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
binding = FragmentUserBinding.bind(view);
|
binding = FragmentUserBinding.bind(view);
|
||||||
|
|
||||||
binding.scan.setOnClickListener(v -> {
|
|
||||||
if (getView() != null) {
|
|
||||||
Navigation.findNavController(getView()).navigate(
|
|
||||||
R.id.action_userFragment_to_qrScanFragment);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
|
|
||||||
@Override
|
|
||||||
public void onFragmentResult(@NonNull String key, @NonNull Bundle bundle) {
|
|
||||||
|
|
||||||
if (getView() != null) {
|
|
||||||
Navigation.findNavController(getView()).navigate(
|
|
||||||
R.id.action_userFragment_to_qrResultFragment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
binding.logout.setOnClickListener(v -> {
|
|
||||||
if (getContext() != null) {
|
|
||||||
SharedPreferences sharedPreferences = getContext().getSharedPreferences("login", Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
|
||||||
editor.putString("login", null);
|
|
||||||
editor.commit();
|
|
||||||
}
|
|
||||||
if (getView() != null) {
|
|
||||||
Navigation.findNavController(getView()).navigate(
|
|
||||||
R.id.action_userFragment_to_loginFragment);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
viewModel = new ViewModelProvider(this).get(UserViewModel.class);
|
viewModel = new ViewModelProvider(this).get(UserViewModel.class);
|
||||||
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||||
UserEntity entity = state.getItem();
|
UserEntity entity = state.getItem();
|
||||||
@ -86,13 +53,31 @@ public class UserFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (getContext() != null) {
|
if (getContext() != null) {
|
||||||
SharedPreferences sharedPreferences = getContext().getSharedPreferences("login", Context.MODE_PRIVATE);
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
||||||
String login = sharedPreferences.getString("login", null);
|
"login", Context.MODE_PRIVATE);
|
||||||
if (login != null && getView() != null) {
|
viewModel.update(preferences.getString("login", ""));
|
||||||
viewModel.update(login);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.scan.setOnClickListener(v -> {
|
||||||
|
if (getView() != null) {
|
||||||
|
Navigation.findNavController(getView()).navigate(
|
||||||
|
R.id.action_userFragment_to_qrResultFragment);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
binding.logout.setOnClickListener(v -> {
|
||||||
|
if (getContext() != null) {
|
||||||
|
SharedPreferences sharedPreferences = getContext().getSharedPreferences("login", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putString("login", null);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
if (getView() != null) {
|
||||||
|
Navigation.findNavController(getView()).navigate(
|
||||||
|
R.id.action_userFragment_to_loginFragment);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.myitschool.work.ui.profile;
|
package ru.myitschool.work.ui.profile;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
@ -13,34 +15,24 @@ import ru.myitschool.work.domain.user.GetUserByLoginUseCase;
|
|||||||
|
|
||||||
public class UserViewModel extends ViewModel {
|
public class UserViewModel extends ViewModel {
|
||||||
|
|
||||||
private final MutableLiveData<State> mutableStateLiveData = new MutableLiveData<State>();
|
private final MutableLiveData<State> mutableStateLiveData = new MutableLiveData<>();
|
||||||
public final LiveData<State> stateLiveData = mutableStateLiveData;
|
public final LiveData<State> stateLiveData = mutableStateLiveData;
|
||||||
|
|
||||||
public final GetUserByLoginUseCase getUserByLoginUseCase = new GetUserByLoginUseCase(
|
public final GetUserByLoginUseCase getUserByLoginUseCase = new GetUserByLoginUseCase(
|
||||||
UserRepositoryImplementation.getInstance()
|
UserRepositoryImplementation.getInstance()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public UserViewModel(String login) {
|
|
||||||
update(login);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(@NonNull String login) {
|
public void update(@NonNull String login) {
|
||||||
mutableStateLiveData.setValue(new State(null, null, true));
|
mutableStateLiveData.setValue(new State(null, null, true));
|
||||||
getUserByLoginUseCase.execute(login, status -> {
|
getUserByLoginUseCase.execute(login, status -> {
|
||||||
mutableStateLiveData.postValue(fromStatus(status));
|
mutableStateLiveData.postValue(new State(
|
||||||
|
status.getErrors() != null ? status.getErrors().getLocalizedMessage() : null,
|
||||||
|
status.getValue(),
|
||||||
|
false
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private State fromStatus(Status<UserEntity> status) {
|
|
||||||
return new State(
|
|
||||||
status.getErrors() != null ? status.getErrors().getLocalizedMessage(): null,
|
|
||||||
status.getValue(),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class State {
|
public class State {
|
||||||
@Nullable
|
@Nullable
|
||||||
private final String errorMessage;
|
private final String errorMessage;
|
||||||
|
@ -3,6 +3,7 @@ package ru.myitschool.work.ui.qr.result;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ import ru.myitschool.work.ui.qr.scan.QrScanDestination;
|
|||||||
public class QrResultFragment extends Fragment {
|
public class QrResultFragment extends Fragment {
|
||||||
|
|
||||||
private FragmentQrResultBinding binding;
|
private FragmentQrResultBinding binding;
|
||||||
private String resultQr;
|
private Bundle resultQr;
|
||||||
private QrResultViewModel viewModel;
|
private QrResultViewModel viewModel;
|
||||||
|
|
||||||
public QrResultFragment() {
|
public QrResultFragment() {
|
||||||
@ -28,31 +29,40 @@ public class QrResultFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
binding = FragmentQrResultBinding.bind(view);
|
|
||||||
|
|
||||||
binding.close.setOnClickListener(v -> {
|
|
||||||
if (getView() != null) {
|
|
||||||
Navigation.findNavController(getView()).navigate(
|
|
||||||
R.id.action_qrResultFragment_to_userFragment);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
|
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFragmentResult(@NonNull String key, @NonNull Bundle bundle) {
|
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
||||||
resultQr = bundle.getString(QrScanDestination.REQUEST_KEY);
|
resultQr = result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
Log.d("status", String.valueOf(resultQr != null));
|
||||||
|
|
||||||
|
if (getView() != null && resultQr == null) {
|
||||||
|
Navigation.findNavController(getView()).navigate(R.id.action_qrResultFragment_to_qrScanFragment);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
binding = FragmentQrResultBinding.bind(view);
|
||||||
|
|
||||||
viewModel = new ViewModelProvider(this).get(QrResultViewModel.class);
|
viewModel = new ViewModelProvider(this).get(QrResultViewModel.class);
|
||||||
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||||
if (state.getErrorMessage() == null && state.isOpened()) {
|
if (state.getErrorMessage() == null && state.isOpened()) {
|
||||||
binding.result.setText(R.string.door_opened);
|
binding.result.setText(R.string.door_opened);
|
||||||
} else {
|
} else if (state.getErrorMessage() != null) {
|
||||||
binding.result.setText(R.string.error);
|
binding.result.setText(R.string.error);
|
||||||
Toast.makeText(getContext(), state.getErrorMessage(), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), state.getErrorMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
binding.result.setText(R.string.error);
|
||||||
|
Toast.makeText(getContext(), "error", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -60,9 +70,16 @@ public class QrResultFragment extends Fragment {
|
|||||||
SharedPreferences sharedPreferences = getContext().getSharedPreferences("login", Context.MODE_PRIVATE);
|
SharedPreferences sharedPreferences = getContext().getSharedPreferences("login", Context.MODE_PRIVATE);
|
||||||
String login = sharedPreferences.getString("login", null);
|
String login = sharedPreferences.getString("login", null);
|
||||||
if (login != null && getView() != null) {
|
if (login != null && getView() != null) {
|
||||||
viewModel.update(login, resultQr);
|
viewModel.update(login, "12314543654745676");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.close.setOnClickListener(v -> {
|
||||||
|
if (getView() != null) {
|
||||||
|
Navigation.findNavController(getView()).navigate(
|
||||||
|
R.id.action_qrResultFragment_to_userFragment);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,7 @@ data object QrScanDestination {
|
|||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun packToBundle(data: String): Bundle {
|
internal fun packToBundle(data: String): Bundle {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.myitschool.work.ui.qr.scan
|
package ru.myitschool.work.ui.qr.scan
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.camera.core.ImageAnalysis
|
import androidx.camera.core.ImageAnalysis
|
||||||
@ -65,6 +66,7 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
|
|||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
is QrScanViewModel.Action.CloseWithResult -> {
|
is QrScanViewModel.Action.CloseWithResult -> {
|
||||||
|
Log.d("result", action.result)
|
||||||
sendResult(QrScanDestination.packToBundle(action.result))
|
sendResult(QrScanDestination.packToBundle(action.result))
|
||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@
|
|||||||
android:id="@+id/userFragment"
|
android:id="@+id/userFragment"
|
||||||
android:name="ru.myitschool.work.ui.profile.UserFragment"
|
android:name="ru.myitschool.work.ui.profile.UserFragment"
|
||||||
android:label="UserFragment" >
|
android:label="UserFragment" >
|
||||||
<action
|
|
||||||
android:id="@+id/action_userFragment_to_qrScanFragment"
|
|
||||||
app:destination="@id/qrScanFragment" />
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_userFragment_to_loginFragment"
|
android:id="@+id/action_userFragment_to_loginFragment"
|
||||||
app:destination="@id/loginFragment" />
|
app:destination="@id/loginFragment" />
|
||||||
@ -23,8 +20,8 @@
|
|||||||
android:name="ru.myitschool.work.ui.qr.scan.QrScanFragment"
|
android:name="ru.myitschool.work.ui.qr.scan.QrScanFragment"
|
||||||
android:label="QrScanFragment" >
|
android:label="QrScanFragment" >
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_qrScanFragment_to_userFragment"
|
android:id="@+id/action_qrScanFragment_to_qrResultFragment"
|
||||||
app:destination="@id/userFragment" />
|
app:destination="@id/qrResultFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/loginFragment"
|
android:id="@+id/loginFragment"
|
||||||
@ -41,5 +38,8 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_qrResultFragment_to_userFragment"
|
android:id="@+id/action_qrResultFragment_to_userFragment"
|
||||||
app:destination="@id/userFragment" />
|
app:destination="@id/userFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_qrResultFragment_to_qrScanFragment"
|
||||||
|
app:destination="@id/qrScanFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
Loading…
x
Reference in New Issue
Block a user