<repo_name>sushantmzjn/ESoftwarica<file_sep>/app/src/main/java/com/sushant/esoftwarica/adapter/UserAdapter.java
package com.sushant.esoftwarica.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sushant.esoftwarica.R;
import com.sushant.esoftwarica.model.User;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class UserAdapter extends RecyclerView.Adapter<UserAdapter.UserViewHolder> {

    Context context;
    List<User> userList;
    int imgId;

    public UserAdapter(Context context, List<User> userList) {
        this.context = context;
        this.userList = userList;
    }

    @NonNull
    @Override
    public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_view, parent, false);
        return new UserViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull UserViewHolder holder, final int position) {

      final User user = userList.get(position);
      String gender=user.getGender();
      if(gender.equals("male")){
           imgId=R.drawable.male;
      }
      else
      {
           imgId=R.drawable.female;
      }

        holder.imgview.setImageResource(imgId);
        holder.Uname.setText(user.getName());
        holder.add.setText(user.getAddress());
        holder.Age.setText(user.getAge());
        holder.gen.setText(user.getGender());

        holder.btndelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userList.remove(position);
                notifyDataSetChanged();
            }
        });


    }

    @Override
    public int getItemCount() {
        return userList.size();
    }

   public class UserViewHolder extends RecyclerView.ViewHolder {

        private CircleImageView imgview;
        private TextView Uname, add, Age, gen;
       private Button btndelete;

        public UserViewHolder(@NonNull View itemView) {
            super(itemView);

            imgview = itemView.findViewById(R.id.imageView);
            Uname = itemView.findViewById(R.id.Title);
            add = itemView.findViewById(R.id.address);
            Age = itemView.findViewById(R.id.age);
            gen = itemView.findViewById(R.id.gender);
            btndelete = itemView.findViewById(R.id.delete);
        }
    }
}
<file_sep>/app/src/main/java/com/sushant/esoftwarica/model/User.java
package com.sushant.esoftwarica.model;

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

public class User{
    private int imageid;
    private String name,address, age, gender;

    static List<User> userList=new ArrayList<>();

    public User(String name, String address, String age, String gender) {
        this.imageid = imageid;
        this.name = name;
        this.address = address;
        this.age = age;
        this.gender = gender;
    }

    public static List<User> getUserList() {
        return userList;
    }

    public static void setUserList(List<User> userList) {
        User.userList = userList;
    }

    public String getName() {
        return name;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}<file_sep>/app/src/main/java/com/sushant/esoftwarica/MainActivity.java
package com.sushant.esoftwarica;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private EditText etU, etP;
    private Button btnL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        etU = findViewById(R.id.etusername);
        etP = findViewById(R.id.etpassword);
        btnL = findViewById(R.id.btnLogin);


    btnL.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String user = etU.getText().toString().trim();
            String pass = etP.getText().toString().trim();

            if (TextUtils.isEmpty(etU.getText().toString())){etU.setError("Input Username"); return;}
            if (TextUtils.isEmpty(etP.getText().toString())){etP.setError("Input Password"); return;}

            if (user.equals("sushant") && pass.equals("<PASSWORD>")){

                Toast toast = Toast.makeText(getApplicationContext(),"Login Successful",Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL,0,0);
                toast.show();
                Intent intent = new Intent(MainActivity.this,Dashboard.class);
                startActivity(intent);
            }else
            {
                etP.setError("Incorrect Password");
                return;
            }
            etP.setText(null);
            etU.setText(null);

        }
    });
    }
}
<file_sep>/app/src/main/java/com/sushant/esoftwarica/ui/add/AddFragment.java
package com.sushant.esoftwarica.ui.add;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.sushant.esoftwarica.R;
import com.sushant.esoftwarica.model.User;

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

public class AddFragment extends Fragment implements View.OnClickListener {

    private EditText sname, saddress, sage;
    private Button Abtn;
    private RadioGroup radioGroup;
    private RadioButton rmale, rfemale;
    String gender, name,address,Age;
    static List<User> userList = new ArrayList<>();

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        final View root = inflater.inflate(R.layout.fragment_add, container, false);
        sname = root.findViewById(R.id.txtname);
        saddress = root.findViewById(R.id.txtaddress);
        sage = root.findViewById(R.id.txtage);
        Abtn = root.findViewById(R.id.btnadd);
        rmale = root.findViewById(R.id.rbm);
        rfemale = root.findViewById(R.id.rbf);
        radioGroup = root.findViewById(R.id.genderG);

        Abtn.setOnClickListener(this);


        return root;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.btnadd:
                 name = sname.getText().toString().trim();
                 address = saddress.getText().toString().trim();
                 Age = sage.getText().toString().trim();

                if (TextUtils.isEmpty(name)){
                    sname.setError("Enter Name");
                    return;
                }
                if (TextUtils.isEmpty(address)){
                    saddress.setError("Enter Address");
                    return;
                }
                if (TextUtils.isEmpty(Age)){
                    sage.setError("Enter Age");
                    return;
                }
                if (rmale.isChecked()){
                     gender = "male";
                }
                if (rfemale.isChecked()){
                    gender = "female";
                }

                User user = new User(name,address, Age, gender);
                userList = user.getUserList();
                userList.add(user);
                user.setUserList(userList);

                Toast.makeText(getActivity(), "User added Successfully", Toast.LENGTH_SHORT).show();

                sname.setText("");
                saddress.setText("");
                sage.setText("");
                rfemale.setChecked(false);
                rmale.setChecked(false);


            break;

        }

    }
}<file_sep>/app/src/main/java/com/sushant/esoftwarica/ui/home/HomeFragment.java
package com.sushant.esoftwarica.ui.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sushant.esoftwarica.R;
import com.sushant.esoftwarica.adapter.UserAdapter;
import com.sushant.esoftwarica.model.User;

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

public class HomeFragment extends Fragment {

    private RecyclerView recyclerView;
    static List<User> userList=new ArrayList<>();


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

        View root = inflater.inflate(R.layout.fragment_home, container, false);
        recyclerView = root.findViewById(R.id.recyclerview);


        User user= new User("sushant", "ktm", "22", "male");
        userList=user.getUserList();
        if(userList.isEmpty()) {
            userList.add(new User("sushant", "ktm", "22", "male"));
            userList.add(new User("sony", "ktm", "22", "female"));
            user.setUserList(userList);
        }


        UserAdapter adapter = new UserAdapter(getActivity(), userList);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));


        return root;
    }
}