Online Shopping System Synopsis by Atulya and Sakshi

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 147

INTERNATIONAL SCHOOL OF INFORMATICS

AND MANAGEMENT

MARCH-2021
ONLINE SHOPPING SYSTEM
MCA-551
CASE STUDY ON MOBILE
APPLICATIONS

SUBMITTED TO: SUBMITTED BY:

MS. MEENAL ATULYA AGRAWAL

KAKKAR MR. Roll No: MCA/2019/3951

PEEYUSH Enrolment No: 19CIIXX212

PAREEK SAKSHI HISSARIA


Roll No: MCA/2019/4071
Enrolment No:
192CIIXX272
TABLE OF CONTENTS

S. No. Headings
1. Project Specification
1. Project Overview
2.Project Need
2. Specific Requirements
3. External
Interface
Requirements
4. Hardware
3. Interfaces
5.Software Interfaces
Software Product Features
6. E-R Diagram
7. Data Flow Diagram
8. Use Case Diagram

4. Advantages 9. Screenshots
5. Limitations 10. Coding
6. Conclusion
7. Bibliography
1) Project Specification: -
1.1) Project Overview: -
The Project is aimed at online shopping in which customer need not to go anywhere they can just do it at
their home by registering themselves on the online shopping application and after that they can place
order whatever they require.
1.2) Project Need: -
The system displays the list of all issues that are open, closed, in progress. If the user can get registered
by clicking on the login button and provide the required information as specified. Each time the
registered customer come on to the application they can makes use of the user name and the password
that is allocated to him and get the details.
2.) Specific Requirements: -

2.1) External Interface Requirements: -


•User Login Screen:

Various fields are:


• User id
• Password
2.2) Hardware Interfaces: -

RAM Required-8GB or more


HARD DISK-1TB

2.3) Software Interfaces: -


Back-end- Firebase with Android Studio
Front-end- JAVA, XML
OPERATING SYSTEM-WINDOWS 10
Database- Firebase
3.) Software Product Features: -
3.1) E-R Diagram: -

Seller_Name Email Phone


Password
Address
S_ID
Seller

Password C_Name
C_ID
A_Id Password

Mobile_No

Online
Admin Shopping Customer
System

Email Address
City
Mobile_No
Email

State
Pin_Code

Color
Product
Type

Manufacturing
date
P_Price P_ID

P_Description P_Name
3.2) Data Flow Diagram

Request for order


and shipment
Check the status
Online Customer
Admin Shopping Get the
response for
Get the response System
delivery
for all transactions

Zero Level Data Flow Diagram


Data Flow Diagram

Login Activity Management

Shipping Order Management


Management

Admin System Customer Profile


Management Management

Online Shopping
Seller System
Payment
Management
Management

Product Details Management


 

One Level Data Flow Diagram


3.3) Use Case Diagram

Login

Register

User ID

Password

Admin Customer
Add Category

Add Item
 

Manage Item

Manage Order

View Item

Make Payment

Seller
Change Password

Logout
3.4) Screenshots
Main Activity Screenshots
3.5) Coding

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="@drawable/main"
tools:context=".Buyers.MainActivity">

<ImageView
android:id="@+id/app_logo"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:background="@android:color/holo_red_light"
android:src="@drawable/tbs" />

<TextView
android:layout_width="300dp"
android:layout_height="100dp"
android:background="@drawable/tbs2"
android:layout_alignBottom="@id/app_log
o"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:layout_marginBottom="-114dp" />

<Button
android:id="@+id/register"
android:layout_width="match
_parent"
android:layout_height="wrap_content"
android:layout_above="@id/login"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:padding="20dp"
android:text="Join Now"
android:textAllCaps="false"
android:textColor="#3E2723"
android:textSize="24sp"
android:textStyle="bold" />
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/seller_begin"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#B00020"
android:padding="20dp"
android:textSize="24sp"
android:textAllCaps="false"
android:text="Already a customer?Login Here!"
android:textColor="@android:color/darker_gray"
/>

<TextView
android:id="@+id/seller_begin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wants to become a Seller?"
android:textSize="20dp"
android:textColor="@android:color/black"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="19dp"
android:layout_marginBottom="10dp"
/>

</RelativeLayout>
MainActivity.java

package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCom
patActivity;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.teamstogether.twentyfourbysevenshopping.Model.Users;
import com.teamstogether.twentyfourbysevenshopping.Prevalent.Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.Sellers.SellerHomeActivity;
import
com.teamstogether.twentyfourbysevenshopping.Sellers.SellerRegistrationAct
ivity;

import io.paperdb.Paper;

public class MainActivity extends AppCompatActivity {

private Button loginButton;


private Button registerButton;
private ProgressDialog loadingBar;
private TextView sellerBegin;

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

registerButton = (Button) findViewById(R.id.register);


loginButton = (Button) findViewById(R.id.login);
sellerBegin = (TextView) findViewById(R.id.seller_begin);
loadingBar = new ProgressDialog(this);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
}
});

sellerBegin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SellerRegistrationActivity.class);
startActivity(intent);
}
});

registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(intent2);
}
});

String UserPhoneKey = Paper.book().read(Prevalent.UserPhoneKey); String


UserPasswordKey = Paper.book().read(Prevalent.UserPasswordKey);

if (UserPhoneKey != "" && UserPasswordKey != "")


{
if (!TextUtils.isEmpty(UserPhoneKey) && !
TextUtils.isEmpty(UserPasswordKey))
{

AllowAccess(UserPhoneKey, UserPasswordKey);

loadingBar.setTitle("Already Logged in");


loadingBar.setMessage("Please wait.....");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
}
}
}

@Override
protected void onStart() {
super.onStart();

FirebaseUser firebaseUser =
FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser !=null)
{
Intent intent = new Intent(MainActivity.this, SellerHomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
}

private void
AllowAccess(final String
phone, final String
password)
{
final
DatabaseReference
RootRef;
RootRef =
FirebaseDatabase.getIn
stance().getReference()
;

RootRef.addListenerForSingleValueEvent(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
if (dataSnapshot.child("Users").child(phone).exists())
{
Users usersData =
dataSnapshot.child("Users").child(phone).getValue(Users.class)
;

if (usersData.getPhone().equals(phone))
{
if (usersData.getPassword().equals(password))
{
Toast.makeText(MainActivity.this, "Please wait, you are already logged in...",
Toast.LENGTH_SHORT).show();
loadingBar.dismiss();

Intent intent = new Intent(MainActivity.this,


HomeActivity.class); Prevalent.currentOnlineUser = usersData;
startActivity(intent);
}
else
{
loadingBar.dismiss();
Toast.makeText(MainActivity.this, "Password is incorrect.",
Toast.LENGTH_SHORT).show();
}
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}
}
activity_home.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" /
>

<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
HomeActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import
androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import
com.google.android.material.floatingactionbutton.FloatingAct
ionButton;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.database.DatabaseReference; import
com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
import
com.teamstogether.twentyfourbysevenshopping.Admin.AdminMa
intainProductsActivity;
import com.teamstogether.twentyfourbysevenshopping.Model.Products;
import com.teamstogether.twentyfourbysevenshopping.Prevalent.Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.ViewHolder.ProductViewHo
lder;

import de.hdodenhof.circleimageview.CircleImageView;
import io.paperdb.Paper;

public class HomeActivity extends AppCompatActivity


implements NavigationView.OnNavigationItemSelectedListener
{
private DatabaseReference ProductsRef;
private RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;

private String type = "";


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

Intent intent = getIntent();


Bundle bundle = intent.getExtras();
if (bundle != null)
{
type =
getIntent().getExtras().get("Admin").toString();
}

ProductsRef = FirebaseDatabase.getInstance().getReference().child("Products");

Paper.init(this);

Toolbar toolbar = findViewById(R.id.toolbar);


toolbar.setTitle("Home");
setSupportActionBar(toolbar);

FloatingActionButton fab = findViewById(R.id.fab);


fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!type.equals("Admin"))
{
Intent intent = new Intent(HomeActivity.this, CartActivity.class);
startActivity(intent);
}
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle =new ActionBarDrawerToggle(
this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView =
findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

View headerView = navigationView.getHeaderView(0);


TextView userNameTextView = headerView.findViewById(R.id.user_profile_name);
CircleImageView profileImageView = headerView.findViewById(R.id.user_profile_image);

if (!type.equals("Admin"))
{
userNameTextView.setText(Prevalent.currentOnlineUser.getName());

Picasso.get().load(Prevalent.currentOnlineUser.getImage()).placeholder(R.drawable.profile).i
nto(profile
ImageView);
}

recyclerView = findViewById(R.id.recycler_menu);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
}

@Override
protected void onStart() {
super.onStart();

FirebaseRecyclerOptions<Products> options =
new
FirebaseRecyclerOptions.Builder<Products>()
.setQuery(ProductsRef.orderByChild("productState").equalTo("Approved"),
Products.class)
.build();

FirebaseRecyclerAdapter<Products, ProductViewHolder> adapter =


new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ProductViewHolder holder, int i,
@NonNull final Products model)
{
holder.txtproductName.setText(model.getPname());
holder.txtProductDescription.setText(model.getDescription());
holder.txtProductPrice.setText("Price = " +"₹"+ model.getPrice() );
Picasso.get().load(model.getImage()).into(holder.imageView);

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

if (type.equals("Admin"))
{
Intent intent = new Intent(HomeActivity.this,
AdminMaintainProductsActivity.class);
intent.putExtra(
"pid",model.getPid());
startActivity(intent);
}
else
{
Intent intent = new Intent(HomeActivity.this,
ProductDetailsActivity.class); intent.putExtra("pid",model.getPid());
startActivity(intent);
}

}
});
}

@NonNull

@Override
public
ProductVie
wHolder
onCreateVi
ewHolder(
@NonNull
ViewGrou
p parent,
int
viewType) {
View view =
LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items_layout,
parent, false);
ProductViewHolder holder = new
ProductViewHolder(view);
return holder;
}
};
recyclerView.setAd
apter(adapter);
adapter.startListening();
}

