diff --git a/app/src/main/java/ru/myitschool/work/data/UserResponseImpl.java b/app/src/main/java/ru/myitschool/work/data/UserRepositoryImpl.java similarity index 55% rename from app/src/main/java/ru/myitschool/work/data/UserResponseImpl.java rename to app/src/main/java/ru/myitschool/work/data/UserRepositoryImpl.java index 785d6fb..f8acdc5 100644 --- a/app/src/main/java/ru/myitschool/work/data/UserResponseImpl.java +++ b/app/src/main/java/ru/myitschool/work/data/UserRepositoryImpl.java @@ -15,17 +15,17 @@ import ru.myitschool.work.domain.entities.HistoryEntity; import ru.myitschool.work.domain.entities.Status; import ru.myitschool.work.domain.entities.UserEntity; -public class UserResponseImpl { +public class UserRepositoryImpl { - private static UserResponseImpl INSTANCE; + private static UserRepositoryImpl INSTANCE; private UserApi userApi = RetrofitFactory.getInstance().getUserApi(); private final CredentialsDataSource credentialsDataSource = CredentialsDataSource.getInstance(); - private UserResponseImpl() {} + private UserRepositoryImpl() {} - public static synchronized UserResponseImpl getInstance() { + public static synchronized UserRepositoryImpl getInstance() { if (INSTANCE == null) { - INSTANCE = new UserResponseImpl(); + INSTANCE = new UserRepositoryImpl(); } return INSTANCE; } @@ -52,11 +52,11 @@ public class UserResponseImpl { } - public void getAllUserHistory(@NonNull Integer id, @NonNull Consumer>> callback) { + public void getAllUserHistory(@NonNull Integer id, @NonNull Consumer>> callback) { userApi.getAllUserHistory(id).enqueue(new CallToConsumer<>( callback, historiesDto -> { - ArrayList result = new ArrayList<>(historiesDto.size()); + ArrayList result1 = new ArrayList<>(historiesDto.size()); for (HistoryDto history : historiesDto) { final Integer id1 = history.id; final Integer idUser = history.idUser; @@ -64,14 +64,59 @@ public class UserResponseImpl { final String nameReader = history.nameReader; final String type = history.type; if (idUser != null && id1 != null){ - result.add(new HistoryEntity(id1, idUser, time, nameReader, type)); + result1.add(new HistoryEntity(id1, idUser, time, nameReader, type)); } } - return result; + return result1; } )); + } + /* public void getHistoryById(@NonNull Integer id, @NonNull Consumer>> callback){ + userApi.getHistoryById(id).enqueue(new CallToConsumer<>( + callback, + historiesDto -> { + final Integer id1 = historiesDto.id; + final Integer idUser = historiesDto.idUser; + final Long time = historiesDto.time; + final String nameReader = historiesDto.nameReader; + final String type = historiesDto.type; + if (id1 != null && idUser != null){ + HistoryEntity historyEntity = new HistoryEntity(id1, idUser, time, nameReader, type); + return historyEntity; + } + else{ + return null; + } + + }; + } */ + + public void isExistUser(@NonNull String username, Consumer> callback) { + userApi.isUserExist(username).enqueue(new CallToConsumer<>( + callback, + user -> { + if (user != null) { + final String username1 = user.username; + 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); + } + else{ + return null; + } + } + else{ + return null; + } + } + )); + } + public void login(@NonNull String username, @NonNull String password, Consumer> callback) { credentialsDataSource.updateLogin(username, password); userApi = RetrofitFactory.getInstance().getUserApi(); diff --git a/app/src/main/java/ru/myitschool/work/data/source/UserApi.java b/app/src/main/java/ru/myitschool/work/data/source/UserApi.java index 61f40c4..cae5ff1 100644 --- a/app/src/main/java/ru/myitschool/work/data/source/UserApi.java +++ b/app/src/main/java/ru/myitschool/work/data/source/UserApi.java @@ -15,15 +15,15 @@ import ru.myitschool.work.ui.History; public interface UserApi { @GET("api/user") Call> getAllUsers(); - @GET("api/user/{id}") - Call getUserById(@Path("id") Integer id); + /* @GET("api/user/{id}") + Call getUserById(@Path("id") Integer id); */ @GET("api/user/username/{username}") Call isUserExist(@Path("username") String username); @GET("api/user/login") Call login(); @GET("api/history/user/{id}") Call> getAllUserHistory(@Path("id") Integer id); - @GET("api/history/{id}") + /* @GET("api/history/{id}") Call getHistoryById(@Path("id") Integer id); - +*/ } diff --git a/app/src/main/res/layout/fragment_admin.xml b/app/src/main/res/layout/fragment_admin.xml new file mode 100644 index 0000000..3f2847f --- /dev/null +++ b/app/src/main/res/layout/fragment_admin.xml @@ -0,0 +1,34 @@ + + + + + +