0% found this document useful (0 votes)
25 views42 pages

Capstone Project

Uploaded by

surajyemle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views42 pages

Capstone Project

Uploaded by

surajyemle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

IMPLEMENTATION

Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PackYourBag"
tools:targetApi="31">
<activity
android:name=".CheckList"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>
</manifest>

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

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

import com.example.packyourbag.CheckList;
import com.example.packyourbag.Constants.MyConstants;
import com.example.packyourbag.R;

import java.util.List;

public class Adapter extends RecyclerView.Adapter<Adapter.myViewHolder> {

List<String> titles;
List<Integer> images;
LayoutInflater inflater;
Activity activity;
public Adapter(Context context, List<String> titles , List<Integer> images , Activity activity)
{

this.titles=titles;
this.images= images;
this.activity = activity;
this.inflater = LayoutInflater.from(context);
}
@NonNull
@Override
public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = inflater.inflate(R.layout.main_item,parent,false);


return new myViewHolder(view);

@Override
public void onBindViewHolder(@NonNull myViewHolder holder, int position) {
holder.title.setText(titles.get(position));
holder.img.setImageResource(images.get(position));
holder.linearLayout.setAlpha(0.8F);

holder.linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Toast.makeText(activity, "Clciked on card", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(view.getContext(), CheckList.class);
intent.putExtra(MyConstants.HEADER_SMALL,titles.get(position));
if(MyConstants.MY_SELECTIONS.equals(titles.get(position))) {
intent.putExtra(MyConstants.SHOW_SMALL,MyConstants.FALSE_STRING);

}else{
intent.putExtra(MyConstants.SHOW_SMALL,MyConstants.TRUE_STRING);
}
view.getContext().startActivity(intent);

}
});

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

public class myViewHolder extends RecyclerView.ViewHolder{

TextView title;
ImageView img;
LinearLayout linearLayout;

public myViewHolder(@NonNull View itemView) {


super(itemView);
title= itemView.findViewById(R.id.title);
img = itemView.findViewById(R.id.img);
linearLayout = itemView.findViewById(R.id.linearLayout);
}
}

}
[10/04, 7:53 am] .: adapter
[10/04, 7:54 am] .: package com.example.packyourbag.Adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.view.ActionBarPolicy;
import androidx.recyclerview.widget.RecyclerView;

import com.example.packyourbag.Constants.MyConstants;
import com.example.packyourbag.Database.RoomDB;
import com.example.packyourbag.Models.Items;
import com.example.packyourbag.R;
import java.util.List;

public class CheckListAdapter extends RecyclerView.Adapter<CheckListViewHolder> {

Context context;
List<Items> itemsList;
RoomDB database;
String show;

public CheckListAdapter(){

}
public CheckListAdapter(Context context ,List<Items> itemsList , RoomDB database ,
String show){
this.context=context;
this.itemsList=itemsList;
this.database=database;
this.show=show;
if(itemsList.size()==0)
Toast.makeText(context.getApplicationContext(), "Nothing to show",
Toast.LENGTH_SHORT).show();

@NonNull
@Override
public CheckListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new
CheckListViewHolder(LayoutInflater.from(context).inflate(R.layout.check_list_item,parent,f
alse));
}

@Override
public void onBindViewHolder(@NonNull CheckListViewHolder holder, int position) {
holder.checkBox.setText(itemsList.get(position).getItemname());
holder.checkBox.setChecked(itemsList.get(position).getChecked());

if(MyConstants.FALSE_STRING.equals(show)){
holder.btnDelete.setVisibility(View.GONE);

holder.layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bord
er_one));

}else{
if(itemsList.get(position).getChecked()){
holder.layout.setBackgroundColor(Color.parseColor("#8e546f"));
}else {

holder.layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bord
er_one));
}
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Boolean check = holder.checkBox.isChecked();
ActionBarPolicy itemList;
database.mainDao().checkUncheck(itemsList.get(position).getID(),check);
if(MyConstants.FALSE_STRING.equals(show)){
itemsList= database.mainDao().getAllSelected(true);
notifyDataSetChanged();
}
else{
itemsList.get(position).setChecked(check);
notifyDataSetChanged();
Toast tostMessage = null;
if(tostMessage!=null){
tostMessage.cancel();
}
if(itemsList.get(position).getChecked()){
tostMessage=
Toast.makeText(context,"("+holder.checkBox.getText()+")packed",Toast.LENGTH_SHORT)
;

}else{
tostMessage = Toast.makeText(context,"("+holder.checkBox.getText()+")
Un-Packed",Toast.LENGTH_SHORT);
}
tostMessage.show();

}
}
});