@Override
public void
onBackPressed() {
DrawerLayout
drawer = (DrawerLayout)
findViewById(R.id.drawer_layout
);
if (drawer.isDrawerOpen(GravityCompat.START)){
drawer.closeDrawer(GravityCompat.START);
}else {
super.onBackPressed();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it
is present.
// }
return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull
MenuItem item) {

int id = item.getItemId();

if (id == R.id.nav_cart)
{
if (!type.equals("Admin"))
{
Intent intent = new Intent(HomeActivity.this, CartActivity.class);
startActivity(intent);
}

}
else if (id == R.id.nav_search)
{
if (!type.equals("Admin"))
{
Intent intent = new Intent(HomeActivity.this, SearchProductActivity.class);
startActivity(intent);
}

}
else if (id == R.id.categories)
{

}
else if (id == R.id.nav_settings)
{
if (!type.equals("Admin"))
{
Intent intent = new Intent(HomeActivity.this, SettingActivity.class);
startActivity(intent);
}

}
else if (id == R.id.logout)
{
if (!type.equals("Admin"))
{
Paper.book().destroy();

Intent intent = new Intent(HomeActivity.this, MainActivity.class);


intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

finish();
}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);


drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Register Activity Screenshot
Code
activity_register.xml
<?xml version="1.0"
encoding="utf-8"?>
<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:background="@drawable/register"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Buyers.RegisterActivity">

<ImageView
android:id="@+id/login_applogo"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:src="@drawable/tbs" />

<EditText
android:id="@+id/register_username_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/login_applogo"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:hint="Name"
android:textColor="#FFDE03"
android:textColorHint="#FFDE03"
android:textSize="17sp"
android:textStyle="bold"
/>

<EditText
android:id="@+id/register_phone_number_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register_username_input"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:hint="Phone Number"
android:inputType="number"
android:textColor="#FFDE03"
android:textColorHint="#FFDE03"
android:textSize="17sp"
android:textStyle="bold"
/>

<EditText
android:id="@+id/register_password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register_phone_number_input"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="6dp"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#FFDE03"
android:textColorHint="#FFDE03"
android:textSize="17sp"
android:textStyle="bold"
/>

<Button
android:id="@+id/register_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register_password_input"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#B00020"
android:padding="17dp"
android:textSize="18sp"
android:textAllCaps="false"
android:text="Create
Account!"
android:textColor="@android:
color/darker_gray"
/>

</RelativeLayout>
RegisterActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

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

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCo
mpatActivity;

import
com.google.android.gms.tasks.O
nCompleteListener;
import
com.google.android.gms.tasks.Ta
sk;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.teamstogether.twentyfourbysevenshopping.R;

import java.util.HashMap;

public class RegisterActivity extends AppCompatActivity


{
private Button createAccountBtn;
private EditText InputName,InputPhoneNumber,InputPassword;
private ProgressDialog loadingBar;

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

createAccountBtn = (Button)
findViewById(R.id.register_btn);
InputName = (EditText) findViewById(R.id.register_username_input);
InputPhoneNumber = (EditText) findViewById(R.id.register_phone_number_input);
InputPassword= (EditText) findViewById(R.id.register_password_input); loadingBar
= new ProgressDialog(this);

createAccountBtn.setOnClickListener(new View.OnClickListener()
}

private void CreateAccount() {


String name = InputName.getText().toString();
String phone = InputPhoneNumber.getText().toString();
String password = InputPassword.getText().toString();

if(TextUtils.isEmpty(name))
{
Toast.makeText(this,"Please write your
name...",Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(phone))
{
Toast.makeText(this,"Please write your phone
number...",Toast.LENGTH_SHORT).show();

}
else if (TextUtils.isEmpty(password))
{
Toast.makeText(this, "Please write your password",
Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Create Account");
loadingBar.setMessage("Please wait, while we are checking the credentials");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
ValidatephoneNumber(name,phone,password);
}
}

private void ValidatephoneNumber(final String


name, final String phone, final String password) {
final DatabaseReference RoofRef;
RoofRef =
FirebaseDatabase.getInstance().getReference();

RoofRef.addListenerForSingleValueEvent(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(!(snapshot.child("Users").child(phone).exists()))
{ HashMap<String,Object> userdataMap = new
HashMap<>(); userdataMap.put("phone",phone);
userdataMap.put("password",password);
userdataMap.put("name",name);

RoofRef.child("Users").child(phone).updateChildren(userdataMap).addOnCompleteListener(new
OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(RegisterActivity.this, "Congratulations, your account has been
created", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Intent intent = new Intent(RegisterActivity.this,
LoginActivity.class); startActivity(intent);
}
else {
Toast.makeText(RegisterActivity.this,"Network Error: Please try again after
some time...",Toast.LENGTH_SHORT).show();
}
}
}
);
}
e
lse {
Toast.makeText(RegisterActivity.this, "This "+phone +" already exits",
Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Toast.makeText(RegisterActivity.this, "Please try again later using another phone
number...", Toast.LENGTH_SHORT).show();
Intent intent = new
Intent(RegisterActivity.this,LoginActivity.class);
startActivity(intent);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
}
);
}

}
Login Activity Screenshot
activity_login.xml
Code
<?xml
version="1.0"
encoding="utf-
8"?>
<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="@drawable/login"
tools:context=".Buyers.LoginActivity">

<ImageView
android:id="@+id/login_applogo"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:src="@drawable/tbs" />

<EditText
android:id="@+id/login_phone_number_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/login_applogo"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:hint="Phone Number"
android:inputType="number"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black"
android:textSize="17sp"
android:textStyle="bold"
/>

<EditText
android:id="@+id/login_password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/login_phone_number_input"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="6dp"
android:hint="Password"
android:inputType="textPassword"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black"
android:textSize="17sp"
android:textStyle="bold"
/>

<LinearLayout
android:id="@+id/linear_layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/login_password_input"
android:layout_marginTop="5dp"
>

<com.rey.material.widget.CheckBox
android:id="@+id/remember_me_chkb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Material.Drawable.CheckBox"
android:text="Remember me"
android:textColor="@android:color/black"
app:cbd_strokeColor="@android:color/holo_green_light"
android:gravity="center_vertical"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginLeft="17dp"
/>

<TextView
android:id="@+id/forgot_password_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password?"
android:textColor="@android:color/black"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginLeft="80dp"
/>
</LinearLayout>

<Button
android:id="@+id/login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linear_layout_1"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#B00020"
android:padding="17dp"
android:textSize="18sp"
android:textAllCaps="false"
android:text="Login"
android:textColor="@andro
id:color/darker_gray"
/>

<TextView
android:id="@+id/admin_panel_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm an Admin?"
android:layout_alignParentEnd="true"
android:layout_below="@+id/login_btn"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginLeft="80dp"
android:layout_marginEnd="23dp"
/>

<TextView
android:id="@+id/not_admin_panel_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm not an Admin?"
android:layout_alignParentStart="true"
android:layout_below="@+id/login_btn"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginLeft="80dp"
android:layout_marginEnd="23dp"
android:layout_marginStart="25dp"
android:visibility="invisible"
/>

</RelativeLayout>
LoginActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

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

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCom
patActivity;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rey.material.widget.CheckBox;
import
com.teamstogether.twentyfourbysevenshopping.Admin.Ad
minHomeActivity;
import com.teamstogether.twentyfourbysevenshopping.Model.Users;
import com.teamstogether.twentyfourbysevenshopping.Prevalent.Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;

import io.paperdb.Paper;

public class LoginActivity extends AppCompatActivity {


private EditText InputNumber,InputPassword;
private Button LoginButton;
private TextView AdminLink,NotAdminLink,
ForgetPasswordLink;

private ProgressDialog loadingBar; private


CheckBox chkBoxRememberMe;

private String parentDbName = "Users";

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

LoginButton = (Button)
findViewById(R.id.login_btn);
NotAdminLink = (TextView) findViewById(R.id.not_admin_panel_link);
ForgetPasswordLink = (TextView) findViewById(R.id.forgot_password_link);
loadingBar = new ProgressDialog(this);

chkBoxRememberMe = (CheckBox) findViewById(R.id.remember_me_chkb);


Paper.init(this);

LoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LoginUser();
}
});

ForgetPasswordLink.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, ResetPasswordActivity.class);
intent.putExtra("check","login");
startActivity(intent);
}
});

AdminLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{ LoginButton.setText("Login Admin");
AdminLink.setVisibility(View.INVISIBLE);
NotAdminLink.setVisibility(View.VISIBLE);
parentDbName = "Admins";
}
});
NotAdminLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{ LoginButton.setText("Login");
AdminLink.setVisibility(View.VISIBLE);
NotAdminLink.setVisibility(View.INVISIBLE);
parentDbName = "Users";
}
});

priv
ate
void
Logi
nUse
r() {
String phone = InputNumber.getText().toString(); String
password = InputPassword.getText().toString();
Toast.makeText(this, "Please write your phone number...", Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please write your password...", Toast.LENGTH_SHORT).show();
}
else {
loadingBar.setTitle("Login Account");
loadingBar.setMessage("Please wait, while are checking the credentials...");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();

AllowAccessToAccount(phone,password);
}
}

private void AllowAccessToAccount(final String phone, final String password)


{
if (chkBoxRememberMe.isChecked())
{
Paper.book().write(Prevalent.UserPhoneKey,phone);
Paper.book().write(Prevalent.UserPasswordKey,password);
}

final DatabaseReference RootRef;


RootRef = FirebaseDatabase.getInstance().getReference();

RootRef.addListenerForSingleValueEvent(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.child(parentDbName).child(phone).exists())
{
Users usersData =
snapshot.child(parentDbName).child(phone).getValue(Users.cl
ass);

if (usersData.getPhone().equals(phone))
{
if (usersData.getPassword().equals(password))
{
if (parentDbName.equals("Admins")){
Toast.makeText(LoginActivity.this,
"Welcome Admin, you are logged in successfully",
Toast.LENGTH_SHORT).show();
loadingBar.dismiss();

Intent intent = new Intent(LoginActivity.this,


AdminHomeActivity.class); startActivity(intent);
}
else if (parentDbName.equals("Users")){
Toast.makeText(LoginActivity.this,
"logged in successfully",
Toast.LENGTH_SHORT).show();
loadingBar.dismiss();

Intent intent = new Intent(LoginActivity.this, HomeActivity.class);


Prevalent.currentOnlineUser = usersData;
startActivity(intent);
}
}
else {
loadingBar.dismiss();
Toast.makeText(LoginActivity.this, "Password is incorrect...",
Toast.LENGTH_SHORT).show();
}
}
}
else {
Toast.makeText(LoginActivity.this,"Account with
this "+phone
+" number doesn't exits",Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
}
activity_admin_home.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Admin.AdminHomeActivity">

<TextView
android:id="@+id/admin_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome Dear Admin"
android:textAlignment="center"
android:textSize="17dp"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold"
android:layout_marginTop="10dp"
/>

<Button
android:id="@+id/maintain_btn"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_below="@id/admin_welcome"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="25dp"
android:background="@color/colorPrimaryDark"
android:text="Maintain Products"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textAllCaps="false"
/>

<Button
android:id="@+id/check_order_btn"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_below="@id/maintain_btn"
android:layout_margin="20dp"
android:layout_marginRight="10dp"
android:background="@color/colorPrimaryDark"
android:text="Check New Orders"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textAllCaps="false"
/>

<Button
android:id="@+id/check_approve_products_btn"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_below="@id/check_order_btn"
android:layout_margin="20dp"
android:layout_marginRight="10dp"
android:background="@color/colorPrimaryDark"
android:text="Check and Approve New Products"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textAllCaps="false"
/>

<Button
android:id="@+id/admin_logout_btn"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="15dp"
android:background="@color/colorPrimaryDark"
android:text="Logout"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textAllCaps="false"
/>

</RelativeLayout>
AdminHomeActivity.java
package com.teamstogether.twentyfourbysevenshopping.Admin;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import
androidx.appcompat.app.AppC
ompatActivity;

import com.teamstogether.twentyfourbysevenshopping.Buyers.HomeActivity;
import com.teamstogether.twentyfourbysevenshopping.Buyers.MainActivity;
import com.teamstogether.twentyfourbysevenshopping.R;

public class AdminHomeActivity extends AppCompatActivity {


private Button LogoutBtn, CheckOrdersBtn, maintainProductsBtn,
checkApproveProductsBtn;

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

LogoutBtn = (Button) findViewById(R.id.admin_logout_btn);


CheckOrdersBtn = (Button) findViewById(R.id.check_order_btn);
maintainProductsBtn = (Button) findViewById(R.id.maintain_btn);
checkApproveProductsBtn = (Button)
findViewById(R.id.check_approve_products_btn);

maintainProductsBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{
Intent intent = new Intent(AdminHomeActivity.this, HomeActivity.class);
intent.putExtra("Admin", "Admin");
startActivity(intent);

}
});

LogoutBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(AdminHomeActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
});

CheckOrdersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(AdminHomeActivity.this, AdminNewOrdersActivity.class);
startActivity(intent);
}
});

checkApproveProductsBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(AdminHomeActivity.this,
AdminCheckNewProductsActivity.class);
startActivi
ty(intent); finish();
}
}
);

}
}
activity_admin_check_new_products.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Admin.AdminCheckNewProductsActivity">

<RelativeLayout
android:id="@+id/r3"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true">

<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Approve New Products"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textAlignment="center"
android:layout_marginTop="10dp"
/>

</RelativeLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/admin_products_checklist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/r3"/>

</RelativeLayout>
AdminCheckNewProductActivity.java
package com.teamstogether.twentyfourbysevenshopping.Admin;

import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AlertDial
og;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
import
com.teamstogether.twentyfourbysevenshopping.Model.Pr
oducts;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.ViewHold
er.ProductViewHolder;

public class AdminCheckNewProductsActivity extends


AppCompatActivity {
private RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
private DatabaseReference uProductsRef;

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

Log.i("NewProductActivity","Activity Created");

uProductsRef = FirebaseDatabase.getInstance().getReference().child("Products");

Log.i("NewProductActivity","Firebase Started");
recyclerView.setLayoutManager(layoutManager);

Toast.makeText(this,"Layout created",Toast.LENGTH_SHORT).show();
}

@Override
protected void onStart() {
super.onStart();

FirebaseRecyclerOptions<Products> options =
new FirebaseRecyclerOptions.Builder<Products>()
.setQuery(uProductsRef.orderByChild("productState").equalTo("Not Approved"),
Products.class)
.build();

FirebaseRecyclerAdapter<Products, ProductViewHolder> adapter =


new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ProductViewHolder holder, int i,
@NonNull final Products products)
{
holder.txtproductName.setText(products.getPname());
holder.txtProductDescription.setText(products.getDescription());
holder.txtProductPrice.setText("Price = " +"₹"+ products.getPrice() );
Picasso.get().load(products.getImage()).into(holder.imageView);

holder.itemView.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{
final String productID = products.getPid();

CharSequence options[] = new CharSequence[]


{
"Yes",
"No"
};

AlertDialog.Builder
builder = new
AlertDialog.Builder(AdminCheckNe
wProductsActivity.this);
builder.setTitle("Do you want to Approved this Product. Are you Sure?");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position)
{
if (position == 0)
{
ChangeProductState(productID);
}
if (position == 1)
{

}
}
});
bu
ild
er.
sh
o
w(
);
}
});
}

@NonNull

@Override
public
ProductVie
wHolder
onCreateVi
ewHolder(
@NonNull
ViewGrou
p parent,
int
viewType)
{
View view =
LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items_layout,
parent, false);
ProductViewHolder holder = new
ProductViewHolder(view);
return holder;
}
};

recyclerView.setAd
apter(adapter);
adapter.startListening();
}

private void
ChangeProductState(String
productID)
{

uProductsRef.child
(productID)
.
activity_admin_maintain_products
Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
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="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="5dp"
app:cardElevation="15dp"
tools:context=".Admin.AdminMaintainProductsActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/product_image_maintain"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/product_name"
android:scaleType="centerCrop"
android:layout_marginTop="2dp"
/>

<EditText
android:id="@+id/product_name_maintain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_image_maintain"
android:hint="Product Price"
android:textAlignment="center"
android:textSize="18dp"
android:padding="12dp"
android:layout_margin="5dp"
android:textColor="@color/colorPrimaryDark"/>

<EditText
android:id="@+id/product_price_maintain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_name_maintain"
android:hint="Product Price"
android:textAlignment="center"
android:textSize="18dp"
android:padding="12dp"
android:layout_margin="5dp"
android:textColor="@color/colorPrimaryDark"/>

<EditText
android:id="@+id/product_description_maintain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_price_maintain"
android:hint="Product Description"
android:layout_marginTop="2dp"
android:textAlignment="center"
android:textSize="16dp"
android:padding="12dp"
android:layout_margin="5dp"
android:textColor="@color/colorPrimary"
/>

<Button
android:id="@+id/apply_changes_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_description_maintain"
android:text="Apply Changes"
android:layout_marginTop="2dp"
android:textAlignment="center"
android:textSize="18dp"
android:padding="12dp"
android:layout_margin="5dp"
android:background="@android:color/holo_purple"
android:textColor="@android:color/white"
/>

<Button
android:id="@+id/delete_product_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/apply_changes_btn"
android:text="Delete This Product"
android:textAlignment="center"
android:textSize="18dp"
android:padding="12dp"
android:layout_margin="30dp"
android:background="@android:color/holo_purple"
android:textColor="@android:color/white"
/>
</RelativeLayout>

</androidx.cardview.widget.CardView>
AdminMaintainProductActivity.java
package com.teamstogether.twentyfourbysevenshopping.Admin;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import
android.widget.ImageView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCo
mpatActivity;

import
com.google.android.gms.tasks.O
nCompleteListener;
import
com.google.android.gms.tasks.Ta
sk;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.Sellers.Sel
lerProductCategoryActivity;

import java.util.HashMap;

public class AdminMaintainProductsActivity extends


AppCompatActivity {

private Button applyChangesBtn, deleteBtn;


private EditText name, price, description;
private ImageView imageView;

private String productId = "";


private DatabaseReference productsRef;

@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_maintain_products);
price = findViewById(R.id.product_price_maintain);
description = findViewById(R.id.product_description_maintain);
imageView = findViewById(R.id.product_image_maintain);
deleteBtn = findViewById(R.id.delete_product_btn);

displaySpecificProductInfo();

applyChangesBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
applyChanges();
}
});

deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteThisProduct();
}
});
}

private void deleteThisProduct()


{
productsRef.removeValue().addOnCompleteListener(new OnCompleteListener<Void>()
{ @Override
public void onComplete(@NonNull Task<Void> task)
{
Intent intent = new Intent(AdminMaintainProductsActivity.this,
SellerProductCategoryActivity.class);
startActivi
ty(intent); finish();

Toast.makeText(AdminMaintainProductsActivity.this, "The Product Is deleted


successfully.", Toast.LENGTH_SHORT).show();
}
}
);
}

p
rivat
e
void
appl
yCha
nges(
){
String pName =
name.getText().toString(); String pPrice =
price.getText().toString();
else if(pPrice.equals(" ")){
Toast.makeText(this, "Write down Product Price", Toast.LENGTH_SHORT).show();
}
else if(pDescription.equals(" ")){
Toast.makeText(this, "Write down Product Description", Toast.LENGTH_SHORT).show();
}
else{
HashMap<String,Object> productMap = new HashMap<>();
productMap.put("pid",productId);
productMap.put("description",pDescription);
productMap.put("price",pPrice);
productMap.put("pname",pName);

productsRef.updateChildren(productMap).addOnCompleteL
istener(new
OnCompleteListener<Void>() {
@Override
public void
onComplete(@NonN
ull Task<Void> task)
{
if(task.isSuccessful()) {
Toast.makeText(AdminMaintainProductsActivity.this, "Changes applied
successfully.", Toast.LENGTH_SHORT)
.show();

Intent intent = new Intent(AdminMaintainProductsActivity.this,


SellerProductCategoryActivity.class);
start
Activity(intent);
finish();
}
}
}
);
}
}

p
rivate
void
display
Specifi
cProdu
ctInfo()
{
productsRef.addValueEventListener(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot snapshot)
{
if (snapshot.exists())
{
Picasso.get().load(pImage).into(imageView);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
}
activity_admin_new_orders.xml
activity_admin_new_orders.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Admin.AdminNewOrdersActivity">

<RelativeLayout
android:id="@+id/r2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true">

<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="New Orders"
android:textColor="@android:color/white"
android:textSize="25dp"
android:textAlignment="center"
android:layout_marginTop="10dp"
/>

</RelativeLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/orders_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/r2"
>
</androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>
AdminNewOrderActivity.java
package com.teamstogether.twentyfourbysevenshopping.Admin;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
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.appcompat.app.AlertDial
og;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import
com.teamstogether.twentyfourbysevenshopping.Model.Ad
minOrders;
import com.teamstogether.twentyfourbysevenshopping.R;

public class AdminNewOrdersActivity extends


AppCompatActivity
{
private RecyclerView orderList;
private DatabaseReference ordersRef;

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

ordersRef =
FirebaseDatabase.getInstance().getReference().child("O
rders");

orderList = findViewById(R.id.orders_list);
orderList.setLayoutManager(new
LinearLayoutManager(this));
}

@Override
.setQuery(ordersRef, AdminOrders.class)
.build();

FirebaseRecyclerAdapter<AdminOrders, AdminOrdersViewHolder> adapter =


new FirebaseRecyclerAdapter<AdminOrders, AdminOrdersViewHolder>(options)
{ @Override
protected void onBindViewHolder(@NonNull AdminOrdersViewHolder
adminOrdersViewHolder,
final int i, @NonNull final AdminOrders
adminOrders)
{
adminOrdersViewHolder.userName.setText("Name: " +
adminOrders.getName());
adminOrdersViewHolder.userPhoneNumber.setText("Phone: "+
adminOrders.getPhone());
adminOrdersViewHolder.userTotalPrice.setText("Total Amount: ₹" +
adminOrders.getTotalAmount());
adminOrdersViewHolder.userDateTime.setText("Orders at: " +
adminOrders.getDate() + " " + adminOrders.getTime());
adminOrdersViewHolder.userShippingAddress.set
Text("Shipping Address: " +
adminOrders.getAddress() + " " + adminOrders.getCity());

adminOrdersViewHolder.ShowOrdersBtn.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v)
{
String uID = getRef(i).getKey();

Intent intent = new Intent(AdminNewOrdersActivity.this,


AdminUserProductsActivity.class);
intent.pu
tExtra("uid", uID);
startActivity(intent);
}
}
);

adminOrdersViewHolder.itemView.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
CharSequence options[] = new CharSequence[]
{
"Yes",
"No"
};

AlertDialog.Builder builder = new


AlertDialog.Builder(AdminNewOrdersActivity.this);
builder.setTitle("Have you shipped this order products ?");

builder.setItems(options, new DialogInterface.OnClickListener() {


public void onClick(DialogInterface dialog, int which) {
if (which == 0)
{
String uID = getRef(i).getKey();

RemoverOrder(uID);
} else {
finish();
}
}
});
bu
ild
er.
sh
o
w(
);
}
});
}

@NonNull

