version4 (pred final) with main

This commit is contained in:
Andrey 2025-02-20 15:36:29 +03:00
parent eaf36da2f0
commit fdd274011e
8 changed files with 89 additions and 32 deletions

View File

@ -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();

View File

@ -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<String> mutableErrorLiveData = new MutableLiveData<>();
public final LiveData<String> errorLiveData = mutableErrorLiveData;

View File

@ -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()
}
}

View File

@ -4,7 +4,7 @@ import android.text.Editable;
import android.text.TextWatcher;
public abstract class TextChangedListener<T> implements TextWatcher {
private final T target;
private final T target;
public TextChangedListener(T target) {
this.target = target;

View File

@ -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">
<RelativeLayout
android:layout_width="fill_parent"

View File

@ -18,7 +18,8 @@
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:background="@color/white">
<ImageView
android:layout_width="wrap_content"
@ -223,7 +224,8 @@
android:layout_marginStart="70dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="70dp"
android:background="@color/white" />
android:background="@color/white"
android:entries="@array/roles"/>
<com.google.android.material.button.MaterialButton

View File

@ -37,7 +37,7 @@
</LinearLayout>
<ImageView
android:id="@+id/imageView2"
android:id="@+id/profile_image_view"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_alignParentStart="true"
@ -45,7 +45,8 @@
android:layout_alignParentEnd="true"
android:layout_marginStart="140dp"
android:layout_marginTop="90dp"
android:layout_marginEnd="140dp" />
android:layout_marginEnd="140dp"
android:background="@color/black" />
<LinearLayout
android:id="@+id/linearLayout"
@ -61,6 +62,7 @@
android:padding="8dp">
<com.google.android.material.button.MaterialButton
android:id="@+id/changeProfile"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"

View File

@ -7,4 +7,5 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="grey">#11FFFFFF</color>
</resources>