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



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


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.Data.model;

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

public User() {

}

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

public long getId() {
return id;
}

public void setId(long 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 + “]”;
}
}

public class UserDAO {

private SQLiteOpenHelper dbHelper;
private SQLiteDatabase database;

public static final String TABLE_USERS = “users_table”;
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 static final String CREATE_USERS_TABLE = “CREATE TABLE ” + TABLE_USERS + ” (” +
COLUMN_ID + ” INTEGER PRIMARY KEY AUTOINCREMENT, ” +
COLUMN_NAME + ” TEXT NOT NULL, ” +
COLUMN_EMAIL + ” TEXT NOT NULL UNIQUE, ” +
COLUMN_PASSWORD + ” TEXT NOT NULL);”;

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

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

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

public long register(String name, String email, String password) {
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, name);
values.put(COLUMN_EMAIL, email);
values.put(COLUMN_PASSWORD, password);

long rowID = database.insert(TABLE_USERS, null, values);
return rowID;
}

public boolean login(String email, String password) {
String selection = COLUMN_EMAIL + “= ? AND ” + COLUMN_PASSWORD + “= ?";
String[] selectionArgs = { email, password };

Cursor cursor = database.query(TABLE_USERS, null, selection, selectionArgs,
null, null, null);

if (cursor.getCount() > 0) {
cursor.moveToFirst();
String dbEmail = cursor.getString(cursor.getColumnIndex(COLUMN_EMAIL));
String dbPassword = cursor.getString(cursor.getColumnIndex(COLUMN_PASSWORD));
if (dbEmail.equals(email) && dbPassword.equals(password)) {
return true;
} else {
return false;
}
} else {
return false;
}
}

public List<User> getAllUsers() {
List<User> users = new ArrayList<User>();

Cursor cursor = database.rawQuery(“SELECT * FROM ” + TABLE_USERS, null);

cursor.moveToFirst();
while (!cursor.isAfterLast()) {
User user = new User();
user.setId(cursor.getLong(cursor.getColumnIndex(COLUMN_ID)));
user.setName(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndex(COLUMN_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndex(COLUMN_PASSWORD)));

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

return users;
}

private class UserDatabaseHelper extends SQLiteOpenHelper {

public UserDatabaseHelper(Context context) {
super(context, “userDatabase.db”, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
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);
}
}
}

<?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”
android:gravity=”center_horizontal” >

<EditText
android:id=”@+id/editTextName”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Name”
android:inputType=”textPersonName” />

<EditText
android:id=”@+id/editTextEmail”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Email”
android:inputType=”textEmailAddress” />

<EditText
android:id=”@+id/editTextPassword”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Password”
android:inputType=”textPassword” />

<Button
android:id=”@+id/buttonRegister_1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Register” />

<Button
android:id=”@+id/buttonLogin_1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Login” />
<Button
android:id=”@+id/buttonExit”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Exit” />

</LinearLayout>

<?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”
android:gravity=”center_horizontal” >

<EditText
android:id=”@+id/editTextEmail”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Email”
android:inputType=”textEmailAddress” />

<EditText
android:id=”@+id/editTextPassword”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Password”
android:inputType=”textPassword” />

<Button
android:id=”@+id/buttonLogin”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Login” />

<Button
android:id=”@+id/buttonReturn”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Return to registration” />

</LinearLayout>