holder.btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(context)
.setTitle("Delete(" + itemsList.get(position).getItemname() + ")")
.setMessage("Are you sure")
.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
database.mainDao().delete(itemsList.get(position));
itemsList.remove(itemsList.get(position));
notifyDataSetChanged();

}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

Toast.makeText(context,"Operation cancaled by thhe


users",Toast.LENGTH_SHORT).show();
}
}).setIcon(R.drawable.ic_delete)
.show();
}
});

}
}

@Override
public int getItemCount() {
return itemsList.size();
}
}
class CheckListViewHolder extends RecyclerView.ViewHolder{
LinearLayout layout;
CheckBox checkBox;
Button btnDelete;

public CheckListViewHolder(@NonNull View itemView) {


super(itemView);
layout = itemView.findViewById(R.id.linearLayout);
checkBox = itemView.findViewById(R.id.checkbox);
btnDelete = itemView.findViewById(R.id.btnDelete);
}
}
[10/04, 7:54 am] .: checklistadapter.java
[10/04, 7:55 am] .: package com.example.packyourbag.Adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.view.ActionBarPolicy;
import androidx.recyclerview.widget.RecyclerView;
import com.example.packyourbag.Constants.MyConstants;
import com.example.packyourbag.Database.RoomDB;
import com.example.packyourbag.Models.Items;
import com.example.packyourbag.R;

import java.util.List;

public class CheckListAdapter extends RecyclerView.Adapter<CheckListViewHolder> {

Context context;
List<Items> itemsList;
RoomDB database;
String show;

public CheckListAdapter(){

}
public CheckListAdapter(Context context ,List<Items> itemsList , RoomDB database ,
String show){
this.context=context;
this.itemsList=itemsList;
this.database=database;
this.show=show;
if(itemsList.size()==0)
Toast.makeText(context.getApplicationContext(), "Nothing to show",
Toast.LENGTH_SHORT).show();

}
@NonNull
@Override
public CheckListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new
CheckListViewHolder(LayoutInflater.from(context).inflate(R.layout.check_list_item,parent,f
alse));
}

@Override
public void onBindViewHolder(@NonNull CheckListViewHolder holder, int position) {
holder.checkBox.setText(itemsList.get(position).getItemname());
holder.checkBox.setChecked(itemsList.get(position).getChecked());

if(MyConstants.FALSE_STRING.equals(show)){
holder.btnDelete.setVisibility(View.GONE);

holder.layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bord
er_one));

}else{
if(itemsList.get(position).getChecked()){
holder.layout.setBackgroundColor(Color.parseColor("#8e546f"));
}else {

holder.layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bord
er_one));
}
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Boolean check = holder.checkBox.isChecked();
ActionBarPolicy itemList;
database.mainDao().checkUncheck(itemsList.get(position).getID(),check);
if(MyConstants.FALSE_STRING.equals(show)){
itemsList= database.mainDao().getAllSelected(true);
notifyDataSetChanged();
}
else{
itemsList.get(position).setChecked(check);
notifyDataSetChanged();
Toast tostMessage = null;
if(tostMessage!=null){
tostMessage.cancel();
}
if(itemsList.get(position).getChecked()){
tostMessage=
Toast.makeText(context,"("+holder.checkBox.getText()+")packed",Toast.LENGTH_SHORT)
;

}else{
tostMessage = Toast.makeText(context,"("+holder.checkBox.getText()+")
Un-Packed",Toast.LENGTH_SHORT);
}
tostMessage.show();

}
}
});

holder.btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(context)
.setTitle("Delete(" + itemsList.get(position).getItemname() + ")")
.setMessage("Are you sure")
.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
database.mainDao().delete(itemsList.get(position));
itemsList.remove(itemsList.get(position));
notifyDataSetChanged();

}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

