Добавь четвертый пункт нижнего меню , а именно профиль , в профиле указывай данные последнего зарегистрированного или вошедшего пользователя , дополнительно укажи там время использования приложения также дай возможность выбрать себе пол ,дату рождения для профиля создай отдельный фрагмент и напиши подробно весь необходимый код и xml. вот мой код : package com.example.myapp_2;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.example.myapp_2.UI.view.fragments.FirstFragment;

public class LoginFragment extends Fragment {

private EditText editTextEmail, editTextPassword;
private Button buttonLogin;

private UserDAO userDAO;

public LoginFragment() {

}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

userDAO = new UserDAO(getActivity());
userDAO.open();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.login, container, false);

getActivity().findViewById(R.id.bottomNavigationView).setVisibility(View.GONE);
editTextEmail = view.findViewById(R.id.editTextEmail);
editTextPassword = view.findViewById(R.id.editTextPassword);
buttonLogin = view.findViewById(R.id.buttonLogin);

buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = editTextEmail.getText().toString();
String password = editTextPassword.getText().toString();

if (userDAO.login(email, password)) {
Toast.makeText(getActivity(), “Login successful”, Toast.LENGTH_SHORT).show();

// переход на другой фрагмент
FragmentTransaction transaction = requireActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_container, new FirstFragment());
transaction.addToBackStack(null);
transaction.commit();
} else {
Toast.makeText(getActivity(), “Invalid email or password”, Toast.LENGTH_SHORT).show();
}
}
});
Button buttonReturn = view.findViewById(R.id.buttonReturn);

buttonReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction transaction = requireActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_container, new RegistrationFragment());
transaction.addToBackStack(null);
transaction.commit();
}
});

return view;
}

@Override
public void onDestroy() {
super.onDestroy();
userDAO.close();
}
}
package com.example.myapp_2;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.example.myapp_2.UI.view.activities.MainActivity;
import com.example.myapp_2.UI.view.fragments.FirstFragment;

import java.util.List;

public class RegistrationFragment extends Fragment {

private EditText editTextName, editTextEmail, editTextPassword;
private Button buttonRegister_1;

private UserDAO userDAO;

public RegistrationFragment() {

}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

userDAO = new UserDAO(getActivity());
userDAO.open();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.refister, container, false);

getActivity().findViewById(R.id.bottomNavigationView).setVisibility(View.GONE);
editTextName = view.findViewById(R.id.editTextName);
editTextEmail = view.findViewById(R.id.editTextEmail);
editTextPassword = view.findViewById(R.id.editTextPassword);
buttonRegister_1 = view.findViewById(R.id.buttonRegister_1);

buttonRegister_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editTextName.getText().toString();
String email = editTextEmail.getText().toString();
String password = editTextPassword.getText().toString();

long rowID = userDAO.register(name, email, password);

if (rowID > 0) {
Toast.makeText(getActivity(), “Registration successful”, Toast.LENGTH_SHORT).show();

// вывод всех пользователей в лог
List<User> users = userDAO.getAllUsers();
Log.d(“UserDatabase”, “All users:”);
for (User user : users) {
Log.d(“UserDatabase”, user.toString());
}

getFragmentManager().popBackStack();
FragmentTransaction transaction = requireActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_container, new FirstFragment());
transaction.addToBackStack(null);
transaction.commit();
} else if (rowID == -1) {
Toast.makeText(getActivity(), “Invalid email”, Toast.LENGTH_SHORT).show();

} else {
Toast.makeText(getActivity(), “Registration failed”, Toast.LENGTH_SHORT).show();
}
}
});
Button buttonLogin_1 = view.findViewById(R.id.buttonLogin_1);

buttonLogin_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction transaction = requireActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_container, new LoginFragment());
transaction.addToBackStack(null);
transaction.commit();
}
});
Button buttonExit = view.findViewById(R.id.buttonExit);

buttonExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

getFragmentManager().popBackStack();
FragmentTransaction transaction = requireActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_container, new FirstFragment());
transaction.addToBackStack(null);
transaction.commit();
}
});


return view;
}

@Override
public void onDestroy() {
super.onDestroy();
userDAO.close();
}
}

package com.example.myapp_2;

