Added translation
This commit is contained in:
parent
b74169da95
commit
6f261ebb03
@ -17,6 +17,7 @@ import androidx.navigation.Navigation;
|
|||||||
import ru.myitschool.work.R;
|
import ru.myitschool.work.R;
|
||||||
import ru.myitschool.work.databinding.FragmentLoginBinding;
|
import ru.myitschool.work.databinding.FragmentLoginBinding;
|
||||||
import ru.myitschool.work.utils.OnChangeText;
|
import ru.myitschool.work.utils.OnChangeText;
|
||||||
|
import ru.myitschool.work.utils.Utils;
|
||||||
|
|
||||||
public class LoginFragment extends Fragment {
|
public class LoginFragment extends Fragment {
|
||||||
private FragmentLoginBinding binding;
|
private FragmentLoginBinding binding;
|
||||||
@ -55,7 +56,8 @@ public class LoginFragment extends Fragment {
|
|||||||
|
|
||||||
private void subscribe(LoginViewModel viewModel) {
|
private void subscribe(LoginViewModel viewModel) {
|
||||||
viewModel.errorLiveData.observe(getViewLifecycleOwner(), error -> {
|
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 -> {
|
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||||
binding.login.setClickable(state.isButtonActive());
|
binding.login.setClickable(state.isButtonActive());
|
||||||
|
@ -3,7 +3,6 @@ package ru.myitschool.work.ui.profile;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -40,6 +39,12 @@ public class UserFragment extends Fragment {
|
|||||||
UserEntity entity = state.getItem();
|
UserEntity entity = state.getItem();
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return;
|
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 {
|
} else {
|
||||||
binding.photo.setVisibility(Utils.visibleOrGone(entity.getPhotoUrl() != null));
|
binding.photo.setVisibility(Utils.visibleOrGone(entity.getPhotoUrl() != null));
|
||||||
binding.position.setVisibility(Utils.visibleOrGone(entity.getPosition() != null));
|
binding.position.setVisibility(Utils.visibleOrGone(entity.getPosition() != null));
|
||||||
@ -61,6 +66,14 @@ public class UserFragment extends Fragment {
|
|||||||
viewModel.update(preferences.getString("login", ""));
|
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 -> {
|
binding.scan.setOnClickListener(v -> {
|
||||||
Navigation.findNavController(getView()).navigate(
|
Navigation.findNavController(getView()).navigate(
|
||||||
R.id.action_userFragment_to_qrScanFragment);
|
R.id.action_userFragment_to_qrScanFragment);
|
||||||
@ -82,10 +95,11 @@ public class UserFragment extends Fragment {
|
|||||||
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
|
getParentFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, this, new FragmentResultListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
||||||
Log.d("result1", QrScanDestination.INSTANCE.getDataIfExist(result));
|
if (QrScanDestination.INSTANCE.getDataIfExist(result) != null) {
|
||||||
getParentFragmentManager().setFragmentResult("requestKey", result);
|
getParentFragmentManager().setFragmentResult("requestKey", result);
|
||||||
Navigation.findNavController(getView()).navigate(
|
Navigation.findNavController(getView()).navigate(
|
||||||
R.id.action_userFragment_to_qrResultFragment);
|
R.id.action_userFragment_to_qrResultFragment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,15 +39,15 @@ public class QrResultFragment extends Fragment {
|
|||||||
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
||||||
resultQr = QrScanDestination.INSTANCE.getDataIfExist(result);
|
resultQr = QrScanDestination.INSTANCE.getDataIfExist(result);
|
||||||
|
|
||||||
|
if (resultQr == null) {
|
||||||
|
binding.result.setText(R.string.door_closed);
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
viewModel.stateLiveData.observe(getViewLifecycleOwner(), state -> {
|
||||||
if (state.getErrorMessage() == null && state.isOpened()) {
|
if (state.getErrorMessage() == null && state.isOpened()) {
|
||||||
binding.result.setText(R.string.door_opened);
|
binding.result.setText(R.string.door_opened);
|
||||||
} else if (state.getErrorMessage() != null) {
|
} else if (state.getErrorMessage() != null) {
|
||||||
binding.result.setText(R.string.error);
|
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();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -66,7 +66,6 @@ class QrScanFragment : Fragment(R.layout.fragment_qr_scan) {
|
|||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
is QrScanViewModel.Action.CloseWithResult -> {
|
is QrScanViewModel.Action.CloseWithResult -> {
|
||||||
Log.d("result", action.result)
|
|
||||||
sendResult(QrScanDestination.packToBundle(action.result))
|
sendResult(QrScanDestination.packToBundle(action.result))
|
||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -15,7 +14,7 @@
|
|||||||
app:flow_verticalGap="24dp"
|
app:flow_verticalGap="24dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:constraint_referenced_ids="title, username, login" />
|
app:constraint_referenced_ids="title, username, login, error" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
|
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
|
||||||
@ -24,6 +23,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/welcome_text" />
|
android:text="@string/welcome_text" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/error"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/username"
|
android:id="@+id/username"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -37,8 +42,4 @@
|
|||||||
android:text="@string/login"
|
android:text="@string/login"
|
||||||
android:clickable="false" />
|
android:clickable="false" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -9,7 +9,6 @@
|
|||||||
android:id="@+id/result"
|
android:id="@+id/result"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="OK"
|
|
||||||
android:textSize="50dp" />
|
android:textSize="50dp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@ -30,7 +29,4 @@
|
|||||||
app:flow_verticalStyle="packed"
|
app:flow_verticalStyle="packed"
|
||||||
app:flow_verticalGap="24dp" />
|
app:flow_verticalGap="24dp" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -33,7 +33,6 @@
|
|||||||
android:id="@+id/error"
|
android:id="@+id/error"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
|
||||||
tools:text="ошибка" />
|
tools:text="ошибка" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@ -60,7 +59,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:flow_verticalGap="24dp"
|
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:flow_lastVerticalStyle="spread"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/nav_graph"
|
android:id="@+id/nav_graph"
|
||||||
app:startDestination="@id/loginFragment">
|
app:startDestination="@id/loginFragment">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/userFragment"
|
android:id="@+id/userFragment"
|
||||||
android:name="ru.myitschool.work.ui.profile.UserFragment"
|
android:name="ru.myitschool.work.ui.profile.UserFragment"
|
||||||
android:label="UserFragment" >
|
android:label="UserFragment"
|
||||||
|
tools:layout="@layout/fragment_user">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_userFragment_to_loginFragment"
|
android:id="@+id/action_userFragment_to_loginFragment"
|
||||||
app:destination="@id/loginFragment" />
|
app:destination="@id/loginFragment" />
|
||||||
@ -19,6 +21,7 @@
|
|||||||
app:destination="@id/qrScanFragment" />
|
app:destination="@id/qrScanFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
|
tools:layout="@layout/fragment_qr_scan"
|
||||||
android:id="@+id/qrScanFragment"
|
android:id="@+id/qrScanFragment"
|
||||||
android:name="ru.myitschool.work.ui.qr.scan.QrScanFragment"
|
android:name="ru.myitschool.work.ui.qr.scan.QrScanFragment"
|
||||||
android:label="QrScanFragment" >
|
android:label="QrScanFragment" >
|
||||||
@ -27,19 +30,25 @@
|
|||||||
app:destination="@id/userFragment" />
|
app:destination="@id/userFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
|
tools:layout="@layout/fragment_login"
|
||||||
android:id="@+id/loginFragment"
|
android:id="@+id/loginFragment"
|
||||||
android:name="ru.myitschool.work.ui.login.LoginFragment"
|
android:name="ru.myitschool.work.ui.login.LoginFragment"
|
||||||
android:label="LoginFragment" >
|
android:label="LoginFragment" >
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_loginFragment_to_userFragment"
|
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>
|
||||||
<fragment
|
<fragment
|
||||||
|
tools:layout="@layout/fragment_qr_result"
|
||||||
android:id="@+id/qrResultFragment"
|
android:id="@+id/qrResultFragment"
|
||||||
android:name="ru.myitschool.work.ui.qr.result.QrResultFragment"
|
android:name="ru.myitschool.work.ui.qr.result.QrResultFragment"
|
||||||
android:label="QrResultFragment" >
|
android:label="QrResultFragment" >
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_qrResultFragment_to_userFragment"
|
android:id="@+id/action_qrResultFragment_to_userFragment"
|
||||||
app:destination="@id/userFragment" />
|
app:destination="@id/userFragment"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
15
app/src/main/res/values-en-rUS/strings.xml
Normal file
15
app/src/main/res/values-en-rUS/strings.xml
Normal 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>
|
@ -1,12 +1,13 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">NTO Pass</string>
|
<string name="app_name">NTO Pass</string>
|
||||||
<string name="logout_text">Выйти из аккаунта</string>
|
|
||||||
<string name="scan_qr_text">Сканировать QR-код</string>
|
<string name="scan_qr_text">Сканировать QR-код</string>
|
||||||
<string name="login_hint">Введите логин</string>
|
<string name="login_hint">Введите логин</string>
|
||||||
<string name="welcome_text">Добро пожаловать</string>
|
<string name="welcome_text">Добро пожаловать</string>
|
||||||
<string name="login">Войти</string>
|
<string name="login">Войти</string>
|
||||||
<string name="refresh_data">Обновить данные</string>
|
<string name="refresh_data">Обновить данные</string>
|
||||||
<string name="to_main_menu">Закрыть</string>
|
<string name="to_main_menu">Закрыть</string>
|
||||||
<string name="door_opened">Дверь открыта</string>
|
<string name="door_opened">успешно</string>
|
||||||
<string name="error">Ошибка доступа</string>
|
<string name="door_closed">Вход был отменён</string>
|
||||||
|
<string name="error">Что-то пошло не так</string>
|
||||||
|
<string name="logout_text">Выйти из аккаунта</string>
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user