Toast.makeText(context,"Operation cancaled by thhe


userss",Toast.LENGTH_SHORT).show();
}
}).setIcon(R.drawable.ic_delete)
.show();
}
});

}
}

@Override
public int getItemCount() {
return itemsList.size();
}
}
class CheckListViewHolder extends RecyclerView.ViewHolder{

LinearLayout layout;
CheckBox checkBox;
Button btnDelete;

public CheckListViewHolder(@NonNull View itemView) {


super(itemView);
layout = itemView.findViewById(R.id.linearLayout);
checkBox = itemView.findViewById(R.id.checkbox);
btnDelete = itemView.findViewById(R.id.btnDelete);
}
}
[10/04, 7:57 am] .: checkListViewHolder.java
[10/04, 7:58 am] .: package com.example.packyourbag.Constants;

public class MyConstants {

public static final String MY_SELECTIONS = "My Selections";

public static final String TRUE_STRING = "true";

public static final String FALSE_STRING = "false";

public static final String HEADER_SMALL = "header";

public static final String SHOW_SMALL = "show";


public static final String USER_SMALL = "user";

public static final String SYSTEM_SMALL = "system";

public static final String BASIC_NEEDS_CAMEL_CASE = "Basic Needs";

public static final String CLOTHING_CAMEL_CASE = "Clothing";

public static final String PERSONAL_CARE_CAMEL_CASE = "Personal Care";

public static final String BABY_NEEDS_CAMEL_CASE = "Baby Needs";

public static final String HEALTH_CAMEL_CASE = "Health";

public static final String TECHNOLOGY_CAMEL_CASE = "Technology";

public static final String FOOD_CAMEL_CASE = "Food";

public static final String BEACH_SUPPLIES_CAMEL_CASE = "Beach Supplies";

public static final String CAR_SUPPLIES_CAMEL_CASE = "Car Supplies";

public static final String NEEDS_CAMEL_CASE = "Needs";

public static final String MY_LIST_CAMEL_CASE = "My List";

public static final String MY_SELECTIONS_CAMEL_CASE = "My Selections";

public static final String FIRST_TIME_CAMEL_CASE = "firstTime";


}

import static androidx.room.OnConflictStrategy.REPLACE;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;

import com.example.packyourbag.Models.Items;

import java.util.List;