public class User {
private int id;
private String name;
private String email;
private String password;

public User() {
}

public User(int id, String name, String email, String password) {
this.id = id;
this.name = name;
this.email = email;
this.password = password;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

@Override
public String toString() {
return “User {id=” + id + “, name=‘” + name + “‘, email=’” + email + “‘, password=’” + password + “’}”;
}
}package com.example.myapp_2;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

public class UserDAO {

private SQLiteDatabase database;
private UserDatabaseHelper dbHelper;

public UserDAO(Context context) {
dbHelper = new UserDatabaseHelper(context);
}

public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}

public void close() {
dbHelper.close();
}

public long register(String name, String email, String password) {
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
return -1; // email не соответствует формату
}

Cursor cursor = database.query(UserDatabaseHelper.TABLE_USERS,
new String[]{UserDatabaseHelper.COLUMN_EMAIL},
UserDatabaseHelper.COLUMN_EMAIL + " = ?“,
new String[]{email}, null, null, null, null);

if (cursor != null && cursor.getCount() > 0) { // если уже есть пользователь с такой почтой
cursor.close();
return -2;
}

ContentValues values = new ContentValues();
values.put(UserDatabaseHelper.COLUMN_NAME, name);
values.put(UserDatabaseHelper.COLUMN_EMAIL, email);
values.put(UserDatabaseHelper.COLUMN_PASSWORD, password);

return database.insert(UserDatabaseHelper.TABLE_USERS, null, values);
}

public boolean login(String email, String password) {
Cursor cursor = database.query(UserDatabaseHelper.TABLE_USERS,
new String[]{UserDatabaseHelper.COLUMN_EMAIL, UserDatabaseHelper.COLUMN_PASSWORD},
UserDatabaseHelper.COLUMN_EMAIL + " = ? AND " + UserDatabaseHelper.COLUMN_PASSWORD + " = ?”,
new String[]{email, password}, null, null, null, null);

if (cursor != null && cursor.getCount() > 0) {
cursor.close();
return true;
} else {
return false;
}
}

@SuppressLint(“Range”)
public List<User> getAllUsers() {
List<User> users = new ArrayList<>();

Cursor cursor = database.query(UserDatabaseHelper.TABLE_USERS,
new String[]{UserDatabaseHelper.COLUMN_ID, UserDatabaseHelper.COLUMN_NAME,
UserDatabaseHelper.COLUMN_EMAIL, UserDatabaseHelper.COLUMN_PASSWORD},
null, null, null, null, null);

if (cursor != null && cursor.moveToFirst()) {
do {
User user = new User();
user.setId(cursor.getInt(cursor.getColumnIndex(UserDatabaseHelper.COLUMN_ID)));
user.setName(cursor.getString(cursor.getColumnIndex(UserDatabaseHelper.COLUMN_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndex(UserDatabaseHelper.COLUMN_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndex(UserDatabaseHelper.COLUMN_PASSWORD)));

users.add(user);
} while (cursor.moveToNext());

cursor.close();
}

return users;
}
}
package com.example.myapp_2;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class UserDatabaseHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = “UserDatabase”;

public static final String TABLE_USERS = “users”;
public static final String COLUMN_ID = “_id”;
public static final String COLUMN_NAME = “name”;
public static final String COLUMN_EMAIL = “email”;
public static final String COLUMN_PASSWORD = “password”;

public UserDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_USERS_TABLE = “CREATE TABLE " + TABLE_USERS + “(”
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,”
+ COLUMN_NAME + " TEXT,“
+ COLUMN_EMAIL + " TEXT,”
+ COLUMN_PASSWORD + " TEXT"
+ “)”;
db.execSQL(CREATE_USERS_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
}package com.example.myapp_2.UI.view.activities;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.myapp_2.Data.model.database.Room.SQLITE.Note;
import com.example.myapp_2.RegistrationFragment;
import com.example.myapp_2.ViewModel.ViewModels.NoteViewModel;
import com.example.myapp_2.R;
import com.example.myapp_2.UI.view.fragments.FirstFragment;
import com.example.myapp_2.UI.view.fragments.SecondFragment;
import com.example.myapp_2.UI.view.fragments.ThirdFragment;
import com.example.myapp_2.databinding.ActivityMainBinding;

import java.util.List;


import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.myapp_2.Data.model.database.Room.SQLITE.Note;
import com.example.myapp_2.ViewModel.ViewModels.NoteViewModel;
import com.example.myapp_2.R;
import com.example.myapp_2.UI.view.fragments.FirstFragment;
import com.example.myapp_2.UI.view.fragments.SecondFragment;
import com.example.myapp_2.UI.view.fragments.ThirdFragment;
import com.example.myapp_2.databinding.ActivityMainBinding;

import java.util.List;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private NoteViewModel noteViewModel;

private BroadcastReceiver broadcastReceiver;