@Override
public
AdminOrd
ersViewHo
lder
onCreateVi
ewHolder(
@NonNull
ViewGrou
p parent,
int
viewType)
{
View
view =
LayoutI
nflater.fr
om(pare
nt.getCo
ntext()).i
nflate(R.
layout.o
rders_la
yout,
parent , false);
return
new
AdminO
rdersVie
wHolder
private void RemoverOrder(String uID)
{
ordersRef.child(uID).removeValue();

}
}
activity_admin_user_products.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Admin.AdminUserProductsActivity">

<RelativeLayout
android:id="@+id/r3"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Products"
android:textColor="@android:color/white"
android:textSize="25dp"
android:textAlignment="center"
android:layout_marginTop="10dp"
/>

</RelativeLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/products_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/r3"
>
</androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>
AdminUserProductsActivity.java
package com.teamstogether.twentyfourbysevenshopping.Admin;

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

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import
com.teamstogether.twentyfourbysevenshopping.Model.Cart
;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.ViewHolde
r.CartViewHolder;

public class AdminUserProductsActivity extends


AppCompatActivity {

private RecyclerView productsList;


RecyclerView.LayoutManager layoutManager;
private DatabaseReference cartListRef;

private String userID = "";

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

userID = getIntent().getStringExtra("uid");

productsList = findViewById(R.id.products_list);
productsList.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
productsList.setLayoutManager(layoutManager);

cartListRef =
FirebaseDatabase.getInstance().getReference()
.child("Cart List").child("Admin
View").child(userID).child("Products");
protected void onStart() {
super.onStart();

FirebaseRecyclerOptions<Cart> options =
new FirebaseRecyclerOptions.Builder<Cart>()
.setQuery(cartListRef, Cart.class)
.build();

FirebaseRecyclerAdapter<Cart, CartViewHolder> adapter = new FirebaseRecyclerAdapter<Cart,


CartViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull CartViewHolder cartViewHolder, int i,
@NonNull Cart cart)
{
cartViewHolder.txtProductQuantity.setText("Quantity = "+
cart.getQuantity()); cartViewHolder.txtProductPrice.setText("Price "+"₹"+
cart.getPrice()); cartViewHolder.txtProductName.setText(cart.getPname());
}

@
NonNull
@Override
pu
blic
CartViewH
older
onCreateVi
ewHolder(
@NonNull
ViewGrou
p parent,
int
viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cart_items_layout,
parent, false);
CartViewHolder holder = new CartViewHolder(view);
return holder;
}
};

productsList.setAdapter
(adapter); adapter.startListening();
}
}
activity_cart.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Buyers.CartActivity">

<RelativeLayout
android:id="@+id/r111"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true">

<TextView
android:id="@+id/total_price"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Total Price = "
android:textColor="@android:color/white"
android:textSize="20dp"
android:textAlignment="center"
android:layout_marginTop="10dp"
/>

</RelativeLayout>

<TextView
android:id="@+id/msg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textAlignment="center"
android:layout_centerVertical="true"
android:text="Congratulations, your oder has been placed successfully. Soon it will be
verified."
android:textSize="20
dp"
android:visibility="gone"
/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cart_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/r111"
android:layout_above="@+id/next_btn"
>
</androidx.recyclerview.widget.RecyclerVi
ew>

<Button
android:id="@+id/codBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/next_btn"
android:background="@color/colorPrimary"
android:text="Cash on Delivery" />

<Button
android:id="@+id/next_btn"
android:layout_width="match_
parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimaryDark"
android:text="Next/RazorPay"
android:textColor="@android:color/white"
android:textSize="20dp"
/>

</RelativeLayout>
CartActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AlertDial
og;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.razorpay.Checkout;
import com.razorpay.PaymentResultListener;
import
com.teamstogether.twentyfourbysevenshopping.Model.Car
t;
import
com.teamstogether.twentyfourbysevenshopping.Prevalent.
Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.ViewHold
er.CartViewHolder;

import org.json.JSONException;
import org.json.JSONObject;

public class CartActivity extends AppCompatActivity


implements PaymentResultListener
{
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
Checkout.preload(getApplicationContext());

codBtn = (Button) findViewById(R.id.codBtn);

codBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CartActivity.this,ConfirmFinalOrderActivity.class);
startActivity(intent);
finish();

Toast.makeText(CartActivity.this,"You Select Cash on Delivery and "+


overTotalPrice , Toast.LENGTH_SHORT).show();
}
});

recyclerView = findViewById(R.id.cart_list);
recyclerView.setHasFixedSize(true);
layoutManager= new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);

NextProcessBtn= (Button) findViewById(R.id.next_btn);


txtTotalAmount = (TextView) findViewById(R.id.total_price);
txtMsg1 = (TextView) findViewById(R.id.msg1);

NextProcessBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{
txtTotalAmount.setText("Total Price = " +
String.valueOf(overTotalPrice));

Intent intent = new Intent(CartActivity.this, ConfirmFinalOrderActivity.class);


intent.putExtra("Total Price", String.valueOf(overTotalPrice));
startActivity(intent);
finish();

Checkout checkout = new Checkout();

checkout.setKeyID("rzp_test_VVG3ldpytJffar");

checkout.setImage(R.drawable.razorpay_logo);

JSONObject object = new JSONObject();


try {
object.put("name", "Twenty Four By Seven Shopping");
object.put("description","Total Payment for your Product");
object.put("currency","INR");
object.put("amount",overTotalPrice*100);
object.put("prefill.email","");
object.put("prefill.contact","");
checkout.open(CartActivity.this,object);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}

@Over
ride
protect
ed
void
onSt
art()
{
supe
r.
on
St
art
();

Chec
k
Or
de
rS
tat
e()
;

final DatabaseReference cartListRef = FirebaseDatabase.getInstance().getReference().child("Cart


List");

FirebaseRecyclerOptions<Cart> options =
new FirebaseRecyclerOptions.Builder<Cart>()
.setQuery(cartListRef.child("User View")
.child(Prevalent.currentOnlineUser.getPhone()).child("Products"), Cart.class)
.build();

FirebaseRecyclerAdapter<Cart, CartViewHolder> adapter


@Override
public void onClick(View v) {
CharSequence options[] = new CharSequence[]
{
"Edit",
"Remove"
};
AlertDialog.Builder builder = new AlertDialog.Builder(CartActivity.this);
builder.setTitle("Cart Options:");

builder.setItems(options, new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0)
{
Intent intent = new Intent(CartActivity.this, ProductDetailsActivity.class);
intent.putExtra("pid",cart.getPid());
startActivity(intent);
}
if (which == 1)
{
cartListRef.child("User View")
.child(Prevalent.currentOnlineUser.getPhone())
.child("Products")
.child(cart.getPid())
.removeValue()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
Toast.makeText(CartActivity.this, "Item removed successfully",
Toast.LENGTH_SHORT).show();

Intent intent = new Intent(CartActivity.this,


HomeActivity.class);
startActivity(intent);
}
}
});
}
}
});
builder.show();
}
});
}

@No
nNul
l
@Override
public CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{ View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cart_items_layout,
parent, false);
CartViewHolder holder = new CartViewHolder(view);
return holder;
}
};

recyclerView.setAdapter(adapter);
adapter.startListening();
}

private void CheckOrderState()


{
DatabaseReference ordersRef;
ordersRef =
FirebaseDatabase.getInstance().getRef
erence().child("Orders").child(Preva
lent.currentOnlineUser.get
Phone());
ordersRef.addValueEventListener(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot snapshot)
{
if (snapshot.exists())
{
String shippingState = snapshot.child("state").getValue().toString();
String userName = snapshot.child("name").getValue().toString();

if (shippingState.equals("shipped"))
{
txtTotalAmount.setText("Dear " + userName + "\n order is
shipped
successfully.");
recyclerView.setVisibility(View.GONE);

txtMsg1.setVisibility(View.VISIBLE);
txtMsg1.setText("Congratulations, your oder has been shipped successfully. Soon
you will received your order at your door step.");
NextProcessBtn.setVisibility(View.GONE);

Toast.makeText(CartActivity.this,
"you can purchase more products, once you received your first order.",
Toast.LENGTH_SHORT).show();
} else if (shippingState.equals("not shipped"))
{
txtTotalAmount.setText("Shipping
Sate = Not Shipped");
recyclerView.setVisibility(View.GONE);

txtMsg1.setVisibility(
View.VISIBLE);
Toast.makeText(CartActivity.this,
"you can purchase more products, once you received your first order.",
Toast.LENGTH_SHORT).show();
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
}
);
}

@
Overrid
e
p
ublic
void
onPay
mentSu
ccess(S
tring s)
{
AlertDialog.Builder builder = new
AlertDialog.Builder(this); builder.setTitle("Payment ID");
builder.setMessage(s);
}

@Override
public void onPaymentError(int i, String
s) {

Toast.makeText(getApplicationContext(
), s, Toast.LENGTH_SHORT).show();

}
}
activity_confirm_final_order.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Buyers.ConfirmFinalOrderActivity">

<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please confirm your shipment details"
android:textSize="18dp"
android:textColor="@color/colorPrimaryDark"
android:layout_margin="25dp"
android:textAlignment="center"
android:textStyle="bold"
/>

<EditText
android:id="@+id/shipment_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txt"
android:layout_marginTop="60dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Your Name"
/>

<EditText
android:id="@+id/shipment_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/shipment_name"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:inputType="number"
android:layout_marginRight="20dp"
android:hint="Your Phone Number"
/>

<EditText
android:id="@+id/shipment_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/shipment_phone_number"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" android:hint="Your
Home Address"
/>

<EditText
android:id="@+id/shipment_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/shipment_address"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Your City Name"
/>

<Button
android:id="@+id/confirm_final_order_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="20dp"
android:text="Confirm"
android:background="@android:color/holo_orange_dark"
android:textColor="@android:color/white"
android:textSize="20dp"
/>

</RelativeLayout>
ConfirmFinalOrderActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

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

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCo
mpatActivity;

import
com.google.android.gms.tasks.O
nCompleteListener;
import
com.google.android.gms.tasks.Ta
sk;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.razorpay.Checkout;
import
com.teamstogether.twentyfourbysevenshopping.Prevalent.
Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;

public class ConfirmFinalOrderActivity extends


AppCompatActivity
{
private EditText nameEditText, phoneEditText, addressEditText, cityEditText;
private Button confirmOrderBtn;

private String totalAmount = "";

@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_confirm_final_order);
Checkout.preload(getApplicationContext());

totalAmount = getIntent().getStringExtra("Total
Price");
Toast.makeText(this, "Total Price = ₹" + totalAmount,
confirmOrderBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Check();
}
});
}

private void Check() {


if
(TextUtils.isEmpty(nameEditTex
t.getText().toString())) {
Toast.makeText(this, "Please
provide your full name.",
Toast.LENGTH_SHORT).sho
w();
} else if (TextUtils.isEmpty(phoneEditText.getText().toString()))
{ Toast.makeText(this, "Please provide your phone number",
Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(addressEditText.getText().toString())){
Toast.makeText(this, "Please provide your address.",
Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(cityEditText.getText().toString())){
Toast.makeText(this, "Please provide your city name.",
Toast.LENGTH_SHORT).show();
}
else
{
ConfirmOrder();
}
}

private void ConfirmOrder()


{
final String saveCurrentDate, saveCurrentTime;
Calendar calForDate = Calendar.getInstance();
SimpleDateFormat currentDate = new SimpleDateFormat("MMM dd, yyyy");
saveCurrentDate = currentDate.format(calForDate.getTime());

SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm:ss a");


saveCurrentTime = currentTime.format(calForDate.getTime());

final DatabaseReference ordersRef =


FirebaseDatabase.getInstance().getReference()
.child("Orders")
.child(Prevalent.currentOnlineUser.getPhone());

HashMap<String, Object> orderMap = new HashMap<>();


orderMap.put("totalAmount", totalAmount);
orderMap.put("name", nameEditText.getText().toString());
orderMap.put("phone", phoneEditText.getText().toString());
orderMap.put("address", addressEditText.getText().toString());
orderMap.put("city", cityEditText.getText().toString());
ordersRef.updateChildren(orderMap).addOnCompleteListener(new OnCompleteListener<Void>()
{
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
FirebaseDatabase.getInstance().getReference().child("Cart List")
.child("User View")
.child(Prevalent.currentOnlineUser.getPhone())
.removeValue()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
Toast.makeText(ConfirmFinalOrderActivity.this,
"Your final order has been placed successfully",
Toast.LENGTH_SHORT).show();

Intent intent = new


Intent(ConfirmFinalOrderActivity.this,
HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
s
tartActivity(intent);
finish();
}
}
}
);
}
}
}
);

}
}
activity_product_details.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Buyers.ProductDetailsActivity">

