diff --git a/app/src/main/java/ru/myitschool/work/ui/login/LoginActivity.java b/app/src/main/java/ru/myitschool/work/ui/login/LoginActivity.java index a2ef4b8..db63386 100644 --- a/app/src/main/java/ru/myitschool/work/ui/login/LoginActivity.java +++ b/app/src/main/java/ru/myitschool/work/ui/login/LoginActivity.java @@ -43,7 +43,7 @@ public class LoginActivity extends AppCompatActivity { return insets; binding = ActivityLoginBinding.bind(v); - viewModel = new ViewModelProvider(this).get(ActivityLoginBinding.class); + viewModel = new ViewModelProvider(this).get(LoginViewModel.class); binding.email.addTextChangedListener(new TextChangedListener<>(binding.email) { @Override @@ -59,21 +59,21 @@ public class LoginActivity extends AppCompatActivity { } }); - binding.btEnter.setOnClickListener(this.onClickListenerLoginButton); + binding.btEnter.setOnClickListener(this::onClickListenerLoginButton); subscribe(); }); } private void subscribe() { - viewModel.errorLiveData.observe(getViewLifecycleOwner(), error -> { + viewModel.errorLiveData.observe(this, error -> { binding.btEnter.setEnabled(true); - Snackbar.make(requireView(), error, Snackbar.LENGTH_LONG).show(); + Snackbar.make(findViewById(android.R.id.content), error, Snackbar.LENGTH_LONG).show(); }); - viewModel.openLiveData.observe(getViewLifecycleOwner(), employee -> { + viewModel.openLiveData.observe(this, employee -> { binding.btEnter.setEnabled(true); - SharedPreferences settings = requireView().getContext().getSharedPreferences( + SharedPreferences settings = this.getSharedPreferences( SettingConstants.PREFS_FILE, Context.MODE_PRIVATE ); settings.edit().putLong(SettingConstants.PREF_ID, employee.getId()).apply(); diff --git a/app/src/main/java/ru/myitschool/work/ui/login/LoginViewModel.java b/app/src/main/java/ru/myitschool/work/ui/login/LoginViewModel.java index 2b7a25d..dac95d8 100644 --- a/app/src/main/java/ru/myitschool/work/ui/login/LoginViewModel.java +++ b/app/src/main/java/ru/myitschool/work/ui/login/LoginViewModel.java @@ -4,12 +4,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; import ru.myitschool.work.api.data.SignRepositoryImpl; import ru.myitschool.work.api.domain.entity.employee.EmpolyeeEntity; import ru.myitschool.work.api.domain.useCases.sign.LoginEmployeeUseCase; -public class LoginViewModel { +public class LoginViewModel extends ViewModel { private final MutableLiveData mutableErrorLiveData = new MutableLiveData<>(); public final LiveData errorLiveData = mutableErrorLiveData; diff --git a/app/src/main/java/ru/myitschool/work/ui/main/MainActivity.kt b/app/src/main/java/ru/myitschool/work/ui/main/MainActivity.kt index 339e6a7..75e3f1b 100644 --- a/app/src/main/java/ru/myitschool/work/ui/main/MainActivity.kt +++ b/app/src/main/java/ru/myitschool/work/ui/main/MainActivity.kt @@ -1,26 +1,76 @@ -package ru.myitschool.work.ui.main; +package ru.myitschool.work.ui.main -import android.os.Bundle; +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.os.Bundle +import android.util.Log +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.fragment.app.Fragment +import com.example.myapplication.core.RoleConstants +import com.example.myapplication.core.SettingConstants +import com.google.android.material.bottomnavigation.BottomNavigationView +import ru.myitschool.work.R +import ru.myitschool.work.ui.createemployee.CreateUserFragment +import ru.myitschool.work.ui.login.LoginActivity +import ru.myitschool.work.ui.profile.ProfileFragment +import ru.myitschool.work.ui.qr.scan.QrScanFragment +import ru.myitschool.work.ui.userlist.CompanyInfoFragment -import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; +class MainActivity : AppCompatActivity() { + private lateinit var settings: SharedPreferences -import ru.myitschool.work.R; + private lateinit var bottomNavigationView: BottomNavigationView -public class MainActivity extends AppCompatActivity { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_main) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) + insets + } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_main); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); + settings = getSharedPreferences(SettingConstants.PREFS_FILE, Context.MODE_PRIVATE) + + if (settings.getLong(SettingConstants.PREF_ID, SettingConstants.ERROR_ID) == SettingConstants.ERROR_ID) { + Log.d("Test", "(MainActivity) Пользователь не зарегистрирован, запускаем регистрацию.") + startActivity(Intent(this, LoginActivity::class.java)) + finish() + return + } + + window.navigationBarColor = ContextCompat.getColor(this, R.color.teal_200) + + bottomNavigationView = findViewById(R.id.bottom_navigation_view) + + if (settings.getString(SettingConstants.PREF_ROLE, SettingConstants.DEF_VALUE) == RoleConstants.ROLE_USER) { + val menuItem = bottomNavigationView.menu.getItem(1); + menuItem.setVisible(false) + } + + bottomNavigationView.setOnItemSelectedListener{ item -> + // if (item.itemId == bottomNavigationView.selectedItemId) return@setOnItemSelectedListener false + + when (item.itemId) { + R.id.scaner -> replaceFragment(QrScanFragment()) + R.id.office -> replaceFragment(CompanyInfoFragment()) + R.id.createEmployee -> replaceFragment(CreateUserFragment()) + //R.id.employees -> replaceFragment(EmployeesListFragment()) + R.id.profile -> replaceFragment(ProfileFragment()) + } + window.statusBarColor = ContextCompat.getColor(this, R.color.grey) + + return@setOnItemSelectedListener true + } + } + + private fun replaceFragment(fragment: Fragment) { + supportFragmentManager.beginTransaction().replace(R.id.container, fragment).commit() } } \ No newline at end of file diff --git a/app/src/main/java/ru/myitschool/work/utils/TextChangedListener.java b/app/src/main/java/ru/myitschool/work/utils/TextChangedListener.java index 4e3be1e..2ef860f 100644 --- a/app/src/main/java/ru/myitschool/work/utils/TextChangedListener.java +++ b/app/src/main/java/ru/myitschool/work/utils/TextChangedListener.java @@ -4,7 +4,7 @@ import android.text.Editable; import android.text.TextWatcher; public abstract class TextChangedListener implements TextWatcher { - private final T target; + private final T target; public TextChangedListener(T target) { this.target = target; diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index b9e5d30..309b3a2 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -19,7 +19,8 @@ android:layout_marginTop="220dp" android:layout_marginEnd="50dp" android:layout_marginBottom="270dp" - app:cardBackgroundColor="@color/white"> + app:cardBackgroundColor="@color/white" + app:cardCornerRadius="20dp"> + android:orientation="horizontal" + android:background="@color/white"> + android:background="@color/white" + android:entries="@array/roles"/> + android:layout_marginEnd="140dp" + android:background="@color/black" /> #FF018786 #FF000000 #FFFFFFFF + #11FFFFFF \ No newline at end of file