static boolean isRegister = false;
Button button1;
Button button3;
// private FirstFragment firstFragment = new FirstFragment();
ActivityMainBinding binding;
private Button btn_fragment1,btn_fragment2,btn_fragment3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
replaceFragment(new FirstFragment());

binding.bottomNavigationView.setOnItemSelectedListener(item -> {
switch(item.getItemId()){
case R.id.home:

replaceFragment(new FirstFragment());
break;
case R.id.profile:
replaceFragment(new SecondFragment());
break;
case R.id.settings:
replaceFragment(new ThirdFragment());
break;
}
return true;
});

getSupportFragmentManager().beginTransaction().replace(R.id.nav_container, new FirstFragment()).addToBackStack(null).commit();

if (isRegister) {
binding.bottomNavigationView.setVisibility(View.GONE);
} else {
binding.bottomNavigationView.setVisibility(View.VISIBLE);
}
}

private void registerBroadcastReceiver() {
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Получение сообщения
String action = intent.getAction();
if(action.equals(“com.example.myapplication_2.SEND_MESSAGE”)) {
String message = intent.getStringExtra(“MESSAGE”);
// Вывод сообщения в лог
Log.d(“MyApp2”, "Received message: " + message);
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(“com.example.myapplication_2.SEND_MESSAGE”);
registerReceiver(broadcastReceiver, intentFilter);
}


@Override
public void onClick(View view) {//2 способ

}
@Override
protected void onDestroy() {
super.onDestroy();
// Удаление приемника
unregisterReceiver(broadcastReceiver);
}

private void replaceFragment(Fragment fragment){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.nav_container,fragment);
String A = “HELLO”;


Bundle bundle = new Bundle();
bundle.putInt(“hello world”, 4344);
fragment.setArguments(bundle);


fragmentTransaction.commit();

}

// вызов фрагмента регистрации с передачей кода запроса

public void startRegistration() {
isRegister = true;
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.nav_container, new RegistrationFragment()).addToBackStack(null).commit();
}

// обработка полученного результата (кода запроса)
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
isRegister = true; // установка значения переменной isRegister в true
}
}

}
Добавление четвертого пункта нижнего меню (профиля) требует создания нового фрагмента и соответствующих XML файлов.

Вот необходимый код и XML для создания фрагмента профиля:

XML-файлы:

fragment_profile.xml:

<?xml version=“1.0” encoding=“utf-8”?>
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>

<!-- Текстовые поля для отображения имени, email и времени использования приложения -->
<TextView
android:id=“@+id/textViewName”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:textSize=“20sp” />

<TextView
android:id=“@+id/textViewEmail”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:textSize=“16sp” />

<TextView
android:id=“@+id/textViewTimeUsed”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:textSize=“16sp” />

<!-- Кнопки для редактирования профиля -->
<Button
android:id=“@+id/buttonEditName”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Edit Name” />

<Button
android:id=“@+id/buttonEditGender”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Edit Gender” />

<Button
android:id=“@+id/buttonEditBirthday”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Edit Birthday” />

</LinearLayout>

fragment_edit_profile.xml:

<?xml version=“1.0” encoding=“utf-8”?>
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>

<!-- Текстовое поле для ввода имени и кнопки сохранения и отмены изменений -->
<TextView
android:layout_marginTop=“16dp”
android:layout_marginLeft=“16dp”
android:layout_marginRight=“16dp”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Name:”
android:textSize=“16sp” />

<EditText
android:id=“@+id/editTextName”
android:layout_marginLeft=“16dp”
android:layout_marginRight=“16dp”
android:layout_marginBottom=“16dp”
android:layout_width=“match_parent”
android:layout_height=“wrap_content” />

<Button
android:id=“@+id/buttonSave”
android:layout_marginLeft=“16dp”
android:layout_marginRight=“8dp”
android:layout_marginBottom=“16dp”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:text=“Save” />

<Button
android:id=“@+id/buttonCancel”
android:layout_marginLeft=“8dp”
android:layout_marginRight=“16dp”
android:layout_marginBottom=“16dp”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:text=“Cancel” />

</LinearLayout>

Файлы классов Java:

ProfileFragment.java


package com.example.myapp_2.UI.view.fragments;



import com.example.myapp_2.R;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ProfileFragment extends Fragment {

private TextView textViewName, textViewEmail, textViewTimeUsed;
private Button buttonEditName, buttonEditGender, buttonEditBirthday;

private String name, email;
private Date timeUsed;

public ProfileFragment() {

}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Получение данных о пользователе (из баз