@Dao
public interface ItemsDao {

@Insert(onConflict = REPLACE)
void saveItems(Items items);

@Query("Select * from items where category=:category order by id asc")


List<Items> getAll(String category);

@Delete
void delete(Items items);

@Query("Update items set checked=:checked where ID=:id")


void checkUncheck(int id, boolean checked);

@Query("Select count(*) from items")


Integer getItemsCount();

@Query("delete from items where addedby=:addedBy")


default Integer deleteAllSystemItems(String addedBy) {
return null;
}

@Query("delete from items where category=:category")


Integer deleteAllByCategory(String category);

@Query("delete from items where category=:category and addedby=:addedBy")


Integer deleteAllByCategoryAndAddedBy(String category,String addedBy);

@Query("select * from items where checked=:checked order by id asc")


List<Items> getAllSelected(Boolean checked );

AppData
import android.app.Application;
import android.content.Context;

import com.example.packyourbag.Constants.MyConstants;
import com.example.packyourbag.Database.RoomDB;
import com.example.packyourbag.Models.Items;

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

public class AppData extends Application {

RoomDB database;
String category;
Context context;

public static final String LAST_VERSION ="LAST_VERSION";


public static final int NEW_VERSION = 1;

public AppData(RoomDB database) {


this.database = database;
}

public AppData(Context context) {


this.context = context;
}

public List<Items> getBasicData(){


category = "Basic Needs ";
List<Items> basicItem = new ArrayList<>();
basicItem.clear();
basicItem.add(new Items("Visa",category,false));
basicItem.add(new Items("passport",category,false));
basicItem.add(new Items("Tickets",category,false));
basicItem.add(new Items("Wallets",category,false));
basicItem.add(new Items("Driving",category,false));
basicItem.add(new Items("Currency",category,false));
basicItem.add(new Items("House Key",category,false));
basicItem.add(new Items("Book",category,false));
basicItem.add(new Items("Travel Pillow",category,false));
basicItem.add(new Items("Eye patch",category,false));
basicItem.add(new Items("Umbrealla",category,false));
basicItem.add(new Items("Note Book",category,false));

return basicItem;
}

public List<Items> getPersonalCareData(){


String [] data = {"Tooth-brush","Tooth-paste","Floss","Mouthwash","Shaving
cream","Soap","Fiber","Shampoo"
,"Hair Conditioner","Brush","Lip Cream"};
return prePareItemsList(MyConstants.PERSONAL_CARE_CAMEL_CASE,data);
}
public List<Items> getClothingData(){
String [] data = {"T-shirt", "Shirt", "Polo shirt", "Blouse", "Tank top", "Sweater",
"Hoodie", "Jacket", "Coat", "Blazer", "Cardigan", "Dress", "Skirt", "Pants", "Jeans", "Shorts",
"Jumpsuit", "Romper", "Suit", "Tie", "Bowtie", "Scarf", "Shawl", "Poncho", "Vest", "Tunic",
"Kimono", "Kaftan", "Leggings", "Joggers", "Capri pants", "Culottes", "Onesie", "Pajamas",
"Lingerie", "Swimsuit", "Bikini", "Board shorts", "Rash guard", "Socks", "Stockings",
"Tights", "Gloves", "Mittens", "Hat", "Beanie", "Cap", "Headband", "Belt", "Tie clip"};
return prePareItemsList(MyConstants.CLOTHING_CAMEL_CASE,data);
}

public List<Items> getBabyNeedsData(){


String [] data = {"Bib", "Diapers", "Onesies", "Baby wipes", "Blanket", "Swaddle
blankets", "Baby lotion", "Baby shampoo", "Baby soap", "Baby bathtub", "Baby clothes",
"Baby hat", "Baby socks", "Baby shoes", "Baby mittens", "Pacifier", "Baby bottles", "Bottle
warmer", "Formula", "Breast pump", "Burp cloths", "Baby carrier", "Stroller", "Car seat",
"Changing table", "Diaper bag", "Baby monitor", "Crib", "Crib mattress", "Baby bedding",
"Baby toys", "Teething toys", "High chair"};
return prePareItemsList(MyConstants.BABY_NEEDS_CAMEL_CASE,data);
}

public List<Items> getHealthData() {


String[] data = { "Sunscreen", "Insect repellent", "Hand sanitizer", "Travel-sized tissue
packs", "Personal hygiene items (toothbrush, toothpaste, floss, deodorant)", "Multivitamins",
"Reusable face mask", "Digital thermometer", "Emergency contact information", "Health
insurance card", "List of emergency contacts", "Medical history summary", "Water purification
tablets", "Compression socks", "Travel-sized hand lotion", "Lip balm with SPF", "Sleep aids",
"Earplugs", "Travel-sized wet wipes", "Anti-bacterial hand wipes", "Anti-fungal cream",
"Condoms or other contraceptives", "Allergy relief nasal spray", "Eye drops", "Disposable
gloves"};
return prePareItemsList(MyConstants.HEALTH_CAMEL_CASE, data);

}
public List<Items> getTechnologyData(){
String [] data = {"Smartphone", "Laptop", "Tablet", "Portable charger", "Travel adapter",
"Headphones", "Camera", "Power bank", "External hard drive", "Travel router", "Noise-
canceling headphones", "GPS device", "E-book reader", "Smartwatch", "Fitness tracker",
"Bluetooth earbuds", "Universal charging cable", "Travel-sized keyboard", "USB flash drive",
"Camera accessories (tripod, lens, etc.)", "Portable Wi-Fi hotspot", "Travel-sized tech
organizer", "Travel-friendly laptop stand", "Travel surge protector"};
return prePareItemsList(MyConstants.TECHNOLOGY_CAMEL_CASE,data);
}

public List<Items> getFoodData(){


String [] data = {"Granola bars", "Trail mix", "Dried fruits", "Nuts", "Beef jerky", "Protein
bars", "Crackers", "Cheese sticks", "Hard-boiled eggs", "Fresh fruits (e.g., apples, bananas)",
"Baby carrots", "Hummus cups", "Yogurt cups", "Pre-cut vegetables", "Sandwiches", "Wraps",
"Peanut butter or almond butter packets", "Instant oatmeal packets", "Cereal cups", "Instant
noodles", "Canned tuna or chicken", "Canned beans", "Rice cakes", "Popcorn", "Dark
chocolate", "Energy drinks", "Bottled water", "Juice boxes", "Sports drinks", "Tea bags",
"Coffee packets", "Instant soup packets"};
return prePareItemsList(MyConstants.FOOD_CAMEL_CASE,data);
}

public List<Items> getBeachSuppliesData(){


String [] data = {"Beach towel", "Sunscreen", "Swimsuit", "Sunglasses", "Beach
umbrella", "Beach chair", "Sun hat", "Flip-flops", "Beach bag", "Waterproof phone case",
"Cooler", "Water bottles", "Snorkel gear", "Beach toys (buckets, shovels, frisbee)", "Beach
ball", "Inflatable floaties", "Sunshade tent", "Portable beach mat", "Water shoes", "Wet wipes",
"Sand anchor for beach umbrella", "Beach blanket", "Portable grill", "Beach tent", "Mesh
beach bag (for sand to fall through)", "Waterproof pouch for valuables"};
return prePareItemsList(MyConstants.BEACH_SUPPLIES_CAMEL_CASE,data);
}

public List<Items> getCarSuppliesData(){


String [] data = {
"Car registration and insurance documents", "Driver's license", "Spare tire", "Car
jack", "Jumper cables", "Tire pressure gauge", "Tire inflator", "Wheel wrench", "Car manual",
"First aid kit", "Flashlight", "Emergency roadside kit", "Reflective triangles or cones",
"Blanket", "Bottled water", "Non-perishable snacks", "Phone charger", "Portable phone power
bank", "GPS or navigation device", "Road atlas or maps"};
return prePareItemsList(MyConstants.CAR_SUPPLIES_CAMEL_CASE,data);
}
public List<Items> getNeedsData(){
String [] data = {"BackPack" , "Daily Bags","Laundary Bag","Sewing Kit ","Travel
Lock","Luggage Bag","Travel Lock","Luggage Tag","Magzing","Sport Equipment"};
return prePareItemsList(MyConstants.NEEDS_CAMEL_CASE,data);
}

public List<Items> prePareItemsList(String category,String []data){


List<String> list = Arrays.asList(data);
List<Items> dataList = new ArrayList<>();
dataList.clear();

for(int i=0;i<list.size();i++){
dataList.add(new Items(list.get(i),category,false));
}
return dataList;
}

public List<List<Items>> getAllData(){

List<List<Items>> listOfAllItems = new ArrayList<>();


listOfAllItems.clear();
listOfAllItems.add(getBasicData());
listOfAllItems.add(getClothingData());
listOfAllItems.add(getPersonalCareData());
listOfAllItems.add(getBabyNeedsData());
listOfAllItems.add(getHealthData());
listOfAllItems.add(getTechnologyData());
listOfAllItems.add(getFoodData());
listOfAllItems.add(getBeachSuppliesData());
listOfAllItems.add(getCarSuppliesData());
listOfAllItems.add(getNeedsData());
return listOfAllItems;
}
public void persistAllData(){
List<List<Items>> listOfAllItems = getAllData();
for(List<Items> list:listOfAllItems) {

for (Items items : list) {


database.mainDao().saveItems(items);
}
}
System.out.println("Data added");
}
}

roomdb
import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.example.packyourbag.Dao.ItemsDao;
import com.example.packyourbag.Models.Items;

@Database(entities = Items.class,version = 1,exportSchema = false)


public abstract class RoomDB extends RoomDatabase {
private static RoomDB database;
private static String DATABASE_NAME = "MyDb";
public synchronized static RoomDB getInstance(Context context){
if (database == null){

database = Room.databaseBuilder(context.getApplicationContext(),
RoomDB.class,DATABASE_NAME).allowMainThreadQueries()
.fallbackToDestructiveMigration()
.build();

}
return database;
}

public abstract ItemsDao mainDao();

item.java
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import java.io.Serializable;

@Entity(tableName="items")
public class Items implements Serializable {

@PrimaryKey(autoGenerate = true)
int ID = 0;

@ColumnInfo(name ="itemname")
String itemname;

@ColumnInfo(name = "category")
String category;

@ColumnInfo(name ="addedby")
public String addedby;

@ColumnInfo(name="checked")
Boolean checked = false;

public Items() {

}
public Items(String itemname , String category ,Boolean checked){
this.addedby="system";
this.itemname=itemname;
this.category=category;
this.checked=checked;
}

public Items(String itemname , String category , String addedby , Boolean checked){


this.itemname=itemname;
this.category=category;
this.addedby=addedby;
this.checked= checked;
}
public int getID() {
return ID;
}

public void setID(int ID) {


this.ID = ID;
}

public String getItemname() {


return itemname;
}

public void setItemname(String itemname) {


this.itemname = itemname;
}

public String getCategory() {


return category;
}

public void setCategory(String category) {


this.category = category;
}

public String getAddedby() {


return addedby;
}
public void setAddedby(String addedby) {
this.addedby = addedby;
}

public Boolean getChecked() {


return checked;
}

public void setChecked(Boolean checked) {


this.checked = checked;
}
}

checklist.java

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.room.Room;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.example.packyourbag.Adapter.CheckListAdapter;
import com.example.packyourbag.Constants.MyConstants;
import com.example.packyourbag.Database.RoomDB;
import com.example.packyourbag.Models.Items;

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

public class CheckList extends AppCompatActivity {

RecyclerView recyclerView;
CheckListAdapter checkListAdapter;
RoomDB database;
List<Items> itemsList = new ArrayList<>();
String header,show;
EditText textAdd;
Button btnAdd;
LinearLayout linearLayout;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_list);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
header = intent.getStringExtra(MyConstants.HEADER_SMALL);
show = intent.getStringExtra(MyConstants.SHOW_SMALL);
getSupportActionBar().setTitle(header);

textAdd = findViewById(R.id.txtAdd);
btnAdd= findViewById(R.id.btnAdd);
recyclerView = findViewById(R.id.recyclerView);
linearLayout= findViewById(R.id.linearLayout);

database = RoomDB.getInstance(this);

if(MyConstants.FALSE_STRING.equals(show)){
linearLayout.setVisibility(View.GONE);
itemsList=database.mainDao().getAllSelected(true);

}else {
itemsList=database.mainDao().getAll(header);
}
updateRecycler(itemsList);

btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String itemName= textAdd.getText().toString();
if(itemName!=null && !itemName.isEmpty()){
addNewItem(itemName);
Toast.makeText(CheckList.this,"Item added",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(CheckList.this,"Empty cant be
added",Toast.LENGTH_SHORT).show();
}
}
});

private void addNewItem(String itemName){


Items item = new Items();
item.setChecked(false);
item.setCategory(header);
item.setItemname(itemName);

item.setAddedby(MyConstants.USER_SMALL);
database.mainDao().saveItems(item);
itemsList = database.mainDao().getAll(header);
updateRecycler(itemsList);
recyclerView.scrollToPosition(checkListAdapter.getItemCount()-1);
textAdd.setText("");

private void updateRecycler(List<Items> itemsList){

recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(1,
LinearLayoutManager.VERTICAL));
checkListAdapter= new CheckListAdapter(CheckList.this,itemsList,database,show);
recyclerView.setAdapter((checkListAdapter));

}
}

main.java
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.Toast;

import com.example.packyourbag.Adapter.Adapter;
import com.example.packyourbag.Constants.MyConstants;
import com.example.packyourbag.Data.AppData;
import com.example.packyourbag.Database.RoomDB;

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

public class MainActivity extends AppCompatActivity {

RecyclerView recyclerView;
List<String> titles;
List<Integer> images;
Adapter adapter;
RoomDB database;

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

getSupportActionBar().hide();
recyclerView = findViewById(R.id.recyclerView);

addAddTitles();
addAllImages();
persistAppData();
database = RoomDB.getInstance(this);
System.out.println("--------------------------------->"
+database.mainDao().getAllSelected(false).get(0).getItemname());
adapter = new Adapter(this,titles,images,MainActivity.this);
GridLayoutManager gridLayoutManager =new
GridLayoutManager(this,2,GridLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(adapter);
}
private static final int TIME_INTERVAL = 2000;

private long mBackPressed;

@Override
public void onBackPressed() {
if(mBackPressed+TIME_INTERVAL>System.currentTimeMillis()){
super.onBackPressed();
return;
}else {

Toast.makeText(this, "Tap back button in order to exit",


Toast.LENGTH_SHORT).show();
}

mBackPressed =System.currentTimeMillis();

private void persistAppData() {


SharedPreferences prefs = getSharedPreferences("Database_mainactivity",
MODE_PRIVATE);

// Your code to edit and save preferences goes here


SharedPreferences.Editor editor = prefs.edit();

database = RoomDB.getInstance(this);
AppData appData = new AppData(database);
int last = prefs.getInt(AppData.LAST_VERSION,0);

if(!prefs.getBoolean(MyConstants.FIRST_TIME_CAMEL_CASE,false)) {
appData.persistAllData();
editor.putBoolean(MyConstants.FIRST_TIME_CAMEL_CASE,true);
editor.commit();
}else if (last<AppData.NEW_VERSION){
database.mainDao().deleteAllSystemItems(MyConstants.SYSTEM_SMALL);
appData.persistAllData();
editor.putInt(AppData.LAST_VERSION,AppData.NEW_VERSION);
editor.commit();
}

private void addAddTitles(){


titles = new ArrayList<>();
titles.add(MyConstants.BASIC_NEEDS_CAMEL_CASE);
titles.add(MyConstants.CLOTHING_CAMEL_CASE);
titles.add(MyConstants.PERSONAL_CARE_CAMEL_CASE);
titles.add(MyConstants.BABY_NEEDS_CAMEL_CASE);
titles.add(MyConstants.HEALTH_CAMEL_CASE);
titles.add(MyConstants.TECHNOLOGY_CAMEL_CASE);
titles.add(MyConstants.FOOD_CAMEL_CASE);
titles.add(MyConstants.BEACH_SUPPLIES_CAMEL_CASE);
titles.add(MyConstants.CAR_SUPPLIES_CAMEL_CASE);
titles.add(MyConstants.NEEDS_CAMEL_CASE);
titles.add(MyConstants.MY_LIST_CAMEL_CASE);
titles.add(MyConstants.MY_SELECTIONS_CAMEL_CASE);
}

private void addAllImages(){


images = new ArrayList<>();
images.add(R.drawable.p1);
images.add(R.drawable.p2);
images.add(R.drawable.p3);
images.add(R.drawable.p4);
images.add(R.drawable.p5);
images.add(R.drawable.p6);
images.add(R.drawable.p7);
images.add(R.drawable.p8);
images.add(R.drawable.p9);
images.add(R.drawable.p10);
images.add(R.drawable.p11);
images.add(R.drawable.p12);
}
}

main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="@drawable/background3"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@drawable/wave2"
android:id="@+id/title_view"
android:textAlignment="center"
android:text="PACK YOUR BAG"
android:textSize="35sp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textColor="@color/white"
/>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerView"
android:layout_below="@+id/title_view"

/>

</RelativeLayout>

mainitem.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:gravity="center"
android:background="#E3ACAC"
android:padding="10dp"
android:layout_gravity="center_vertical|center_horizontal"
>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/img"
android:src="@drawable/shopping_bag"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title"
android:text="Basic Needs"
android:textSize="20sp"
android:textColor="@color/black"
android:textStyle="bold"
android:textAlignment="center"
/>

</LinearLayout>
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:padding="10dp"
android:textAlignment="center"
android:id="@+id/linearLayout"
android:orientation="horizontal">

<CheckBox
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:id="@+id/checkbox"
android:layout_gravity="center"
android:textSize="20dp"
android:text="This is just for test"

/>
<Button
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content"
android:id="@+id/btnDelete"
android:layout_gravity="center"
android:background="@drawable/delete_white"
/>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E3ACAC"
tools:context=".CheckList">

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerView"
android:layout_marginBottom="60dp"

/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:id="@+id/linearLayout"
android:background="#FFD6D6">

<EditText
android:id="@+id/txtAdd"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:hint="Enter item to add"
android:textSize="22sp"
android:layout_marginLeft="8dp"
android:textStyle="bold"/>

<Button
android:id="@+id/btnAdd"
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content"
android:background="@drawable/ic_circle"
android:layout_marginEnd="8dp"
/>

</LinearLayout>

</RelativeLayout>

You might also like