added Admin
This commit is contained in:
parent
ae7a743d41
commit
6edfdf475e
@ -116,8 +116,9 @@ public class UserRepositoryImpl implements UserRepository, SignUserRepository {
|
||||
final Long lastVisit = user.lastVisit;
|
||||
final Integer idUser = user.idUser;
|
||||
final String position = user.position;
|
||||
final boolean action = user.action;
|
||||
if (idUser != null && username != null){
|
||||
return new UserEntity(username1, photo, lastVisit, idUser, position);
|
||||
return new UserEntity(username1, photo, lastVisit, idUser, position, action);
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.myitschool.work.data.dto;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@ -33,7 +34,18 @@ public class UserDto {
|
||||
@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("action")
|
||||
public boolean action;
|
||||
|
||||
@Nullable
|
||||
public boolean getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public UserDto(@Nullable String username, @Nullable String password, @Nullable String photo,
|
||||
@Nullable Long lastVisit, @Nullable Integer idUser, int status,
|
||||
@Nullable String position, @NonNull boolean action) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.photo = photo;
|
||||
@ -41,6 +53,7 @@ public class UserDto {
|
||||
this.idUser = idUser;
|
||||
this.status = status;
|
||||
this.position = position;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.myitschool.work.domain.entities;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@ -25,13 +26,22 @@ public class UserEntity {
|
||||
@Nullable
|
||||
@SerializedName("position")
|
||||
public String position;
|
||||
@Nullable
|
||||
@SerializedName("action")
|
||||
public boolean action;
|
||||
|
||||
public UserEntity(@Nullable String username, @Nullable String photo, @Nullable Long lastVisit, @Nullable Integer id, @Nullable String position) {
|
||||
@Nullable
|
||||
public boolean getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public UserEntity(@Nullable String username, @Nullable String photo, @Nullable Long lastVisit, @Nullable Integer id, @Nullable String position, @NonNull boolean action) {
|
||||
this.username = username;
|
||||
this.photo = photo;
|
||||
this.lastVisit = lastVisit;
|
||||
this.id = id;
|
||||
this.position = position;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -4,15 +4,22 @@ import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
|
||||
import ru.myitschool.work.R;
|
||||
import ru.myitschool.work.databinding.ActivityRootBinding;
|
||||
import ru.myitschool.work.databinding.FragmentProfileBinding;
|
||||
import ru.myitschool.work.domain.entities.UserEntity;
|
||||
import ru.myitschool.work.ui.profile.ProfileViewModel;
|
||||
import ru.myitschool.work.utils.PreferenceManager;
|
||||
|
||||
public class RootActivity extends AppCompatActivity {
|
||||
private ActivityRootBinding binding;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -30,6 +37,7 @@ public class RootActivity extends AppCompatActivity {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void onClickNavHistory() {
|
||||
|
@ -1,4 +1,62 @@
|
||||
package ru.myitschool.work.ui.admin;
|
||||
|
||||
public class AdminFragment {
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import ru.myitschool.work.R;
|
||||
import ru.myitschool.work.databinding.FragmentAdminBinding;
|
||||
import ru.myitschool.work.databinding.FragmentProfileBinding;
|
||||
import ru.myitschool.work.domain.GetUserByUsernameUseCase;
|
||||
import ru.myitschool.work.domain.entities.UserEntity;
|
||||
import ru.myitschool.work.ui.profile.ProfileViewModel;
|
||||
import ru.myitschool.work.utils.Constants;
|
||||
import ru.myitschool.work.utils.PreferenceManager;
|
||||
|
||||
public class AdminFragment extends Fragment {
|
||||
private static final String KEY_USER_USERNAME = "username";
|
||||
|
||||
private FragmentAdminBinding binding;
|
||||
private PreferenceManager preferenceManager;
|
||||
private AdminViewModel viewModel;
|
||||
|
||||
public AdminFragment() {
|
||||
super(R.layout.fragment_admin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
binding = FragmentAdminBinding.bind(view);
|
||||
preferenceManager = new PreferenceManager(this.getContext());
|
||||
viewModel = new ViewModelProvider(this).get(AdminViewModel.class);
|
||||
binding.searchButton.setOnClickListener(view1 -> {
|
||||
String usernameSearch = binding.search.getText().toString();
|
||||
// TODO : к базе
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
binding = null;
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
public static Bundle getBundle(@NonNull String id) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_USER_USERNAME, id);
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,91 @@
|
||||
package ru.myitschool.work.ui.admin;
|
||||
|
||||
public class AdminViewModel {
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.myitschool.work.data.UserRepositoryImpl;
|
||||
import ru.myitschool.work.domain.GetAllUserHistoryUseCase;
|
||||
import ru.myitschool.work.domain.GetUserByUsernameUseCase;
|
||||
import ru.myitschool.work.domain.entities.HistoryEntity;
|
||||
import ru.myitschool.work.domain.entities.Status;
|
||||
import ru.myitschool.work.domain.sign.IsUserExistUseCase;
|
||||
import ru.myitschool.work.ui.information.InformationViewModel;
|
||||
import ru.myitschool.work.ui.profile.ProfileViewModel;
|
||||
|
||||
public class AdminViewModel extends ViewModel {
|
||||
private final MutableLiveData<AdminViewModel.State> mutableStateLiveData = new MutableLiveData<>();
|
||||
|
||||
public final LiveData<AdminViewModel.State> stateLiveData = mutableStateLiveData;
|
||||
|
||||
public final GetUserByUsernameUseCase getUserByUsernameUseCase = new GetUserByUsernameUseCase(
|
||||
UserRepositoryImpl.getInstance()
|
||||
);
|
||||
|
||||
public final GetAllUserHistoryUseCase getAllUserHistoryListUseCase = new GetAllUserHistoryUseCase(
|
||||
UserRepositoryImpl.getInstance()
|
||||
);
|
||||
private final IsUserExistUseCase isUserExistUseCase = new IsUserExistUseCase(
|
||||
UserRepositoryImpl.getInstance()
|
||||
);
|
||||
|
||||
public void load(@NonNull String username) {
|
||||
mutableStateLiveData.setValue(new AdminViewModel.State(null, null, true));
|
||||
postUserByUsername(username);
|
||||
}
|
||||
|
||||
private void postUserByUsername(String username) {
|
||||
final String currentUsername = username;
|
||||
if (currentUsername == null || currentUsername.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
isUserExistUseCase.execute(currentUsername, status -> {
|
||||
if (status.getValue() == null || status.getErrors() != null) {
|
||||
Log.d("tagg", status.getErrors().toString());
|
||||
}
|
||||
|
||||
});
|
||||
getUserByUsernameUseCase.execute(currentUsername, status ->{
|
||||
if (status.getValue() == null || status.getErrors() != null) {
|
||||
Log.d("tagg", status.getErrors().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public class State {
|
||||
@Nullable
|
||||
private final String errorMessage;
|
||||
|
||||
@Nullable
|
||||
private final List<HistoryEntity> itemsHistory;
|
||||
|
||||
private final boolean isLoading;
|
||||
|
||||
public State(@Nullable String errorMessage, @Nullable List<HistoryEntity> itemsHistory, boolean isLoading) {
|
||||
this.errorMessage = errorMessage;
|
||||
this.itemsHistory = itemsHistory;
|
||||
this.isLoading = isLoading;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<HistoryEntity> getItemsHistory() {
|
||||
return itemsHistory;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,8 @@ public class InformationViewModel extends ViewModel {
|
||||
UserRepositoryImpl.getInstance()
|
||||
);
|
||||
|
||||
/*public ListViewModel() {
|
||||
update();
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
@ -39,7 +38,7 @@ public class InformationViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
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));
|
||||
|
@ -47,6 +47,7 @@ public class ProfileViewModel extends ViewModel {
|
||||
//mutableErrorLiveData.postValue("Something wrong. Try later =(" + status.getErrors());
|
||||
return;
|
||||
}
|
||||
|
||||
//userCheckCompleted = true;
|
||||
/*if (status.getStatusCode() == 200) {
|
||||
if (status.getValue() != null) {
|
||||
|
@ -24,5 +24,20 @@
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:menu="@menu/bottom_nav_menu"
|
||||
app:labelVisibilityMode="labeled"
|
||||
android:animateLayoutChanges="true"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/qr_scan"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/baseline_qr_code_scanner_24"
|
||||
app:layout_constraintBottom_toTopOf="@+id/nav_view"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:visibility="gone"
|
||||
android:layout_margin="24dp"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user