feat: last

This commit is contained in:
SunZar 2025-02-20 16:55:34 +03:00
parent 1daf04e716
commit b862af7143
23 changed files with 436 additions and 118 deletions

View File

@ -0,0 +1,82 @@
kotlin version: 2.0.21
error message: Daemon compilation failed: null
java.lang.Exception
at org.jetbrains.kotlin.daemon.common.CompileService$CallResult$Error.get(CompileService.kt:69)
at org.jetbrains.kotlin.daemon.common.CompileService$CallResult$Error.get(CompileService.kt:65)
at org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.compileWithDaemon(GradleKotlinCompilerWork.kt:240)
at org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.compileWithDaemonOrFallbackImpl(GradleKotlinCompilerWork.kt:159)
at org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.run(GradleKotlinCompilerWork.kt:111)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction.execute(GradleCompilerRunnerWithWorkers.kt:76)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:209)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59)
at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$0(DefaultWorkerExecutor.java:174)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:195)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:128)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:170)
at org.gradle.internal.Factories$1.create(Factories.java:31)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:267)
at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:131)
at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:136)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:165)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:134)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.nio.file.DirectoryNotEmptyException: C:\Users\User\AppData\Local\Temp\kotlin-backups16499515935208141936
at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(Unknown Source)
at java.base/java.nio.file.Files.delete(Unknown Source)
at org.jetbrains.kotlin.incremental.RecoverableCompilationTransaction$cleanupStash$2$1$1.invoke(CompilationTransaction.kt:244)
at org.jetbrains.kotlin.incremental.RecoverableCompilationTransaction$cleanupStash$2$1$1.invoke(CompilationTransaction.kt:244)
at org.jetbrains.kotlin.incremental.RecoverableCompilationTransaction.cleanupStash$lambda$11$lambda$10$lambda$9(CompilationTransaction.kt:244)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
at java.base/java.util.ArrayList.forEach(Unknown Source)
at java.base/java.util.stream.SortedOps$RefSortingSink.end(Unknown Source)
at java.base/java.util.stream.Sink$ChainedReference.end(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.forEach(Unknown Source)
at org.jetbrains.kotlin.incremental.RecoverableCompilationTransaction.cleanupStash(CompilationTransaction.kt:244)
at org.jetbrains.kotlin.incremental.RecoverableCompilationTransaction.close(CompilationTransaction.kt:254)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.tryCompileIncrementally(IncrementalCompilerRunner.kt:747)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:120)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:675)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1660)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
... 3 more

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.function.Consumer;
import ru.myitschool.work.data.dto.HistoryDto;
import ru.myitschool.work.data.dto.PassingDto;
import ru.myitschool.work.data.dto.UserDto;
import ru.myitschool.work.data.network.RetrofitFactory;
import ru.myitschool.work.data.source.CredentialsDataSource;
@ -66,7 +67,7 @@ public class UserRepositoryImpl implements UserRepository, SignUserRepository {
final String username1 = history.username;
final String time = history.time;
final String type = history.type;
final Long code = history.code;
final String code = history.code;
if (username1 != null && id1 != null){
result1.add(new HistoryEntity(id1, username1, type, time, code));
}
@ -77,6 +78,14 @@ public class UserRepositoryImpl implements UserRepository, SignUserRepository {
}
@Override
public void createHistory(@NonNull String username, @NonNull String type, @NonNull String time, @NonNull String code, Consumer<Status<Void>> callback) {
userApi.postNewHistory(new PassingDto(username, type, time, code), username).enqueue(new CallToConsumer<>(
callback,
dto -> null
));
}
@Override
public void isExistUser(@NonNull String username, Consumer<Status<Void>> callback) {
userApi.isExistUser(username).enqueue(new CallToConsumer<>(

View File

@ -23,6 +23,6 @@ public class HistoryDto {
@Nullable
@SerializedName("code")
public Long code;
public String code;
}

View File

@ -0,0 +1,31 @@
package ru.myitschool.work.data.dto;
import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
public class PassingDto {
public PassingDto(@Nullable String username, @Nullable String time, @Nullable String type, @Nullable String code) {
this.username = username;
this.time = time;
this.type = type;
this.code = code;
}
@Nullable
@SerializedName("username")
public String username;
@Nullable
@SerializedName("time")
public String time;
@Nullable
@SerializedName("type")
public String type;
@Nullable
@SerializedName("code")
public String code;
}

View File

@ -30,6 +30,7 @@ public class UserDto {
@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;
@ -101,7 +102,7 @@ public class UserDto {
public void setStatus(int status) {
this.status = status;
}
}*/

View File

@ -37,7 +37,7 @@ public class RetrofitFactory {
private final Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://10.0.2.2:8080/")
.baseUrl("http://10.6.66.85:8080/")
.client(client.build())
.addConverterFactory(GsonConverterFactory.create())
.build();

View File

@ -5,17 +5,16 @@ import java.util.List;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import ru.myitschool.work.data.dto.HistoryDto;
import ru.myitschool.work.data.dto.PassingDto;
import ru.myitschool.work.data.dto.UserDto;
import ru.myitschool.work.ui.History;
public interface UserApi {
@GET("api/user")
Call<List<UserDto>> getAllUsers();
@GET("api/user/{id}")
@GET("api/{username}/info")
Call<UserDto> getUserByUsername(@Path("username") String Username);
@GET("api/{username}/auth")
Call<Void> isExistUser(@Path("username") String username);
@ -23,6 +22,8 @@ public interface UserApi {
Call<Void> login();
@GET("api/{username}/passing")
Call<List<HistoryDto>> getAllUserHistory(@Path("username") String username);
@GET("api/{username}/passing/new")
Call<Void> postNewHistory(@Body PassingDto dto, @Path("username") String username);
/* @GET("api/history/{id}")
Call<HistoryDto> getHistoryById(@Path("id") Integer id);
*/

View File

@ -0,0 +1,25 @@
package ru.myitschool.work.domain;
import androidx.annotation.NonNull;
import java.util.function.Consumer;
import ru.myitschool.work.domain.entities.Status;
public class CreateHistoryUseCase {
private final UserRepository repo;
public CreateHistoryUseCase(UserRepository repo) {
this.repo = repo;
}
public void execute(
@NonNull String username,
@NonNull String time,
@NonNull String type,
@NonNull String code,
Consumer<Status<Void>> callback
) {
repo.createHistory(username, time, type, code, callback);
}
}

View File

@ -17,6 +17,13 @@ public interface UserRepository {
//void getVolunteerCenterById(@NonNull Integer id, @NonNull Consumer<Status<HistoryEntity>> callback);
//void isExist(@NonNull String username, @NonNull Consumer<Status<Void>> callback);
//void register(@NonNull String id, @NonNull Consumer<Status<FullUserEntity>> callback);
void createHistory(
@NonNull String username,
@NonNull String type,
@NonNull String time,
@NonNull String code,
Consumer<Status<Void>> callback
);
// void login(@NonNull String username, @NonNull String password, @NonNull Consumer<Status<Void>> callback);
}

View File

@ -46,15 +46,15 @@ public class HistoryEntity {
}
@Nullable
public Long getCode() {
public String getCode() {
return code;
}
public void setCode(@Nullable Long code) {
public void setCode(@Nullable String code) {
this.code = code;
}
public HistoryEntity(@Nullable Long id, @Nullable String username, @Nullable String type, @Nullable String time, @Nullable Long code) {
public HistoryEntity(@Nullable Long id, @Nullable String username, @Nullable String type, @Nullable String time, @Nullable String code) {
this.id = id;
this.username = username;
this.type = type;
@ -76,6 +76,6 @@ public class HistoryEntity {
@Nullable
@SerializedName("code")
public Long code;
public String code;
}

View File

@ -1,35 +0,0 @@
package ru.myitschool.work.ui;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import ru.myitschool.work.R;
import ru.myitschool.work.databinding.FragmentProfileBinding;
import ru.myitschool.work.databinding.FragmentResultBinding;
public class ProfileFragment extends Fragment {
FragmentProfileBinding binding;
SharedPreferences sharedPreferences;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentProfileBinding.inflate(inflater, container, false);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
sharedPreferences = getContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE);
}
}

View File

@ -2,11 +2,14 @@ package ru.myitschool.work.ui;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;
import ru.myitschool.work.R;
@ -14,6 +17,7 @@ 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.ui.qr.scan.QrScanDestination;
import ru.myitschool.work.utils.PreferenceManager;
public class RootActivity extends AppCompatActivity {
@ -38,19 +42,52 @@ public class RootActivity extends AppCompatActivity {
return true;
});
binding.qrScan.setOnClickListener(view -> {
onClickScan();
});
/*getSupportFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, (requestKey, result) -> {
String res = "";
if (result.get(requestKey) != null) {
res = result.get(requestKey).toString();
}
//Toast.makeText(getContext(), res, Toast.LENGTH_LONG).show();
Toast.makeText(this, "EEEEEEEEEEEEEEEEEEEE", Toast.LENGTH_SHORT).show();
//ResultFragment resFragment = ResultFragment.newInstance(res);
//Navigation.findNavController(view).navigate(R.id.action_informationFragment_to_resultFragment);
NavHostFragment navHostFragment =
(NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.root_fragment);
NavController navController = navHostFragment.getNavController();
navController.navigate(R.id.action_informationFragment_to_resultFragment);
//getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, resFragment).commit();
});*/
}
private void onClickScan() {
NavHostFragment navHostFragment =
(NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.root_fragment);
NavController navController = navHostFragment.getNavController();
navController.navigate(R.id.action_informationFragment_to_qrScanFragment);
//getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new QrScanFragment()).commit();
}
private void onClickNavHistory() {
NavHostFragment navHostFragment =
(NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.root_fragment);
NavController navController = navHostFragment.getNavController();
navController.navigate(R.id.action_profileFragment_to_informationFragment);
//navHostFragment.getChildFragmentManager().getFragments().get(0);
switch (navController.getCurrentDestination().getId()) {
// case R.id.historyFragment:
// navController.navigate(R.id.action_listFragment_to_mapFragment);
// break;
case R.id.profileFragment:
navController.navigate(R.id.action_informationFragment_to_profileFragment);
//navController.navigate(R.id.action_profileFragment_to_informationFragment);
//Navigation.findNavController(view).navigate(R.id.action_loginFragment_to_informationFragment);
break;
}
Log.d("tagigi", navController.getCurrentDestination().getId() + "");
@ -62,10 +99,11 @@ public class RootActivity extends AppCompatActivity {
NavHostFragment navHostFragment =
(NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.root_fragment);
NavController navController = navHostFragment.getNavController();
navController.navigate(R.id.action_informationFragment_to_profileFragment);
//navController.navigate(R.id.action_listFragment_to_profileFragment);
switch (navController.getCurrentDestination().getId()) {
case R.id.informationFragment:
navController.navigate(R.id.action_profileFragment_to_informationFragment);
// navController.navigate(R.id.action_informationFragment_to_profileFragment);
break;
// case R.id.profileFragment:
// navController.navigate(R.id.action_mapFragment_to_profileFragment);

View File

@ -59,7 +59,7 @@ 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();
//Toast.makeText(getContext(), username, Toast.LENGTH_SHORT).show();
viewModel = new ViewModelProvider(this).get(InformationViewModel.class);
//getInformation();
@ -80,8 +80,9 @@ public class InformationFragment extends Fragment {
subscribe(viewModel, adapter, view);
//getParentFragmentManager()
requireActivity().getSupportFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, getViewLifecycleOwner(), (requestKey, result) -> {
/*requireActivity().getSupportFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, getViewLifecycleOwner(), (requestKey, result) -> {
String res = "";
if (result.get(requestKey) != null) {
res = result.get(requestKey).toString();
@ -89,11 +90,12 @@ public class InformationFragment extends Fragment {
//Toast.makeText(getContext(), res, Toast.LENGTH_LONG).show();
Toast.makeText(getContext(), "EEEEEEEEEEEEEEEEEEEE", Toast.LENGTH_SHORT).show();
//ResultFragment resFragment = ResultFragment.newInstance(res);
Navigation.findNavController(view).navigate(R.id.action_informationFragment_to_resultFragment);
//getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, resFragment).commit();
});
});*/
viewModel.changeSelectedUsername(username);
viewModel.load();

View File

@ -175,7 +175,7 @@ public class LoginFragment extends Fragment {
private void subscribe(LoginViewModel viewModel) {
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error -> {
Toast.makeText(getContext(), error, Toast.LENGTH_SHORT).show();
//Toast.makeText(getContext(), error, Toast.LENGTH_SHORT).show();
});
/*viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
binding.confirm.setText(state.getButton());
@ -184,11 +184,12 @@ public class LoginFragment extends Fragment {
});*/
viewModel.openListLiveData.observe(getViewLifecycleOwner(), username -> {
final View view = getView();
Toast.makeText(getContext(), "FFFFFFFFF", Toast.LENGTH_SHORT).show();
//Toast.makeText(getContext(), "FFFFFFFFF", Toast.LENGTH_SHORT).show();
if (view == null) return;
preferenceManager.putString(Constants.KEY_USER_USERNAME, username);
preferenceManager.putString(Constants.KEY_USER_ROLE, username);
view.getRootView().findViewById(R.id.nav_view).setVisibility(View.VISIBLE);
view.getRootView().findViewById(R.id.qr_scan).setVisibility(View.VISIBLE);
Navigation.findNavController(view).navigate(R.id.action_loginFragment_to_informationFragment);
});
}

View File

@ -1,7 +1,10 @@
package ru.myitschool.work.ui.profile;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -10,6 +13,7 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;
import ru.myitschool.work.R;
import ru.myitschool.work.databinding.FragmentLoginBinding;
import ru.myitschool.work.databinding.FragmentProfileBinding;
import ru.myitschool.work.domain.entities.HistoryEntity;
import ru.myitschool.work.domain.entities.UserEntity;
@ -29,29 +33,45 @@ public class ProfileFragment extends Fragment {
super(R.layout.fragment_profile);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentProfileBinding.inflate(inflater, container, false);
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding = FragmentProfileBinding.bind(view);
preferenceManager = new PreferenceManager(this.getContext());
viewModel = new ViewModelProvider(this).get(ProfileViewModel.class);
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
final UserEntity userEntity = state.getUser();
binding.username.setText(userEntity.getUsername());
binding.position.setText(userEntity.getPosition());
binding.lastTime.setText(userEntity.getName());
});
subscribe();
binding.exit.setOnClickListener(view2 -> {
preferenceManager.clear();
view.getRootView().findViewById(R.id.nav_view).setVisibility(View.GONE);
Navigation.findNavController(view).navigate(R.id.action_profileFragment_to_informationFragment);
view.getRootView().findViewById(R.id.qr_scan).setVisibility(View.GONE);
Navigation.findNavController(view).navigate(R.id.action_profileFragment_to_loginFragment);
});
viewModel.load(preferenceManager.getString(Constants.KEY_USER_USERNAME));
//Toast.makeText(getContext(), "SSSSSSSSSSS", Toast.LENGTH_SHORT).show();
}
private void subscribe() {
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
final UserEntity userEntity = state.getUser();
if (state.isLoading() == false) {
if (state.getUser() != null && state.getErrorMessage() == null) {
binding.username.setText(userEntity.getUsername());
binding.position.setText(userEntity.getPosition());
binding.name.setText(userEntity.getName());
}
}
});
}
@Override

View File

@ -32,46 +32,46 @@ public class ProfileViewModel extends ViewModel {
);
public void load(@NonNull String username) {
mutableStateLiveData.setValue(new State(null, null, null, true));
mutableStateLiveData.setValue(new State(null, null, true));
postUserByUsername(username);
}
private void postUserByUsername(String username) {
final String currentUsername = username;
if (currentUsername == null || currentUsername.isEmpty()) {
//mutableErrorLiveData.postValue("Login cannot be null");
return;
}
isUserExistUseCase.execute(currentUsername, status -> {
getUserByUsernameUseCase.execute(currentUsername, status -> {
if (status.getValue() == null || status.getErrors() != null) {
Log.d("tagg", status.getErrors().toString());
//mutableErrorLiveData.postValue("Something wrong. Try later =(" + status.getErrors());
return;
}
//userCheckCompleted = true;
/*if (status.getStatusCode() == 200) {
if (status.getValue() != null) {
GetAllUserHistoryUseCase.execute(status.getValue().getStatus(), status2 -> {
Log.d("taggis", status.getStatusCode() + " " + status.getErrors());
if (status.getStatusCode() == 200 && status.getErrors() == null) {
mutableStateLiveData.postValue(new ProfileViewModel.State(
status.getErrors() != null ? status.getErrors().getLocalizedMessage() : null,
status.getValue(),
status2.getValue(),
false
));
} else {
//mutableErrorLiveData.postValue("Something wrong");
}
});
} else {
mutableStateLiveData.postValue(new State(
status.getErrors() != null ? status.getErrors().getLocalizedMessage() : null,
status.getValue(),
null,
false
));
}
if (status.getStatusCode() == 200 && status.getErrors() == null) {
mutableStateLiveData.postValue(new ProfileViewModel.State(
status.getErrors() != null ? status.getErrors().getLocalizedMessage() : null,
status.getValue(),
false
));
} else {
mutableStateLiveData.postValue(new State(
status.getErrors() != null ? status.getErrors().getLocalizedMessage() : null,
null,
false
));
}
//isNewAccount = !status.getValue();
//checkAuth();
/*if(isNewAccount) {
mutableStateLiveData.postValue(
new State(R.string.title_user_new, R.string.button_user_new, true)
);
} else {
mutableStateLiveData.postValue(
new State(R.string.title_user_exist, R.string.button_user_exist, true)
);
}*/
});
}
@ -85,15 +85,12 @@ public class ProfileViewModel extends ViewModel {
@Nullable
private final UserEntity user;
@Nullable
private final HistoryEntity historyEntity;
private final boolean isLoading;
public State(@Nullable String errorMessage, @Nullable UserEntity user, @Nullable HistoryEntity historyEntity, boolean isLoading) {
public State(@Nullable String errorMessage, @Nullable UserEntity user, boolean isLoading) {
this.errorMessage = errorMessage;
this.user = user;
this.historyEntity = historyEntity;
this.isLoading = isLoading;
}
@ -107,11 +104,6 @@ public class ProfileViewModel extends ViewModel {
return user;
}
@Nullable
public HistoryEntity getVolunteerCenter() {
return historyEntity;
}
public boolean isLoading() {
return isLoading;
}

View File

@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResult
import androidx.fragment.app.viewModels
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.Navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.google.mlkit.vision.barcode.BarcodeScanner
@ -21,6 +22,8 @@ import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.barcode.common.Barcode
import ru.myitschool.work.R
import ru.myitschool.work.databinding.FragmentQrScanBinding
import ru.myitschool.work.utils.Constants
import ru.myitschool.work.utils.PreferenceManager
import ru.myitschool.work.utils.collectWhenStarted
import ru.myitschool.work.utils.visibleOrGone
@ -31,6 +34,7 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
private var barcodeScanner: BarcodeScanner? = null
private var isCameraInit: Boolean = false
private var preferenceManager: PreferenceManager? = null
private val permissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted -> viewModel.onPermissionResult(isGranted) }
@ -40,6 +44,7 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentQrScanBinding.bind(view)
preferenceManager = PreferenceManager(this.context)
sendResult(bundleOf())
subscribe(view)
initCallback()
@ -66,7 +71,8 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
goBack(view)
}
is QrScanViewModel.Action.CloseWithResult -> {
sendResult(QrScanDestination.packToBundle(action.result))
preferenceManager?.putString(Constants.KEY_RESULT, action.result)
//sendResult(QrScanDestination.packToBundle(action.result))
goBack(view)
}
}
@ -115,7 +121,8 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
}
private fun goBack(view: View) {
findNavController(view).navigate<Any>(R.id.action_qrScanFragment_to_informationFragment)
Navigation.findNavController(view).navigate(R.id.action_qrScanFragment_to_resultFragment);
//findNavController(view).navigate<Any>(R.id.action_qrScanFragment_to_informationFragment)
/*findNavControllerOrNull()?.popBackStack()
?: requireActivity().onBackPressedDispatcher.onBackPressed()*/
}

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.ui;
package ru.myitschool.work.ui.result;
import android.content.Context;
import android.content.SharedPreferences;
@ -6,6 +6,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -20,35 +21,53 @@ import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import ru.myitschool.work.R;
import ru.myitschool.work.databinding.FragmentProfileBinding;
import ru.myitschool.work.databinding.FragmentResultBinding;
import ru.myitschool.work.domain.entities.UserEntity;
import ru.myitschool.work.ui.Door;
import ru.myitschool.work.ui.StoreAPI;
import ru.myitschool.work.ui.profile.ProfileViewModel;
import ru.myitschool.work.utils.Constants;
import ru.myitschool.work.utils.PreferenceManager;
public class ResultFragment extends Fragment {
FragmentResultBinding binding;
SharedPreferences sharedPreferences;
PreferenceManager preferenceManager;
private ResultViewModel viewModel;
Door door;
private String code;
public static ResultFragment newInstance(String data) {
/*public static ResultFragment newInstance(String data) {
ResultFragment fragment = new ResultFragment();
Bundle args = new Bundle();
args.putString(Constants.KEY_RESULT, data);
fragment.setArguments(args);
return fragment;
}
}*/
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentResultBinding.inflate(inflater, container, false);
return super.onCreateView(inflater, container, savedInstanceState);
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
sharedPreferences = getContext().getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE);
super.onViewCreated(view, savedInstanceState);
preferenceManager = new PreferenceManager(this.getContext());
if (getArguments() != null) {
code = preferenceManager.getString(Constants.KEY_RESULT);
if (code != null) {
Toast.makeText(this.getContext(), code, Toast.LENGTH_SHORT).show();
viewModel.postUserByUsername(preferenceManager.getString(Constants.KEY_USER_USERNAME), System.currentTimeMillis() + "", "Смартфон", code);
binding.result.setText(code);
}
subscribe();
//Toast.makeText(this.getContext(), "BAN", Toast.LENGTH_SHORT).show();
/*if (getArguments() != null) {
door = new Door(getArguments().getString(Constants.KEY_RESULT, ""));
} else {
door = new Door("");
@ -61,6 +80,19 @@ public class ResultFragment extends Fragment {
binding.close.setOnClickListener(view1 -> {
onClickClose(view);
});*/
}
private void subscribe() {
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
if (state.isLoading() == false) {
if (state.getSended() == true) {
binding.result.setText("Opened");
} else {
binding.result.setText("Not opened");
}
}
});
}
@ -69,7 +101,7 @@ public class ResultFragment extends Fragment {
//getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new InformationFragment()).commit();
}
private void patchDoor() {
/*private void patchDoor() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ru.myitschool.work.core.Constants.SERVER_ADDRESS)
.addConverterFactory(GsonConverterFactory.create())
@ -99,5 +131,5 @@ public class ResultFragment extends Fragment {
binding.result.setText(getText(R.string.wrong));
}
});
}
}*/
}

View File

@ -0,0 +1,95 @@
package ru.myitschool.work.ui.result;
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 ru.myitschool.work.data.UserRepositoryImpl;
import ru.myitschool.work.domain.CreateHistoryUseCase;
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.UserEntity;
import ru.myitschool.work.domain.sign.IsUserExistUseCase;
public class ResultViewModel extends ViewModel {
private final MutableLiveData<State> mutableStateLiveData = new MutableLiveData<>();
public final LiveData<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()
);
private final CreateHistoryUseCase createHistoryUseCase = new CreateHistoryUseCase(
UserRepositoryImpl.getInstance()
);
public void load(@NonNull String username) {
//mutableStateLiveData.setValue(new State(null, null, true));
//postUserByUsername(username);
}
public void postUserByUsername(String username, String time, String type, String code) {
final String currentUsername = username;
final String currentTime = time;
final String currentType = type;
final String currentCode = code;
mutableStateLiveData.setValue(new State(null, false, true));
if (currentUsername == null || currentUsername.isEmpty()) {
//mutableErrorLiveData.postValue("Login cannot be null");
return;
}
createHistoryUseCase.execute(currentUsername, currentTime, currentType, currentCode, status -> {
if (status.getStatusCode() == 201 && status.getErrors() == null) {
mutableStateLiveData.setValue(new State(null, true, false));
} else {
mutableStateLiveData.setValue(new State(null, false, false));
}
});
}
public class State {
@Nullable
private final String errorMessage;
@Nullable
private final boolean sended;
private final boolean isLoading;
public State(@Nullable String errorMessage, boolean sended, boolean isLoading) {
this.errorMessage = errorMessage;
this.sended = sended;
this.isLoading = isLoading;
}
@Nullable
public String getErrorMessage() {
return errorMessage;
}
@Nullable
public boolean getSended() {
return sended;
}
public boolean isLoading() {
return isLoading;
}
}
}

View File

@ -20,23 +20,24 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/position"
android:id="@+id/name"
app:layout_constraintTop_toBottomOf="@id/username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastTime"
app:layout_constraintTop_toBottomOf="@id/position"
android:id="@+id/position"
app:layout_constraintTop_toBottomOf="@id/name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/exit"
android:text="выход"
app:layout_constraintTop_toBottomOf="@id/lastTime"
app:layout_constraintTop_toBottomOf="@id/position"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

View File

@ -24,12 +24,15 @@
</fragment>
<fragment
android:id="@+id/profileFragment"
android:name="ru.myitschool.work.ui.ProfileFragment"
android:name="ru.myitschool.work.ui.profile.ProfileFragment"
android:label="ProfileFragment"
tools:layout="@layout/fragment_profile">
<action
android:id="@+id/action_profileFragment_to_informationFragment"
app:destination="@id/informationFragment" />
<action
android:id="@+id/action_profileFragment_to_loginFragment"
app:destination="@id/loginFragment" />
</fragment>
<fragment
android:id="@+id/loginFragment"
@ -39,6 +42,9 @@
<action
android:id="@+id/action_loginFragment_to_informationFragment"
app:destination="@id/informationFragment" />
<action
android:id="@+id/action_loginFragment_to_profileFragment"
app:destination="@id/profileFragment" />
<!-- <action-->
<!-- android:id="@+id/action_signInFragment_to_signUpFragment" -->
<!-- app:destination="@id/signUpFragment" />-->
@ -52,10 +58,13 @@
<action
android:id="@+id/action_qrScanFragment_to_informationFragment"
app:destination="@id/informationFragment" />
<action
android:id="@+id/action_qrScanFragment_to_resultFragment"
app:destination="@id/resultFragment" />
</fragment>
<fragment
android:id="@+id/resultFragment"
android:name="ru.myitschool.work.ui.ResultFragment"
android:name="ru.myitschool.work.ui.result.ResultFragment"
android:label="ResultFragment"
tools:layout="@layout/fragment_qr_scan" >
<action

View File

@ -15,5 +15,5 @@
<string name="time">Время:</string>
<string name="type">Тип прохода:</string>
<string name="code">Идентификатор:</string>
<string name="code">Идентификатор: </string>
</resources>

View File

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