Added translation

This commit is contained in:
A1pha 2024-11-27 15:07:56 +03:00
parent b74169da95
commit 6f261ebb03
10 changed files with 65 additions and 29 deletions

View File

@ -17,6 +17,7 @@ import androidx.navigation.Navigation;
import ru.myitschool.work.R;
import ru.myitschool.work.databinding.FragmentLoginBinding;
import ru.myitschool.work.utils.OnChangeText;
import ru.myitschool.work.utils.Utils;
public class LoginFragment extends Fragment {
private FragmentLoginBinding binding;
@ -55,7 +56,8 @@ public class LoginFragment extends Fragment {
private void subscribe(LoginViewModel viewModel) {
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error -> {
Toast.makeText(getContext(), error, Toast.LENGTH_SHORT).show();
binding.error.setVisibility(Utils.visibleOrGone(error != null));
binding.error.setText(error);
});
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
binding.login.setClickable(state.isButtonActive());

View File

@ -3,7 +3,6 @@ package ru.myitschool.work.ui.profile;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
@ -40,6 +39,12 @@ public class UserFragment extends Fragment {
UserEntity entity = state.getItem();
if (entity == null) {
return;
} else if (state.getErrorMessage() != null) {
binding.error.setVisibility(View.VISIBLE);
binding.error.setText(state.getErrorMessage());
binding.logout.setVisibility(View.GONE);
binding.scan.setVisibility(View.GONE);
} else {
binding.photo.setVisibility(Utils.visibleOrGone(entity.getPhotoUrl() != null));
binding.position.setVisibility(Utils.visibleOrGone(entity.getPosition() != null));
@ -61,6 +66,14 @@ public class UserFragment extends Fragment {
viewModel.update(preferences.getString("login", ""));
}
binding.refresh.setOnClickListener(v -> {
if (getContext() != null) {
SharedPreferences preferences = getContext().getSharedPreferences(
"login", Context.MODE_PRIVATE);
viewModel.update(preferences.getString("login", ""));
}
});
binding.scan.setOnClickListener(v -> {
Navigation.findNavController(getView()).navigate(
R.id.action_userFragment_to_qrScanFragment);
@ -82,10 +95,11 @@ public class UserFragment extends Fragment {
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
Log.d("result1", QrScanDestination.INSTANCE.getDataIfExist(result));
getParentFragmentManager().setFragmentResult("requestKey", result);
Navigation.findNavController(getView()).navigate(
R.id.action_userFragment_to_qrResultFragment);
if (QrScanDestination.INSTANCE.getDataIfExist(result) != null) {
getParentFragmentManager().setFragmentResult("requestKey", result);
Navigation.findNavController(getView()).navigate(
R.id.action_userFragment_to_qrResultFragment);
}
}
});

View File

@ -39,15 +39,15 @@ public class QrResultFragment extends Fragment {
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
resultQr = QrScanDestination.INSTANCE.getDataIfExist(result);
if (resultQr == null) {
binding.result.setText(R.string.door_closed);
}
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
if (state.getErrorMessage() == null && state.isOpened()) {
binding.result.setText(R.string.door_opened);
} else if (state.getErrorMessage() != null) {
binding.result.setText(R.string.error);
Toast.makeText(getContext(), state.getErrorMessage(), Toast.LENGTH_SHORT).show();
} else {
binding.result.setText(R.string.error);
Toast.makeText(getContext(), "error", Toast.LENGTH_SHORT).show();
}
});

View File

@ -66,7 +66,6 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
goBack()
}
is QrScanViewModel.Action.CloseWithResult -> {
Log.d("result", action.result)
sendResult(QrScanDestination.packToBundle(action.result))
goBack()
}

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -15,7 +14,7 @@
app:flow_verticalGap="24dp"
app:layout_constraintBottom_toBottomOf="parent"
android:orientation="vertical"
app:constraint_referenced_ids="title, username, login" />
app:constraint_referenced_ids="title, username, login, error" />
<TextView
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
@ -24,6 +23,12 @@
android:layout_height="wrap_content"
android:text="@string/welcome_text" />
<TextView
android:id="@+id/error"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
@ -37,8 +42,4 @@
android:text="@string/login"
android:clickable="false" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -9,7 +9,6 @@
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="OK"
android:textSize="50dp" />
<Button
@ -30,7 +29,4 @@
app:flow_verticalStyle="packed"
app:flow_verticalGap="24dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -33,7 +33,6 @@
android:id="@+id/error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:text="ошибка" />
<Button
@ -60,7 +59,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
app:flow_verticalGap="24dp"
app:constraint_referenced_ids="fullname,photo,position,lastEntry,error,logout,refresh,scan"
app:constraint_referenced_ids="fullname,photo,position,lastEntry,logout,refresh,scan,error"
app:flow_lastVerticalStyle="spread"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"

View File

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/loginFragment">
<fragment
android:id="@+id/userFragment"
android:name="ru.myitschool.work.ui.profile.UserFragment"
android:label="UserFragment" >
android:label="UserFragment"
tools:layout="@layout/fragment_user">
<action
android:id="@+id/action_userFragment_to_loginFragment"
app:destination="@id/loginFragment" />
@ -19,6 +21,7 @@
app:destination="@id/qrScanFragment" />
</fragment>
<fragment
tools:layout="@layout/fragment_qr_scan"
android:id="@+id/qrScanFragment"
android:name="ru.myitschool.work.ui.qr.scan.QrScanFragment"
android:label="QrScanFragment" >
@ -27,19 +30,25 @@
app:destination="@id/userFragment" />
</fragment>
<fragment
tools:layout="@layout/fragment_login"
android:id="@+id/loginFragment"
android:name="ru.myitschool.work.ui.login.LoginFragment"
android:label="LoginFragment" >
<action
android:id="@+id/action_loginFragment_to_userFragment"
app:destination="@id/userFragment" />
app:destination="@id/userFragment"
app:popUpTo="@id/nav_graph"
app:popUpToInclusive="true" />
</fragment>
<fragment
tools:layout="@layout/fragment_qr_result"
android:id="@+id/qrResultFragment"
android:name="ru.myitschool.work.ui.qr.result.QrResultFragment"
android:label="QrResultFragment" >
<action
android:id="@+id/action_qrResultFragment_to_userFragment"
app:destination="@id/userFragment" />
app:destination="@id/userFragment"
app:popUpTo="@id/nav_graph"
app:popUpToInclusive="true" />
</fragment>
</navigation>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">NTO Pass</string>
<string name="scan_qr_text">Scan QR</string>
<string name="login_hint">Enter login</string>
<string name="welcome_text">Welcome</string>
<string name="login">Login</string>
<string name="refresh_data">Refresh</string>
<string name="to_main_menu">Close</string>
<string name="door_opened">Success</string>
<string name="door_closed">Operation was cancelled</string>
<string name="error">Something went wrong</string>
<string name="close_button">Close</string>
<string name="logout_text">Logout</string>
</resources>

View File

@ -1,12 +1,13 @@
<resources>
<string name="app_name">NTO Pass</string>
<string name="logout_text">Выйти из аккаунта</string>
<string name="scan_qr_text">Сканировать QR-код</string>
<string name="login_hint">Введите логин</string>
<string name="welcome_text">Добро пожаловать</string>
<string name="login">Войти</string>
<string name="refresh_data">Обновить данные</string>
<string name="to_main_menu">Закрыть</string>
<string name="door_opened">Дверь открыта</string>
<string name="error">Ошибка доступа</string>
<string name="door_opened">успешно</string>
<string name="door_closed">Вход был отменён</string>
<string name="error">Что-то пошло не так</string>
<string name="logout_text">Выйти из аккаунта</string>
</resources>