<ImageView
android:id="@+id/product_image_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>

<TextView
android:id="@+id/product_name_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_image_details"
android:text="Product Name"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="18sp"
android:gravity="center"
android:layout_marginTop="10dp"
/>

<TextView
android:id="@+id/product_description_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_name_details"
android:text="Product Description"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="18sp"
android:gravity="center"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/product_price_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_description_details"
android:text="Product Price"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="15dp"
android:gravity="center"
android:layout_marginTop="10dp"
/>

<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
android:id="@+id/number_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="6dp"
app:textSize="16dp"
app:initialNumber="1"

app:finalNumber="10"
android:layout_centerHorizontal="true"
android:layout_below="@id/product_price_details"
android:layout_marginTop="10dp"
/>

<Button
android:id="@+id/pd_add_to_cart_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:layout_margin="15dp"
android:layout_alignParentBottom="true"
android:text="Add to cart"
android:textColor="@android:color/white"
android:textSize="18dp"
/>
</RelativeLayout>
ProductDetailActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppComp
atActivity;

import
com.cepheuen.elegantnumberbutton
.view.ElegantNumberButton;
import
com.google.android.gms.tasks.OnC
ompleteListener;
import
com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import com.teamstogether.twentyfourbysevenshopping.Model.Products;
import com.teamstogether.twentyfourbysevenshopping.Prevalent.Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;

public class ProductDetailsActivity extends AppCompatActivity


{
private Button addToCartButton;
private ImageView productImage;
private ElegantNumberButton
numberButton;
private TextView productPrice, productDescription, productName;
private String productId = "", state = "Normal";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
numberButton = (ElegantNumberButton) findViewById(R.id.number_btn);
productImage = (ImageView) findViewById(R.id.product_image_details);
productName = (TextView) findViewById(R.id.product_name_details);
productDescription = (TextView) findViewById(R.id.product_description_details);
productPrice = (TextView) findViewById(R.id.product_price_details);

getProductDetails(productId);

addToCartButton.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
addingToCartList();

if (state.equals("Order
Placed") ||
state.equals("Order
Shipped"))
{
Toast.makeText(ProductDetailsActivity.this, "you can add purchase more products, once
your order is shipped or confirmed.", Toast.LENGTH_LONG).show();
}
else {
addingToCartList();
}
}
}
);
}

@
Over
ride
p
rotec
ted
void
onSt
art()
{
s
up
er.
on
St
art
();

C
he
ck
Or
de
rS
cartMap.put("price", productPrice.getText().toString());
cartMap.put("date", saveCurrentDate);
cartMap.put("time", saveCurrentTime);
cartMap.put("quantity", numberButton.getNumber());
cartMap.put("discount", "");

cartListRef.child("User
View").child(Prevalent.currentOnlineUser.getPhone())
.child("Products").child(productId)
.updateChildren(cartMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
cartListRef.child("Admin
View").child(Prevalent.currentOnlineUser.getPhone())
.child("Products").child(productId)
.updateChildren(cartMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task)
{
if (task.isSuccessful())
{
Toast.makeText(ProductDetailsActivity.this, "Add to Cart List.",
Toast.LENGTH_SHORT).show();

Intent intent = new Intent(ProductDetailsActivity.this,


HomeActivity.class);
startActivity(intent);
}
}
});
}
}
});

private void
getProduc
tDetails(S
tring
productId
)
{
DatabaseReference productsRef =
FirebaseDatabase.getInstance().getReference().child("Products");

productsRef.child(productId).addValueEventListener(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
productName.setText(products.getPname());
productPrice.setText(products.getPrice());
productDescription.setText(products.getDescription());
Picasso.get().load(products.getImage()).into(productImage);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}

priv
ate
void
Chec
kOrd
erSta
te()
{
DatabaseReference ordersRef;
ordersRef =
FirebaseDatabase.getInstance().getReference().child("Orders").child(Prevalent.currentOnlineUser.get
Phone());
ordersRef.addValueEventListener(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot snapshot)
{
if (snapshot.exists())
{
String shippingState =
snapshot.child("state").getValue().toString();

if (shippingState.equals("shipped"))
{
state = "Order shipped";
} else if (shippingState.equals("not shipped"))
{
state = "Order Placed";
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
activity_reset_password.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Buyers.ResetPasswordActivity">

<RelativeLayout
android:id="@+id/relative123"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true">

<TextView
android:id="@+id/page_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Reset Password "
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textStyle="bold" />

</RelativeLayout>

<EditText
android:id="@+id/find_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:textColorHint="@android:color/white"
android:padding="14dp"
android:layout_margin="15dp"
android:layout_below="@id/relative123"
android:hint="Please write your phone number..."
/>

<TextView
android:id="@+id/title_questions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Answer the Following Secuirty Questions?"
android:gravity="center"
android:textSize="26dp"
android:layout_marginTop="35dp"
android:layout_below="@id/find_phone_number"
/>

<EditText
android:id="@+id/question_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:textColorHint="@android:color/white"
android:padding="14dp"
android:layout_margin="15dp"
android:layout_below="@id/title_questions"
android:hint="Where your parents met, first time?"
/>

<EditText
android:id="@+id/question_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:textColorHint="@android:color/white"
android:padding="14dp"
android:layout_margin="15dp"
android:layout_below="@id/question_1"
android:hint="Whats your favourite super hero?"
/>

<Button
android:id="@+id/verify_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:padding="14dp"
android:layout_margin="15dp"
android:layout_below="@id/question_2"
android:text="Verify"
android:textColor="@android:color/white"
android:textStyle="bold"
android:textSize="20dp"
/>
</RelativeLayout>
ResetPasswordActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AlertDial
og;
import
androidx.appcompat.app.AppCom
patActivity;

import
com.google.android.gms.tasks.On
CompleteListener;
import
com.google.android.gms.tasks.Tas
k;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import
com.teamstogether.twentyfourbysevenshopping.Prevalent.
Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;

import java.util.HashMap;

public class ResetPasswordActivity extends


AppCompatActivity {

private String check = "";


private TextView pageTitle, titleQuestions;
private EditText phoneNumber, question1, question2;
private Button verifyButton;

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

@Override
protected void onStart() {
super.onStart();

phoneNumber.setVisibility(View.GONE);

if (check.equals("settings"))
{
pageTitle .setText("Set Questions");
titleQuestions.setText("Please set Answers for the following security Questions?");
verifyButton.setText("Set");

displayPreviousAnswers();

verifyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
setAnswers();
}
});
}
else if
(che
ck.e
quals
("lo
gin"
))
{
pho
ne
N
u
m
be
r.s
et
Vi
si
bil
ity
(V
ie
w.
VI
SI
B
L
else {
DatabaseReference ref = FirebaseDatabase.getInstance()
.getReference()
.child("Users")
.child(Prevalent.currentOnlineUser.getPhone());

HashMap<String,Object> userdataMap = new HashMap<>();


userdataMap.put("answer1",answer1);
userdataMap.put("password",answer2);

ref.child("Security
Questions").updateChildren(userdataMap).addOnCompleteLi
stener(new
OnCompleteListener<Void>() {
@Override
public void
onComplete(@NonN
ull Task<Void> task)
{
if (task.isSuccessful())
{
Toast.makeText(ResetPasswordActivity.this, "you have set security questions
successfully.",
Toast.LENGTH_SHORT).show();

Intent intent = new Intent(ResetPasswordActivity.this,


HomeActivity.class); startActivity(intent);
}
}
}
);
}
}

p
rivate
void
display
Previou
sAnswe
rs()
{
D
ataba
seRe
feren
ce
ref =
Fireb
aseD
ataba
se.ge
tInst
@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}

priv
ate
void
verif
yUse
r()
{
fi
na
l
St
rin
g
ph
on
e
=
ph
on
eN
u
m
be
r.
ge
tT
ex
t()
.to
St
rin
g()
;
final String answer1 = question1.getText().toString().toLowerCase();
final String answer2 = question2.getText().toString().toLowerCase();

if (!phone.equals("") && !answer1.equals("") &&


answer2.equals(""))
{
final DatabaseReference ref = FirebaseDatabase.getInstance()
.getReference()
.child("Users")
.child(phone);

ref.addValueEventListener(new ValueEventListener()
AlertDialog.Builder(ResetPasswordActivity.this);
builder.setTitle("New Password");

final EditText newPassword = new EditText(ResetPasswordActivity.this);


newPassword.setHint("Write Password Here...");
builder.setView(newPassword);

builder.setPositiveButton("Change", new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which)
{
if (!newPassword.getText().toString().equals(""))
{
ref.child("password").setValue(newPassword.getText().toString())
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task)
{
if (task.isSuccessful())
{
Toast.makeText(ResetPasswordActivity.this, "Password
changed successfully.", Toast.LENGTH_SHORT).show();
}
}
}
);
}
}
}
);

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
});

build
er.
sh
o
w(
);
}
}
else
{
Toast.makeText(ResetPasswordActivity.this, "you have not set the security
questions.", Toast.LENGTH_SHORT).show();
}
}
Toast.LENGTH_SHORT).show();
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
else
{
To
ast
.m
ak
eT
ext
(t
hi
s,
"p
le
as
e
co
m
pl
et
e
th
e
fo
r
m.
",
To
ast
.L
E
N
G
T
H
_S
H
O
R
T)
.sh
o
w(
);
activity_search_product.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Buyers.SearchProductActivity">

<RelativeLayout
android:id="@+id/r5"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">

<com.rey.material.widget.EditText
android:id="@+id/search_product_name"
android:layout_width="290dp"
android:layout_height="wrap_content"
android:hint="Product Name"
android:textSize="18dp"
android:textStyle="bold"
android:background="@android:color/white"
android:padding="9dp"
android:layout_marginStart="5dp"
android:layout_centerVertical="true"
android:textColorHint="@color/colorPrimaryD
ark"
/>

<Button
android:id="@+id/search_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:textColor="@android:color/white"
android:textSize="16dp"
android:textStyle="bold"
android:padding="9dp"
android:layout_centerInParent="true"
android:background="@color/colorPrimaryDark"
android:layout_toRightOf="@+id/search_product_name"/>

</RelativeLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/r5">

</androidx.recyclerview.widget.Recycler
View>

</RelativeLayout>
SearchProductActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import
androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.rey.material.widget.EditText;
import com.squareup.picasso.Picasso;
import
com.teamstogether.twentyfourbysevenshopping.Model.Pro
ducts;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.ViewHolde
r.ProductViewHolder;

public class SearchProductActivity extends


AppCompatActivity
{
private Button SearchBtn;
private EditText inputText;
private RecyclerView searchList;
private String SearchInput;

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

inputText = findViewById(R.id.search_product_name);
SearchBtn = (Button) findViewById(R.id.search_btn);
searchList = findViewById(R.id.search_list);
searchList.setLayoutManager(new
LinearLayoutManager(SearchProductActivity.this));

SearchBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});

