feat: History is working, small changes in Login

This commit is contained in:
SunZar 2025-02-20 14:42:33 +03:00
parent ae7a743d41
commit d5a49dfa1e
21 changed files with 213 additions and 148 deletions

View File

@ -62,13 +62,13 @@ public class UserRepositoryImpl implements UserRepository, SignUserRepository {
historiesDto -> {
ArrayList<HistoryEntity> result1 = new ArrayList<>(historiesDto.size());
for (HistoryDto history : historiesDto) {
final Integer id1 = history.id;
final Long id1 = history.id;
final String username1 = history.username;
final Long time = history.time;
final String time = history.time;
final String type = history.type;
final Integer code = history.code;
final Long code = history.code;
if (username1 != null && id1 != null){
result1.add(new HistoryEntity(id1, username1, time, type, code));
result1.add(new HistoryEntity(id1, username1, type, time, code));
}
}
return result1;
@ -111,13 +111,14 @@ public class UserRepositoryImpl implements UserRepository, SignUserRepository {
callback,
user -> {
if (user != null) {
final Integer id1 = user.id;
final String username1 = user.username;
final String name = user.name;
final String photo = user.photo;
final Long lastVisit = user.lastVisit;
final Integer idUser = user.idUser;
final String position = user.position;
if (idUser != null && username != null){
return new UserEntity(username1, photo, lastVisit, idUser, position);
final String authority = user.authority;
if (id1 != null && username != null){
return new UserEntity(id1, username1, name, photo, position, authority);
}
else{
return null;

View File

@ -7,7 +7,7 @@ import com.google.gson.annotations.SerializedName;
public class HistoryDto {
@Nullable
@SerializedName("id")
public Integer id;
public Long id;
@Nullable
@SerializedName("username")
@ -15,7 +15,7 @@ public class HistoryDto {
@Nullable
@SerializedName("time")
public Long time;
public String time;
@Nullable
@SerializedName("type")
@ -23,6 +23,6 @@ public class HistoryDto {
@Nullable
@SerializedName("code")
public Integer code;
public Long code;
}

View File

@ -5,35 +5,32 @@ import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
public class UserDto {
@Nullable
@SerializedName("id")
public Integer id;
@Nullable
@SerializedName("username")
public String username;
@Nullable
@SerializedName("password")
public String password;
@SerializedName("name")
public String name;
@Nullable
@SerializedName("photo")
public String photo;
@Nullable
@SerializedName("lastVisit")
public Long lastVisit;
@Nullable
@SerializedName("idUser")
public Integer idUser;
@Nullable
@SerializedName("status")
public int status;
@Nullable
@SerializedName("position")
public String position;
public UserDto(@Nullable String username, @Nullable String password, @Nullable String photo, @Nullable Long lastVisit, @Nullable Integer idUser, int status, @Nullable String position) {
@Nullable
@SerializedName("authority")
public String authority;
/*public UserDto(@Nullable String username, @Nullable String password, @Nullable String photo, @Nullable Long lastVisit, @Nullable Integer idUser, int status, @Nullable String position) {
this.username = username;
this.password = password;
this.photo = photo;
@ -108,7 +105,7 @@ public class UserDto {
*/

View File

@ -15,14 +15,14 @@ import ru.myitschool.work.ui.History;
public interface UserApi {
@GET("api/user")
Call<List<UserDto>> getAllUsers();
@GET("api/user/{id}")
@GET("api/user/{id}")
Call<UserDto> getUserByUsername(@Path("username") String Username);
@GET("api/user/username/{username}")
Call<UserDto> isExistUser(@Path("username") String username);
@GET("api/user/login")
@GET("api/{username}/auth")
Call<Void> isExistUser(@Path("username") String username);
@GET("api/login")
Call<Void> login();
@GET("api/history/user/{id}")
Call<List<HistoryDto>> getAllUserHistory(@Path("id") String username);
@GET("api/{username}/passing")
Call<List<HistoryDto>> getAllUserHistory(@Path("username") String username);
/* @GET("api/history/{id}")
Call<HistoryDto> getHistoryById(@Path("id") Integer id);
*/

View File

@ -7,14 +7,14 @@ import com.google.gson.annotations.SerializedName;
public class HistoryEntity {
@Nullable
@SerializedName("id")
public Integer id;
public Long id;
@Nullable
public Integer getId() {
public Long getId() {
return id;
}
public void setId(@Nullable Integer id) {
public void setId(@Nullable Long id) {
this.id = id;
}
@ -28,11 +28,11 @@ public class HistoryEntity {
}
@Nullable
public Long getTime() {
public String getTime() {
return time;
}
public void setTime(@Nullable Long time) {
public void setTime(@Nullable String time) {
this.time = time;
}
@ -46,19 +46,19 @@ public class HistoryEntity {
}
@Nullable
public Integer getCode() {
public Long getCode() {
return code;
}
public void setCode(@Nullable Integer code) {
public void setCode(@Nullable Long code) {
this.code = code;
}
public HistoryEntity(@Nullable Integer id, @Nullable String username, @Nullable Long time, @Nullable String type, @Nullable Integer code) {
public HistoryEntity(@Nullable Long id, @Nullable String username, @Nullable String type, @Nullable String time, @Nullable Long code) {
this.id = id;
this.username = username;
this.time = time;
this.type = type;
this.time = time;
this.code = code;
}
@ -68,7 +68,7 @@ public class HistoryEntity {
@Nullable
@SerializedName("time")
public Long time;
public String time;
@Nullable
@SerializedName("type")
@ -76,6 +76,6 @@ public class HistoryEntity {
@Nullable
@SerializedName("code")
public Integer code;
public Long code;
}

View File

@ -15,32 +15,37 @@ public class UserEntity {
public String username;
@Nullable
@SerializedName("photo")
public String photo;
@SerializedName("name")
public String name;
@Nullable
@SerializedName("lastVisit")
public Long lastVisit;
@SerializedName("photo")
public String photo;
@Nullable
@SerializedName("position")
public String position;
public UserEntity(@Nullable String username, @Nullable String photo, @Nullable Long lastVisit, @Nullable Integer id, @Nullable String position) {
this.username = username;
this.photo = photo;
this.lastVisit = lastVisit;
@Nullable
@SerializedName("authority")
public String authority;
public UserEntity(@Nullable Integer id, @Nullable String username, @Nullable String name, @Nullable String photo, @Nullable String position, @Nullable String authority) {
this.id = id;
this.username = username;
this.name = name;
this.photo = photo;
this.position = position;
this.authority = authority;
}
@Nullable
public String getPosition() {
return position;
public Integer getId() {
return id;
}
public void setPosition(@Nullable String position) {
this.position = position;
public void setId(@Nullable Integer id) {
this.id = id;
}
@Nullable
@ -52,6 +57,15 @@ public class UserEntity {
this.username = username;
}
@Nullable
public String getName() {
return name;
}
public void setName(@Nullable String name) {
this.name = name;
}
@Nullable
public String getPhoto() {
return photo;
@ -62,21 +76,20 @@ public class UserEntity {
}
@Nullable
public Long getLastVisit() {
return lastVisit;
public String getPosition() {
return position;
}
public void setLastVisit(@Nullable Long lastVisit) {
this.lastVisit = lastVisit;
public void setPosition(@Nullable String position) {
this.position = position;
}
@Nullable
public Integer getId() {
return id;
public String getAuthority() {
return authority;
}
public void setId(@Nullable Integer id) {
this.id = id;
public void setAuthority(@Nullable String authority) {
this.authority = authority;
}
}

View File

@ -10,7 +10,7 @@ import ru.myitschool.work.domain.entities.Status;
public interface SignUserRepository {
void getUserByUsername(@NonNull String username, Consumer<Status<UserEntity>> callback);
void isExistUser(@NonNull String login, Consumer<Status<Void>> callback);
void isExistUser(@NonNull String username, Consumer<Status<Void>> callback);
void login(
@NonNull String username,

View File

@ -56,9 +56,12 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold
}
public void bind(HistoryEntity item) {
binding.time.setText(item.getTime().toString().substring(0, 10) + " "
+ item.getTime().toString().substring(11, 16));
binding.nameReader.setText(item.getType());
//binding.time.setText(item.getTime().toString().substring(0, 10) + " "
//+ item.getTime().toString().substring(11, 16));
//binding.nameReader.setText(item.getType());
binding.time.setText(item.getTime());
binding.code.setText(item.getCode().toString());
binding.type.setText(item.getType());
/*if (item.getType() == 1){
binding.type.setText("QR-code");
}

View File

@ -59,12 +59,13 @@ public class InformationFragment extends Fragment {
//sharedPreferences = getContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE);
preferenceManager = new PreferenceManager(this.getContext());
username = preferenceManager.getString(Constants.KEY_USER_USERNAME);
Toast.makeText(getContext(), username, Toast.LENGTH_SHORT).show();
viewModel = new ViewModelProvider(this).get(InformationViewModel.class);
//getInformation();
binding.scan.setOnClickListener(view1 -> {
onClickScan(view);
});
// binding.scan.setOnClickListener(view1 -> {
// onClickScan(view);
// });
binding.logout.setOnClickListener(view2 -> {
onClickLogout(view);
@ -120,8 +121,9 @@ public class InformationFragment extends Fragment {
binding.loading.setVisibility(Utils.visibleOrGone(loadingHistory));
//binding.loading.setVisibility(Utils.visibleOrGone(loadingHistory));
if (state.isLoading() == false) {
binding.refreshLayout.setRefreshing(false);
if (state.getItemsHistory() != null) {
history = state.getItemsHistory();
@ -138,12 +140,12 @@ public class InformationFragment extends Fragment {
historyAdapter.updateData(history);
historyAdapter.notifyDataSetChanged();
binding.refreshLayout.setRefreshing(false);
} else {
Toast.makeText(this.getContext(), "Error", Toast.LENGTH_SHORT).show();
takeError();
}
} else {
Toast.makeText(this.getContext(), "Error", Toast.LENGTH_SHORT).show();
takeError();
}
binding.refreshLayout.setRefreshing(false);
//binding.refreshLayout.setRefreshing(false);
});
/*
viewModel.stateHistoryLiveData.observe(getViewLifecycleOwner(), state -> {
@ -250,7 +252,7 @@ public class InformationFragment extends Fragment {
binding.lastEntry.setVisibility(View.GONE);
binding.position.setVisibility(View.GONE);
//binding.logout.setVisibility(View.GONE);
binding.scan.setVisibility(View.GONE);
//binding.scan.setVisibility(View.GONE);
binding.error.setVisibility(View.VISIBLE);
binding.refreshLayout.setRefreshing(false);

View File

@ -35,11 +35,11 @@ public class InformationViewModel extends ViewModel {
private String username;
public void changeSelectedUsername(@NonNull String username) {
this.username = this.username;
this.username = username;
}
public void load() {
mutableStateAllUserHistoryLiveData.setValue(new InformationViewModel.State(null, null, false));
mutableStateAllUserHistoryLiveData.setValue(new InformationViewModel.State(null, null, true));
getHistById();
/*getAllUserHistoryUseCase.execute(username, status -> {
mutableStateHistoryLiveData.postValue(fromStatus(status));

View File

@ -23,10 +23,10 @@ import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import ru.myitschool.work.R;
import ru.myitschool.work.core.Constants;
import ru.myitschool.work.databinding.FragmentLoginBinding;
import ru.myitschool.work.ui.StoreAPI;
import ru.myitschool.work.ui.login.LoginViewModel;
import ru.myitschool.work.utils.Constants;
import ru.myitschool.work.utils.OnChangeText;
import ru.myitschool.work.utils.PreferenceManager;
@ -135,7 +135,7 @@ public class LoginFragment extends Fragment {
subscribe(viewModel);
}
private void onClickLogin(View view) {
/*private void onClickLogin(View view) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.SERVER_ADDRESS)
.addConverterFactory(GsonConverterFactory.create())
@ -171,7 +171,7 @@ public class LoginFragment extends Fragment {
binding.error.setVisibility(View.VISIBLE);
}
});
}
}*/
private void subscribe(LoginViewModel viewModel) {
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error -> {
@ -184,8 +184,10 @@ public class LoginFragment extends Fragment {
});*/
viewModel.openListLiveData.observe(getViewLifecycleOwner(), username -> {
final View view = getView();
Toast.makeText(getContext(), "FFFFFFFFF", Toast.LENGTH_SHORT).show();
if (view == null) return;
preferenceManager.putString(ru.myitschool.work.utils.Constants.KEY_USER_USERNAME, username);
preferenceManager.putString(Constants.KEY_USER_USERNAME, username);
preferenceManager.putString(Constants.KEY_USER_ROLE, username);
view.getRootView().findViewById(R.id.nav_view).setVisibility(View.VISIBLE);
Navigation.findNavController(view).navigate(R.id.action_loginFragment_to_informationFragment);
});

View File

@ -59,11 +59,12 @@ public class LoginViewModel extends ViewModel {
}
public void confirm() {
if (userCheckCompleted) {
loginUser(username, password);
/*if (userCheckCompleted) {
checkAuth();
} else {
checkUserExist();
}
}*/
}
@ -72,14 +73,17 @@ public class LoginViewModel extends ViewModel {
final String currentPassword = password;
if (currentPassword == null || currentPassword.isEmpty()) {
mutableErrorLiveData.postValue("Password cannot be null");
userCheckCompleted = false;
return;
}
if (currentUsername == null || currentUsername.isEmpty()) {
mutableErrorLiveData.postValue("Login cannot be null");
userCheckCompleted = false;
return;
}
if (!isAccountExist) {
mutableErrorLiveData.postValue("This user not exist");
userCheckCompleted = false;
return;
/*createUserUseCase.execute(currentUsername, currentPassword, status -> {
if (status.getStatusCode() == 201 && status.getErrors() == null) {
@ -101,6 +105,7 @@ public class LoginViewModel extends ViewModel {
mutableOpenListLiveData.postValue(currentUsername);
} else {
mutableErrorLiveData.postValue("Something wrong");
userCheckCompleted = false;
}
});
}
@ -109,12 +114,14 @@ public class LoginViewModel extends ViewModel {
final String currentUsername = username;
if (currentUsername == null || currentUsername.isEmpty()) {
mutableErrorLiveData.postValue("Login cannot be null");
userCheckCompleted = false;
return;
}
isUserExistUseCase.execute(currentUsername, status -> {
if (status.getErrors() != null) {
//Log.d("tagg", status.getErrors().toString());
mutableErrorLiveData.postValue("Something wrong. Try later =(" + status.getErrors());
userCheckCompleted = false;
return;
}
userCheckCompleted = true;

View File

@ -40,7 +40,7 @@ public class ProfileFragment extends Fragment {
binding.username.setText(userEntity.getUsername());
binding.position.setText(userEntity.getPosition());
binding.lastTime.setText(userEntity.getLastVisit().toString());
binding.lastTime.setText(userEntity.getName());
});

View File

@ -24,9 +24,9 @@ public class ProfileViewModel extends ViewModel {
UserRepositoryImpl.getInstance()
);
public final GetAllUserHistoryUseCase getAllUserHistoryListUseCase = new GetAllUserHistoryUseCase(
/*public final GetAllUserHistoryUseCase getAllUserHistoryListUseCase = new GetAllUserHistoryUseCase(
UserRepositoryImpl.getInstance()
);
);*/
private final IsUserExistUseCase isUserExistUseCase = new IsUserExistUseCase(
UserRepositoryImpl.getInstance()
);

View File

@ -3,6 +3,8 @@ package ru.myitschool.work.utils;
public class Constants {
public static final String KEY_PREFERENCE_NAME = "App";
public static final String KEY_USER_USERNAME = "userUsername";
public static final String KEY_USER_ROLE = "userRole";
public static final String KEY_USER_BLOCKED = "userBlocked";
public static String KEY_LOGIN = "login";
public static String KEY_RESULT = "result";
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -51,50 +52,36 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/refresh"
android:text="@string/refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/logout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/scan"
android:text="@string/scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/refresh"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/error"
android:visibility="gone"
android:text="@string/error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/scan"
app:layout_constraintTop_toBottomOf="@id/logout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.recyclerview.widget.RecyclerView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/historylist"
android:layout_gravity="center"
/>
<ProgressBar
android:id="@+id/loading"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/error"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/historylist"
tools:listitem="@layout/item_history"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf="@id/error"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,39 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/time"
android:layout_width="match_parent"
<LinearLayout
android:id="@+id/layout_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:tag="iuroi"/>
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/nameReader"
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textSize="16sp"
android:text="@string/time"/>
<TextView
android:id="@+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:text="iuroxsssssi"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:text="kijt"
app:layout_constraintBottom_toBottomOf="@+id/time"
app:layout_constraintStart_toEndOf="@id/time"
app:layout_constraintTop_toTopOf="parent" />
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_time">
<TextView
android:id="@+id/type"
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textSize="16sp"
android:text="@string/code"/>
<TextView
android:id="@+id/code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:text="iuroxsssssi"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:text="hgfdfbjdhf"
app:layout_constraintBottom_toBottomOf="@+id/time"
app:layout_constraintStart_toEndOf="@id/nameReader"
app:layout_constraintTop_toTopOf="parent" />
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_code">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textSize="16sp"
android:text="@string/type"/>
<TextView
android:id="@+id/type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:text="iuroxsssssi"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -12,4 +12,8 @@
<string name="cancelled">Operation was cancelled</string>
<string name="success">Success</string>
<string name="wrong">Something wrong</string>
<string name="time">Time:</string>
<string name="type">Enter type:</string>
<string name="code">Identificator:</string>
</resources>

View File

@ -12,4 +12,7 @@
<string name="cancelled">Вход был отменён</string>
<string name="success">Успешно</string>
<string name="wrong">Что-то пошло не так</string>
<string name="time">Время:</string>
<string name="type">Тип прохода:</string>
<string name="code">Идентификатор:</string>
</resources>

View File

@ -12,4 +12,8 @@
<string name="cancelled">Вход был отменён</string>
<string name="success">Успешно</string>
<string name="wrong">Что-то пошло не так</string>
<string name="time">Время:</string>
<string name="type">Тип прохода:</string>
<string name="code">Идентификатор:</string>
</resources>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="close_button">Close</string>
<string name="close_button" translatable="false">Close</string>
</resources>