@Ov
errid
e
prot
ecte
d
void
onSt
art()
{
su
pe
r.
on
St
art
();

DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Products");

FirebaseRecyclerOptions<Products> options = new FirebaseRecyclerOptions.Builder<Products>()


.setQuery(reference.orderByChild("pname").startAt(SearchInput), Products.class)
.build();

FirebaseRecyclerAdapter<Products, ProductViewHolder> adapter =


new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ProductViewHolder holder, int i,
@NonNull final Products products)
{
holder.txtproductName.setText(products.getPname());
holder.txtProductDescription.setText(products.getDescription());
holder.txtProductPrice.setText("Price = " +"₹"+ products.getPrice() );
Picasso.get().load(products.getImage()).into(holder.imageView);

holder.itemView.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(SearchProductActivity.this,
ProductDetailsActivity.class);
intent.putExtra("pid
",products.getPid());
startActivity(intent);
}
}
);
}
};

searchList.setAdapter(adapter);
adapter.startListening();
}
}
activity_setting.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Buyers.SettingActivity">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_settings"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/close_settings_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
android:textColor="@android:color/white"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignParentStart="true"/>

<TextView
android:id="@+id/update_account_settings_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:textColor="@android:color/white"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="10dp"
android:layout_alignParentEnd="true"/>

</RelativeLayout>
</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/settings_profile_image"
android:layout_width="130dp"
android:layout_height="130dp"
android:src="@drawable/profile"
android:layout_below="@+id/app_bar_settings"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"/>

<TextView
android:id="@+id/profile_image_change_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Profile"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="10dp"
android:layout_marginTop="4dp"
android:textColor="@android:color/black"
android:layout_below="@+id/settings_profile_image"
android:layout_centerHorizontal="true"/>

<EditText
android:id="@+id/settings_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_image_change_btn"
android:hint="Phone Number..."
android:layout_margin="15dp"
android:padding="10dp"
/>

<EditText
android:id="@+id/settings_full_name"
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:layout_below="@+id/settings_phone_number"
android:hint="Full Name..."
android:layout_margin="15dp"
android:padding="10dp"
/>

<EditText
android:id="@+id/settings_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_full_name"
android:hint="Address"
android:layout_margin="15dp"
android:padding="10dp"
/>

<Button
android:id="@+id/security_questions_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_address"
android:text="Set Security Questions"
android:background="@color/colorPrimaryDark"
android:textColor="@android:color/white"
android:layout_margin="15dp"
android:padding="10dp"
/>

</RelativeLayout>
SettingActivity.java
package com.teamstogether.twentyfourbysevenshopping.Buyers;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.annotation.Nullable;
import
androidx.appcompat.app.AppCom
patActivity;

import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.StorageTask;
import com.squareup.picasso.Picasso;
import
com.teamstogether.twentyfourbysevenshopping.Prevalent.
Prevalent;
import com.teamstogether.twentyfourbysevenshopping.R;
import com.theartofdev.edmodo.cropper.CropImage;

import java.util.HashMap;

import de.hdodenhof.circleimageview.CircleImageView;

public class SettingActivity extends AppCompatActivity


{

private CircleImageView profileImageView;


private EditText fullNameEditText, userPhoneEditText, addressEditText;
private TextView profileChangeTextBtn, closeTextBtn, saveTextButton;
private Button securityQuestionBtn;

private Uri imageUri;


private String myUrl ="";
private StorageTask
uploadTask;
private StorageReference storageProfilePictureRef;
private String checker = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
profileImageView = (CircleImageView) findViewById(R.id.settings_profile_image);
fullNameEditText = (EditText) findViewById(R.id.settings_full_name);
userPhoneEditText = (EditText) findViewById(R.id.settings_phone_number);
addressEditText = (EditText) findViewById(R.id.settings_address);
profileChangeTextBtn = (TextView) findViewById(R.id.profile_image_change_btn);
closeTextBtn = (TextView) findViewById(R.id.close_settings_btn);
saveTextButton = (TextView) findViewById(R.id.update_account_settings_btn);
securityQuestionBtn = findViewById(R.id.security_questions_btn);

userInfoDisplay(profileImageView, fullNameEditText, userPhoneEditText, addressEditText);

closeTextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

securityQuestionBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(SettingActivity.this, ResetPasswordActivity.class);
intent.putExtra("check","settings");
startActivity(intent);
}
});

saveTextButton.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
if (checker.equals("clicked"))
{
userInfoSaved();
}
else
{
updateOnlyUserInfo();
}
}
});

profileChangeTextBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
checker = "clicked";

CropImage.activity(imageUri)
.setAspectRatio(1,1)
.start(SettingActivity.this);
}
});
}

priv
ate
void
upda
teOn
lyUs
erInf
o() {
userMap.put("name", fullNameEditText.getText().toString());
userMap.put("address", addressEditText.getText().toString());
userMap.put("phoneOrder", userPhoneEditText.getText().toString());
ref.child(Prevalent.currentOnlineUser.getPhone()).updateChildren(userMap);

startActivity(new Intent(SettingActivity.this, HomeActivity.class));


Toast.makeText(SettingActivity.this, "Profile Info update successfully",
Toast.LENGTH_SHORT).show();

finish();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode==CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode==RESULT_OK &&


data!=null)
{
CropImage.ActivityResult result= CropImage.getActivityResult(data);
imageUri= result.getUri();

profileImageView.setImageURI(imageUri);
}
else
{
Toast.makeText(this, "Error, Try Again", Toast.LENGTH_SHORT).show();

startActivity(new
Intent(SettingActivity.this,SettingActivity.class)); finish();
}
}

private void userInfoSaved()


{
if (TextUtils.isEmpty(fullNameEditText.getText().toString()))
{
Toast.makeText(this, "Name is mandatory",
Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(addressEditText.getText().toString()))
{
Toast.makeText(this, "Name is address",
Toast.LENGTH_SHORT).show();
}
else if
(TextUtils.isEmpty(userPhoneEditText.getText().toString()))
{
Toast.makeText(this, "Name is mandatory.",
Toast.LENGTH_SHORT).show();
}
else if (checker.equals("clicked"))
{
uploadImage();
}
}

private void uploadImage()


{
final ProgressDialog progressDialog = new
ProgressDialog(this); progressDialog.setTitle("Update Profile");
progressDialog.setMessage("Please wait, while we are
progressDialog.show();

if (imageUri != null)
{
final StorageReference fileRef = storageProfilePictureRef
.child(Prevalent.currentOnlineUser.getPhone() + ".jpg");

uploadTask = fileRef.putFile(imageUri);

uploadTask.continueWithTask(new Continuation() {
@Override
public Object then(@NonNull Task task) throws
Exception
{
if (!task.isSuccessful())
{
throw task.getException();
}
return fileRef.getDownloadUrl();
}
})
.addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful())
{
Uri downloadUri = task.getResult();
myUrl = downloadUri.toString();

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users");

HashMap<String, Object> userMap = new HashMap<>();


userMap.put("name", fullNameEditText.getText().toString());
userMap.put("address", addressEditText.getText().toString());
userMap.put("phoneOrder", userPhoneEditText.getText().toString());
userMap.put("image", myUrl);
ref.child(Prevalent.currentOnlineUser.getPhone()).updateChildren(userMap);

progressDialog.dismiss();

startActivity(new Intent(SettingActivity.this,HomeActivity.class));
Toast.makeText(SettingActivity.this,
"Profile Info update successfully",
Toast.LENGTH_SHORT).show();

finish();
}
else
{
progressDialog.dismiss();
Toast.makeText(SettingActivity.this, "Error.",
Toast.LENGTH_SHORT).show();
}
}
});
}
else {
Toast
.m
ak
eT
ext
(t
private void userInfoDisplay(final CircleImageView profileImageView, final EditText fullNameEditText,
final EditText userPhoneEditText, final EditText addressEditText)
{
DatabaseReference UsersRef =
FirebaseDatabase.getInstance().getReference().child("Users").child(Prevalent.currentOnlineUser.getPhone());

UsersRef.addValueEventListener(new ValueEventListener()
{ @Override
public void onDataChange(@NonNull DataSnapshot
snapshot) {
if (snapshot.exists())
{
if (snapshot.child("image").exists())
{
String image= snapshot.child("image").getValue().toString(); String
name = snapshot.child("name").getValue().toString(); String
phone = snapshot.child("phone").getValue().toString(); String
address = snapshot.child("address").getValue().toString();

Picasso.get().load(image).into(profileImageView);
fullNameEditText.setText(name);
userPhoneEditText.setText(phone);
addressEditText.setText(address);
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
}
activity_seller_registration.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Sellers.SellerRegistrationActivity">

<ImageView
android:id="@+id/img_seller"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:src="@drawable/seller"
android:scaleType="centerCrop"
/>

<TextView
android:id="@+id/title_seller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Seller Registration Form"
android:gravity="center"
android:layout_below="@+id/img_seller"
android:layout_marginTop="30dp"
android:textStyle="bold"
android:textSize="24dp"
android:textColor="@android:color/holo_gr
een_dark"
/>

<EditText
android:id="@+id/seller_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/title_seller"
android:hint="Name..."
android:inputType="text"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<EditText
android:id="@+id/seller_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/seller_name"
android:hint="Phone..."
android:inputType="number"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<EditText
android:id="@+id/seller_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/seller_phone"
android:hint="Email..."
android:inputType="textEmailAddress"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<EditText
android:id="@+id/seller_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/seller_email"
android:hint="Password..."
android:inputType="textPassword"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<EditText
android:id="@+id/seller_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/seller_password"
android:hint="Shop - Business Address..."
android:inputType="text"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<Button
android:id="@+id/seller_register_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_below="@+id/seller_address"
android:background="@android:color/white"
android:text="Register"
android:textAllCaps="false"
android:textSize="18dp"
/>

<Button
android:id="@+id/seller_already_have_account_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:background="@android:color/holo_green_dark"
android:text="Already have an Account?"
android:textAllCaps="false"
android:textSize="18dp"
android:layout_alignParentBottom="true"
android:textColor="@android:color/white"
android:layout_marginBottom="15dp"
/>

</RelativeLayout>
SellerRegistrationActivity.java
package com.teamstogether.twentyfourbysevenshopping.Sellers;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCo
mpatActivity;

import
com.google.android.gms.tasks.O
nCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.teamstogether.twentyfourbysevenshopping.R;

import java.util.HashMap;

public class SellerRegistrationActivity extends


AppCompatActivity {
private Button sellerLoginBegin;
private EditText nameInput, phoneInput, emailInput, passwordInput, addressInput;
private Button registerButton;

private FirebaseAuth mAuth;


private ProgressDialog loadingBar;

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

mAuth = FirebaseAuth.getInstance();
loadingBar = new ProgressDialog(this);

sellerLoginBegin =
findViewById(R.id.seller_already_have_account_btn)
;
registerButton = findViewById(R.id.seller_register_btn);
nameInput = findViewById(R.id.seller_name);
phoneInput = findViewById(R.id.seller_phone);
emailInput = findViewById(R.id.seller_email);
passwordInput = findViewById(R.id.seller_password);
addressInput = findViewById(R.id.seller_address);

sellerLoginBegin.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(SellerRegistrationActivity.this, SellerLoginActivity.class);
startActivity(intent);
}
public void onClick(View v) {
registerSeller();
}
});
}

private void registerSeller() {


final String name = nameInput.getText().toString(); final
String phone = phoneInput.getText().toString(); final
String email = emailInput.getText().toString(); String
password = passwordInput.getText().toString(); final
String address = addressInput.getText().toString();

if (!name.equals("") && !phone.equals("") && !


email.equals("") && !password.equals("") && !
address.equals(""))
{
loadingBar.setTitle("Creating Seller Account"); loadingBar.setMessage("Please
wait, while we are checking the credentials");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();

mAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if (task.isSuccessful())
{
final DatabaseReference rootRef;
rootRef = FirebaseDatabase.getInstance().getReference();

String sid = mAuth.getCurrentUser().getUid();

HashMap<String, Object> sellerMap = new HashMap<>();


sellerMap.put("sid", sid);
sellerMap.put("phone",phone);
sellerMap.put("email",email);
sellerMap.put("address",address);
sellerMap.put("name",name);

rootRef.child("Sellers").child(sid).up
dateChildren(sellerMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task)
{
loadingBar.dismiss();
Toast.makeText(SellerRegistrationActivity.this,
"You are Registered Successfully",
Toast.LENGTH_SHORT).show();

Intent intent = new Intent(SellerRegistrationActivity.this, SellerHomeActivity.class);


intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
});
}
}
});
}
else
{
T
o
a
s
t.
m
a
k
e
T
e
x
t
(
t
h
i
s
,
"
P
l
e
a
s
e
c
o
m
p
l
e
t
e
t
h
e
r
e
g
i
s
t
r
a
t
i
o
n
f
o
r
m
.
"
,
T
o
a
s
t.
L
activity_seller_login.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Sellers.SellerLoginActivity">

<ImageView
android:id="@+id/img_seller"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:src="@drawable/sellerlogin"
android:scaleType="centerCrop"
/>

<TextView
android:id="@+id/title_seller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Seller Login Form"
android:gravity="center"
android:layout_below="@+id/img_seller"
android:layout_marginTop="50dp"
android:textStyle="bold"
android:textSize="24dp"
android:textColor="@android:color/holo_gr
een_dark"
/>

<EditText
android:id="@+id/seller_login_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/title_seller"
android:hint="Email..."
android:inputType="textEmailAddress"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<EditText
android:id="@+id/seller_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@+id/seller_login_email"
android:hint="Password..."
android:inputType="textPassword"
android:textSize="16dp"
android:layout_marginTop="10dp"
/>

<Button
android:id="@+id/seller_login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/seller_login_password"
android:background="@android:color/holo_purple"
android:textColor="@android:color/holo_red_dark"
android:text="Login"
android:textAllCaps="false"
android:textSize="18dp"
/>

</RelativeLayout>
SellerLoginActivity.java
package com.teamstogether.twentyfourbysevenshopping.Sellers;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCo
mpatActivity;

import
com.google.android.gms.tasks.O
nCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import
com.teamstogether.twentyfourbysevenshopping.
R;

public class SellerLoginActivity extends


AppCompatActivity {
private Button loginSellerBtn;
private EditText emailInput, passwordInput;
private ProgressDialog loadingBar;
private FirebaseAuth mAuth;

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

mAuth = FirebaseAuth.getInstance();

emailInput = findViewById(R.id.seller_login_email);
passwordInput = findViewById(R.id.seller_login_password);
loginSellerBtn = findViewById(R.id.seller_login_btn);
loadingBar = new ProgressDialog(this);

loginSellerBtn.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
loginSeller();
}
});
}

private void loginSeller() {


final String email =
emailInput.getText().toString();
final String password =
passwordInput.getText().toStrin
g();

if (!email.equals("") && !password.equals("")) {


@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if (task.isSuccessful())
{
Intent intent = new Intent(SellerLoginActivity.this, SellerHomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
}
});
}
else {
Toast.m
akeText
(this,
"Pleas
e
comple
te the
Login
form.",
Toast.L
ENGT
H_SH
ORT).s
how();
}
}
}
activity_seller_home.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">

<RelativeLayout
android:id="@+id/re11"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
android:layout_alignParentTop="true">

</RelativeLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/seller_home_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/nav_view"
android:layout_below="@id/re11"
>
</androidx.recyclerview.widget.RecyclerView>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />

<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:text="My All Products"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="18dp"
android:textStyle="bold" />

<!-- <fragment-->
<!-- android:id="@+id/nav_host_fragment"-->
<!-- android:name="androidx.navigation.fragm
<!-- ent.NavHostFragment"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:defaultNavHost="true"-->
<!-- app:layout_constraintBottom_toTopOf="@id/nav_view"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
app:navGraph="@navigation/mobile_navigation" />-->
</RelativeLayout>
SellerHomeActivity.java
package com.teamstogether.twentyfourbysevenshopping.Sellers;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.appcompat.app.AlertDialog
;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import
com.google.android.material.bottomnavigation.BottomNavig
ationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
import com.teamstogether.twentyfourbysevenshopping.Buyers.MainActivity;
import com.teamstogether.twentyfourbysevenshopping.Model.Products;
import com.teamstogether.twentyfourbysevenshopping.R;
import
com.teamstogether.twentyfourbysevenshopping.ViewHolder.ItemViewHolder;

public class SellerHomeActivity extends AppCompatActivity {


private TextView mTextMessage;

private RecyclerView recyclerView;


RecyclerView.LayoutManager layoutManager;
private DatabaseReference unverifiedProductsRef;

private
BottomNavigationView.OnNavigationItemSelectedLi
stener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem
item) {
switch (item.getItemId())
{
case R.id.navigation_home:
Intent intentHome = new Intent(SellerHomeActivity.this,SellerHomeActivity.class);
startActivity(intentHome);
return true;
case R.id.navigation_add:
Intent intentCate = new Intent(SellerHomeActivity.this, SellerProductCategoryActivity.class);
startActivity(intentCate);
return true;
Intent intentMain = new Intent(SellerHomeActivity.this, MainActivity.class);
intentMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intentMain);
finish();
return true;
}
return false;
}
};

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

BottomNavigationView navView =
findViewById(R.id.nav_view);
mTextMessage = findViewById(R.id.message);
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

unverifiedProductsRef =
FirebaseDatabase.getInstance().getReference().child("Products");

recyclerView = findViewById(R.id.seller_home_recyclerview);
recyclerView.setHasFixedSize(true); layoutManager
= new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);

@Override
protected void onStart() {
super.onStart();

FirebaseRecyclerOptions<Products> options =
new
FirebaseRecyclerOptions.Builder<Products>()

.setQuery(unverifiedProductsRef.orderByChild("sid").equalTo(FirebaseAuth.getInstance().getCurrentUser().getUid()),
Products.class)
.build();

FirebaseRecyclerAdapter<Products, ItemViewHolder> adapter =


new FirebaseRecyclerAdapter<Products, ItemViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ItemViewHolder
holder, int i, @NonNull final Products
products)
{
holder.txtproductName.setText(products.getPname());
holder.txtProductDescription.setText(products.getDescription());
holder.txtProductStatus.setText("State :"+ products.getProductState());
holder.txtProductPrice.setText("Price = " +"₹"+ products.getPrice() );
Picasso.get().load(products.getImage()).into(holder.imageView);

holder.itemView.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{
final String productsID = products.getPid();
CharSequence options[] = new CharSequence[]
{
"Yes",
"No"
};

AlertDialog.Builder builder = new AlertDialog.Builder(SellerHomeActivity.this);


builder.setTitle("Do you want to Delete this Product. Are you Sure?");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position)
{
if (position == 0)
{
deleteProduct(productsID);
}
if (position == 1)
{

}
}
});
bu
ild
er.
sh
o
w(
);
}
});
}

@NonNull

@Override
public
ItemView
Holder
onCreateVi
ewHolder(
@NonNull
ViewGrou
p parent,
int
viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.seller_item_view, parent, false);
ItemViewHolder holder = new ItemViewHolder(view);
return holder;
}
};

recyclerView.setAdapter(adapter);
adapter.startListening();
}

private void deleteProduct(String


productsID)
{
unverifiedProductsRef.child(prod
uctsID)
.removeValue()
activity_seller_product_category.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Sellers.SellerProductCategoryActivity">

<TextView
android:id="@+id/slogan_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:text="Add new Product"
android:textSize="26sp"
android:textStyle="bold"
/>

<LinearLayout
android:id="@+id/linear_category_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/slogan_category"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_marginTop="100dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">

<ImageView
android:id="@+id/t_shirts"
android:layout_width="161dp"
android:layout_height="80dp"
android:src="@drawable/tshirt" />

<ImageView
android:id="@+id/shirt"
android:layout_width="115dp"
android:layout_height="80dp"
android:src="@drawable/shirt" />
<ImageView
android:id="@+id/sweater"
android:layout_width="161dp"
android:layout_height="80dp"
android:src="@drawable/sweater" />
</LinearLayout>

<LinearLayout
android:id="@+id/linear_category_layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linear_category_layout"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_marginTop="10dp">

<ImageView
android:id="@+id/pant"
android:layout_width="151dp"
android:layout_height="80dp"
android:src="@drawable/pant" />

<ImageView
android:id="@+id/watch"
android:layout_width="122dp"
android:layout_height="80dp"
android:src="@drawable/watch" />
<ImageView
android:id="@+id/washing_machine"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/washingmachine"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_category_layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linear_category_layout2"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_marginTop="10dp">

<ImageView
android:id="@+id/laptop"
android:layout_width="152dp"
android:layout_height="80dp"
android:src="@drawable/laptop" />

<ImageView
android:id="@+id/smartphone"
android:layout_width="112dp"
android:layout_height="80dp"
android:src="@drawable/smartphones" />
<ImageView
android:id="@+id/gaming_console"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/gaming_consol
e"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_category_layout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linear_category_layout3"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_marginTop="10dp">

<ImageView
android:id="@+id/shoes"
android:layout_width="152dp"
android:layout_height="80dp"
android:src="@drawable/shoes" />

<ImageView
android:id="@+id/led_tv"
android:layout_width="112dp"
android:layout_height="80dp"
android:src="@drawable/ledtv" />
<ImageView
android:id="@+id/jeans"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/jeans"
/>
</LinearLayout>

</RelativeLayout>
SellerProductCategoryActivity.java
package com.teamstogether.twentyfourbysevenshopping.Sellers;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import
android.widget.ImageView;

import
androidx.appcompat.app.App
CompatActivity;

import
com.teamstogether.twentyfour
bysevenshopping.R;

public class
SellerProductCategoryActivity
extends AppCompatActivity {
private ImageView tshirts,shirts,sweater;
private ImageView pant,watch,washingmachine;
private ImageView
laptop,smartphone,gamingconsole;
private ImageView shoes,ledtv,jeans;

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

tshirts = (ImageView) findViewById(R.id.t_shirts);


shirts = (ImageView) findViewById(R.id.shirt);
sweater = (ImageView) findViewById(R.id.sweater);
pant = (ImageView) findViewById(R.id.pant);
watch = (ImageView) findViewById(R.id.watch);
washingmachine = (ImageView)
findViewById(R.id.washing_machine);
laptop = (ImageView) findViewById(R.id.laptop);
smartphone = (ImageView) findViewById(R.id.smartphone);
gamingconsole = (ImageView) findViewById(R.id.gaming_console);
shoes = (ImageView) findViewById(R.id.shoes);
ledtv = (ImageView) findViewById(R.id.led_tv);
jeans = (ImageView) findViewById(R.id.jeans);

tshirts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","tshirts");
startActivity(intent);
}
});

shirts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","shirts");
startActivity(intent);
}
});
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","sweater");
startActivity(intent);
}
});

pant.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","pant");
startActivity(intent);
}
});

watch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","watch");
startActivity(intent);
}
});

washingmachine.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","Washing Machine");
startActivity(intent);
}
});

laptop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","laptop");
startActivity(intent);
}
});

smartphone.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","smartphone");
startActivity(intent);
}
});

gamingconsole.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","Gaming Console");
startActivity(intent);
}
});
shoes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","shoes");
startActivity(intent);
}
});

ledtv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","Led TV");
startActivity(intent);
}
});

jeans.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SellerProductCategoryActivity.this, SellerAddNewProductActivity.class);
intent.putExtra("category","jeans");
startActivity(intent);
}
});

}
}
activity_seller_add_new_product.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<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="@color/colorPrimaryDark"
tools:context=".Sellers.SellerAddNewProductActivity">

<ImageView
android:id="@+id/select_product_image"
android:layout_width="350dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:cropToPadding="false"
android:scaleType="centerCrop"
android:src="@drawable/select_product_image" />

<EditText
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/select_product_image"
android:layout_marginLeft="45dp"
android:layout_marginTop="20dp"
android:layout_marginRight="45dp"
android:background="@android:color/transparent"
android:textColor="@android:color/black"
android:textStyle="bold"
android:hint="Product Name..."
android:inputType="textMultiLine"
android:padding="20dp" />

<EditText
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/product_name"
android:layout_marginLeft="45dp"
android:layout_marginTop="6dp"
android:layout_marginRight="45dp"
android:background="@android:color/transparent"
android:textColor="@android:color/black"
android:textStyle="bold"
android:hint="Product Description..."
android:inputType="textMultiLine"
android:padding="20dp" />

<EditText
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/product_description"
android:layout_marginLeft="45dp"
android:layout_marginTop="6dp"
android:layout_marginRight="45dp"
android:background="@android:color/transparent"
android:textColor="@android:color/black"
android:textStyle="bold"
android:hint="Product Price..."
android:inputType="textMultiLine"
android:padding="20dp" />

<Button
android:id="@+id/add_new_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/product_price"
android:layout_marginLeft="45dp"
android:layout_marginTop="20dp"
android:layout_marginRight="45dp"
android:padding="17dp"
android:text="Add Product"
android:textStyle="bold"
android:background="@android:color/transparent"
android:textColor="@android:color/black"
/>

</RelativeLayout>
SellerAddNewProductActivity.java
package com.teamstogether.twentyfourbysevenshopping.Sellers;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import
android.widget.ImageView;
import android.widget.Toast;

import
androidx.annotation.NonNull;
import
androidx.annotation.Nullable;
import
androidx.appcompat.app.AppCo
mpatActivity;

import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.teamstogether.twentyfourbysevenshopping.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;

public class SellerAddNewProductActivity extends


AppCompatActivity {

private String CategoryName, Description, Price, Pname, saveCurrentDate,saveCurrentTime;


private Button AddNewProductButton;
private ImageView InputProductImage;
private EditText InputProductName,InputProductDescription,InputProductPrice;
private static final int GalleryPick=1;
private Uri ImageUri;
private String productRandomKey, downloadImageUrl;
private StorageReference ProductImageRef;
private DatabaseReference ProductRef, sellersRef;
private ProgressDialog loadingBar;

private String sName, sAddress, sPhone, sEmail, sID;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seller_add_new_product);
CategoryName = getIntent().getExtras().get("category").toString();
ProductImageRef = FirebaseStorage.getInstance().getReference().child("Product Images");
ProductRef = FirebaseDatabase.getInstance().getReference().child("Products");
sellersRef = FirebaseDatabase.getInstance().getReference().child("Sellers");

AddNewProductButton = (Button) findViewById(R.id.add_new_product);


InputProductImage = (ImageView) findViewById(R.id.select_product_image);
InputProductName = (EditText) findViewById(R.id.product_name);
InputProductDescription = (EditText) findViewById(R.id.product_description);
InputProductPrice = (EditText) findViewById(R.id.product_price);
loadingBar = new ProgressDialog(this);

InputProductImage.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View view) {
OpenGallery();
}
});

AddNewProductButton.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View view) {
ValidateProductData();
}
});

sellersRef.child(FirebaseAuth.getInstan
ce().getCurrentUser().getUid())
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot
snapshot)
{
if (snapshot.exists())
{
sName = snapshot.child("name").getValue().toString();
sAddress = snapshot.child("address").getValue().toString();
sPhone = snapshot.child("phone").getValue().toString();
sID = snapshot.child("sid").getValue().toString();
sEmail = snapshot.child("email").getValue().toString();
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}

private
void
OpenGall
ery() {
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent,GalleryPick);
}

@Override
protected void onActivityResult(int requestCode, int
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GalleryPick && resultCode == RESULT_OK && data != null) {
ImageUri = data.getData();
InputProductImage.setImageURI(ImageUri);
}
}

private void ValidateProductData() {


Description = InputProductDescription.getText().toString();
Price = InputProductPrice.getText().toString();
Pname = InputProductName.getText().toString();

if(ImageUri == null)
{
Toast.makeText(this, "Product image is mandatory...",
Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Description))
{
Toast.makeText(this, "Please write the product
description...", Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(Price))
{
Toast.makeText(this, "Please write product price...",
Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(Pname))
{
Toast.makeText( this, "Please write the product
name...",Toast.LENGTH_SHORT).show();
}
else {
StoreProductInformation();
}
}

private void StoreProductInformation()


{
loadingBar.setTitle("Add New Product");
loadingBar.setMessage("Dear Seller, please wait while we are adding the new product...");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
Calendar calendar= Calendar.getInstance();

SimpleDateFormat currentDate = new SimpleDateFormat("MM dd,yyyy");


saveCurrentDate = currentDate.format(calendar.getTime());

SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm:ss a");


saveCurrentTime = currentTime.format(calendar.getTime());

productRandomKey = saveCurrentDate+saveCurrentTime;

final StorageReference filePath =


ProductImageRef.child(ImageUri.getLastPathSegment() +
productRandomKey + ".jpg");

final UploadTask uploadTask = filePath.putFile(ImageUri);

uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
String message = e.toString();
Toast.makeText(SellerAddNewProductActivity.this, "Error:" + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
{ @Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
{ Toast.makeText(SellerAddNewProductActivity.this, "Product Image uploaded
Successfully...",
Toast.LENGTH_SHORT).show();
Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot,
Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws
Exception {
if(!task.isSuccessful())
{
throw task.getException();
}

downloadImageUrl = filePath.getDownloadUrl().toString();
return filePath.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()){
downloadImageUrl = task.getResult().toString();
Intent intent = new Intent(SellerAddNewProductActivity.this, SellerProductCategoryActivity.class);
startActivity(intent);
loadingBar.dismiss();
Toast.makeText(SellerAddNewProductActivity.this, "got the Product image URL Successfully",
Toast.LENGTH_SHORT).show();

saveProductInfoToDatabase();
}
else
{
loadingBar.dismiss();
String message = task.getException().toString();
Toast.makeText(SellerAddNewProductActivity.this, "Error: " + message,
Toast.LENGTH_SHORT).show();
}

});
}
}
);
}

private void saveProductInfoToDatabase()


{ HashMap<String,Object> productMap = new
HashMap<>();
productMap.put("pid",productRandomKey);
productMap.put("date", saveCurrentDate);
productMap.put("time",saveCurrentTime);
productMap.put("description",Description);
productMap.put("pid",productRandomKey);
productMap.put("image",downloadImageUrl);
productMap.put("category",CategoryName);
productMap.put("price", Price);
productMap.put("pname", Pname);

productMap.put("sellerName", sName);
productMap.put("sellerAddress", sAddress);
productMap.put("sellerPhone", sPhone);
productMap.put("sellerEmail", sEmail);
productMap.put("sid", sID);
productMap.put("productState", "Not Approved");

ProductRef.child(productRandomKey).updateChild
ren(productMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task)
{
if (task.isSuccessful())
{
Intent intent = new Intent(SellerAddNewProductActivity.this, SellerHomeActivity.class);
startActivity(intent);

loadingBar.dismiss();
Toast.makeText(SellerAddNewProductActivity.this, "Product is added successfully..",
Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.dismiss();
String message = task.getException().toString();
Toast.makeText(SellerAddNewProductActivity.this, "Error: " + message,
Toast.LENGTH_SHORT).show();
}
}
}
);
}
}
4. Advantages
 Customer can buy anytime, anywhere at any place while going online.
 Less time consuming.
 Have options different options for payment.
 24*7 hours services.

5. Limitations
 Lack of interaction.
 It is not possible to bargain.
 Delivery time is too long.
 Does not guarantee the products.
 We cannot touch and check the material.

6. Conclusion
As a result, we provide best services to our customer and provide a better customer service response. The
customer here gets more facilities like if they did not like the product after delivery they can return and
even money is refunded. Company promises to give the warrantee along with the bill and can return the
order and replace the if it is damage or factory damage. With many brans their might me a chance of
fraud but we guarantee to check the products as many times that is original or copy and responsible for
providing original items by the company and takes action on the employee who are malpractice and
make some mistakes while packing the products.
Th a
nk
You

You might also like