You are on page 1of 83

SYNOPSIS

This project is a web based shopping system for an existing shop. The project
objective is to deliver the online shopping application into android platform. This
project is an attempt to provide the advantages of online shopping to customers of a
real shop. It helps buying the products in the shop anywhere through internet by using
an android device. Thus the customer will get the service of online shopping and home
delivery from his favorite shop. This system can be implemented to any shop in the
locality or to multinational branded shops having retail outlet chains. If shops are
providing an online portal where their customers can enjoy easy shopping from
anywhere, the shops won’t be losing any more customers to the trending online shops
such as flipcart or ebay. Since the application is available in the Smartphone it is easily
accessible and always available.

1
1. INTRODUCTION

E-commerce represents the direction of future trade development. Promotion of


ecommerce will bring great benefits to the society and the economy. For example,
ecommerce improves the speed and quality of services of transaction, promotes the
globalization of markets, and cuts down cost. For these reasons, this project aimed to
design and implement an online shopping website for selling Asian food and groceries
in the Helsinki area. The website is designed for people who prefer online shopping of
daily necessities, especially Asian food. This website covers the entire process from
product management, classification and querying, to the shopping cart, and user order
processing. According to a simple market research, there are large domestic
supermarket chains located around every city in Finland and every corner in Helsinki.
However, the selection of commodities in these different supermarkets is almost same,
and there are only few Asian food items on the shelf.

In addition, only three large scale Asian supermarkets are located in Helsinki
and they are in the same place in the city centre. According to information received
from friends, a lot of Finnish people like Asian diet. Thus, the goal of this project is to
provide a platform for more and more Finnish people to become familiar with Asian
food and purchase it online, and to develop an independent online shopping system
based on Android Studio. In the future, this project could be used for the establishment
of a personal online shopping portal, or it could be sold to a company interested in
Asian product trading. The system includes both a front-end portal for customers and a
back-end management system used by administrators to manage the website in the
background. Android Studio is used as the framework for the project to facilitate
software development, maintenance and upgrading.

2
2. SYSTEM CONFIGURATION

2.1 Hardware Specification

Processor : Intel(R) Core 2Duo

Clock speed : 2.93 GHz

Hard Disk : 500 GB

RAM : 2 GB Ram

Cache Memory : 2 MB

Monitor : Color Monitor

Keyboard : 104 Keys

2.2 Software Specification

Operating System : Windows 7/10

Language : JAVA

Tool : Android Studio

2.3 SOFTWARE DESCRIPTION


3
Android

Android was founded by a company, named android Inc. in Palo Alto of


California, U.S in 2003 whose founder was Andy Rubin. Early intension of the
company was to develop an advanced Os for digital cameras, but then it was realized
that market for such devices was not large enough so that diverted their attention to
producing a smart phone OS. Android was then acquired by the Google in 2005 and
unveiled its distribution in 2007 with formation of Open Handset Alliance led by
Google. Android mobile operating system is based on the Linux kernel and is
developed by Google. Android OS has its own virtual machine called DVM which is
used for executing the android application. One of the reasons for the success of
Google’s OS is the constant improvement of its many versions, with every new one
offering more advanced features, faster access to the internet.

Open Handset Alliance

The Open Handset Alliance (OHA) is a consortium whose goal is to develop


open standards for mobile devices, promote innovation in mobile phones and provide a
better experience for consumers at a lower cost.

Android Architecture

Software stack is split into four layers. That are

1. Application layer

2. Application Framework

3. Libraries

4. Linux kernel

4
Fig 2.1 Android Architecture

Linux Kernel

Lower layer of android operating system is Linux kernel. It does not really
interact with the users and developers. The Linux Kernel provides a level of abstraction
between the device hardware and the upper layers of the Android software stack. Based
on Linux version 2.6, the kernel provides pre-emptive multitasking, lowlevel core
system services such as memory, process and power management in addition to
providing a network stack and device drivers for hardware such as the device display,
Wi-Fi and audio. Also, the kernel handles all the things that Linux is really good at
such as networking and a vast array of device drivers, which take the pain out of
interfacing to peripheral hardware.

Libraries

On top of Linux kernel there is a set of c/c++ libraries used by the various
components of the android system. Some of the core libraries are listed below:

5
 System c library – a BSD– derived implementation of the standard and system
library (libc) tuned for embedded Linux-based devices.

 SQLite - It is used to access data published by content providers and includes


SQLite database management classes.

 SSL - It is used to provide internet security.

 SGL – the underlying 2D graphics engine.

 Libwebcore – a modern web browser engine which powers both the android
browser and an embedded web view.

 OpenGL - It is used to provide Java interface to the OpenGL/ES 3D graphics


rendering API.

Android Runtime:

Dalvik Virtual Machine:

Dalvik is a purpose built virtual machine designed specifically for android


which was developed by Dan Bornstein and his team. It was mainly developed for
mobile devices. Dalvik Virtual Machine is same as JVM but only difference is that it is
designed and optimized for Android. Every android application runs in its own process
is called Dalvik virtual machine. Dalvik uses its own 16 bit instruction set than java 8
bit stack instructions, which reduce the Dalvik instruction count and raised its
interpreter speed. The Dalvik VM executes files in the Dalvik Executable (.dex) format
which is optimized for minimal memory footprint. The VM is register based, and runs
its classes compiled by a java language compiler that have been transformed into the
.dex format by the included “dx” tool. The Dalvik VM dependent on the Linux kernel
for underlying functionality such as threading and low level memory management.

6
Fig 2.2 Dalvik Virtual Machine

Application Framework

It provides many higher level services to applications in the form of Java


classes. Application developers are allowed to make use of these services in their
application. This framework describes the concept that Android applications are
constructed from reusable, interchangeable and replaceable components. The Android
framework includes the following key services:

 Activity Manager – Controls all aspects of the application lifecycle and activity
stack.

 Content Providers – Allows applications to publish and share data with other
applications.

7
 Resource Manager – Provides access to non-code embedded resources such as
strings, color settings and user interface layouts.

 Notifications Manager – Allows applications to display alerts and notifications


to the user.

 View System – An extensible set of views used to create application user


interfaces.

 Package Manager – The system by which applications are able to find out
information about other applications currently installed on the device.

 Telephony Manager – Provides the telephony services available on the device


such as status and subscriber information.

 Location Manager – Provides access to the location services allowing an


application to receive updates about location changes.

Android Security

Nowadays near all of the tasks that you could only perform on a computer are
also performed on mobile devices as well. This means that more sensitive information
is stored on people mobile devices than before. The need for security is greater than
ever for not only consumers, but large enterprise as well. Android software stack itself
provides security to its application. Key features includes physical access, app
permission, the application sandbox, rooting. Physical access Android has a couple of
features that can help to prevent hackers. The first is the unlock screen when the device
is woken from sleep. The standard unlock screen is just the slider which basically stops
the screen from being activated in your pocket. But Android also allows you to set an
unlock pattern, PIN or password. Unless the intruder knows the pattern, PIN or
password they can’t get access to your device.

8
App permissions

Every app that you install on your device needs to specifically ask you for
permission to perform certain tasks. This is done when you install the app. What this
means in practical terms is that apps have limited abilities. As well as limiting the
abilities of apps, Android also controls how an app accesses the device’s hardware.
There is no direct hardware access allowed in Android; all access is through the
different software layers which make up the Android OS. This means that rogue apps
can’t go around re-programming the microphone on your phone or bypassing the app
permissions by talking directly to the video camera, etc.

The Application Sandbox

Android has another layer of protection in that it doesn’t give one app access to
the resource of another app. This is known as the ‘sandbox’ where every app gets to
play in its own sandbox and can’t use another app’s toys! Android does this by giving
each app a unique user id (a UID) and by running that app as a separate process with
that UID. Only processes with the same UIDs can share resources which, as each ID is
uniquely assigned, means that no other apps have permission. Google’s own words on
this, “like all security features, the Application Sandbox is not unbreakable. However,
to break out of the Application Sandbox in a properly configured device, one must
compromise the security of the Linux kernel.”

Rooting

In the world of Linux ‘root’ is the supreme user level which has the rights to
perform any task. It is similar to the Administrator user on a Windows PC. By default,
only the Linux kernel and a small number of core utilities run as this super user. But by
‘rooting’ your device (which means the root user level is available to all apps) then
many of the security mechanisms described above are made null and void. This is

9
because an app with root permission can modify any other part of the Android OS
including the operating system itself, the kernel, and other apps.

Malware

It is an unfortunate reality, but reality none the less, that Android has a malware
problem. First, for an app to be malicious it doesn’t need to have access to the deeper
levels of the OS. If an unsuspecting user installs a malicious app which sends premium
rate SMS message sand the user granted those privileges to the app when it’s installed,
then the malware has successfully been installed without breaking any of the security.
Secondly, some malware actually comes with root exploits built-in. This means that
when the app is installed it actually roots the device (without the user knowing) and by-
passes all the system security. Thirdly, there is malware that just loves rooted phones. If
the malware gets installed on a non-rooted phone it does nothing, but when installed on
a rooted phone it unleashes all of its nastiness.

3. SYSTEM ANALYSIS
10
3.1 Existing System

Many customers go for purchasing offline so as to examine the product and hold
the possession of the product just after the payment for the product. In this
contemporary world customer loyalty depends upon the consistent ability to deliver
quality, value and satisfaction. Offline shopping has a sense of immediacy. You get to
posses the item you've purchased the very moment. If we can search and make a list of
items that we would like to try while shopping, before actually going out. This way we
can be more confident in our purchase and not missing out something. This can also
help us to decide what areas to visit. And plan such an event with friends.

Disadvantages

 Time Consuming

 Shipping Rates

 Refunds/Returns Disputes

 Lack of options

 Cash-Back offers not present

 Bad customer service

3.2 Proposed System

To remove all the disadvantages of conventional methods, a system is proposed


which is an online shopping. The purpose of online shopping is to save time, save
money. Through online shopping one can save his valuable time. One can watch and
select things he wants to buy. Through online shopping we can save our money
because prices are less than market prices and we receive our bought things at our

11
home. No need to go anywhere and do shopping. We can get different varieties of
things online and we can choose which one we want.

Through Online Shopping, a person who wants to buy is a lifestyle e-commerce


web application, which retails various fashion and lifestyle products. This project
allows viewing various products available enables registered users to purchase desired
products instantly using PayPal payment processor (Instant Pay) and also can place
order by using Cash on Delivery (Pay Later) option. This project provides an easy
access to Administrators and Managers to view orders placed using Pay Later and
Instant Pay options. In order to develop an e-commerce website, a numbers of
Technologies must be studied and understood

Advantages

 Lower prices

 More saving options

 Saves Time

 Provide discount and offer

4. PROJECT DEFINTION AND DESCRIPTION


12
This project is an Application Based shopping system for an existing shop. The
project objective is to deliver the online shopping application into android platform.
Online shopping is the process whereby consumers directly buy goods or services from
a seller in real-time, without an intermediary service, over the Internet. It is a form of
electronic commerce. This project is an attempt to provide the advantages of online
shopping to customers of a real shop .It helps buying the products in the shop
anywhere through internet by using an android device. Thus the customer will get the
service of online shopping and home delivery from his favorite shop.

The central concept of the application is to allow the customer to shop virtually
using the Internet and allow customers to buy the items and articles of their desire from
the store. The information pertaining to the products are stores on an RDBMS at the
server side (store).The Server process the customers and the items are shipped to the
address submitted by them. The application was designed into two modules first is for
the customers who wish to buy the articles. Second is for the storekeepers who
maintains and updates the information pertaining to the articles and those of the
customers. The end user of this product is a departmental store where the application is
hosted on the web and the administrator maintains the database. The application which
is deployed at the customer database, the details of the items are brought forward from
the database for the customer view based on the selection through the menu and the
database of all the products are updated at the end of each transaction. Data entry into
the application can be done through various screens designed for various levels of
users. Once the authorized personnel feed the relevant data into
Loginthe
DBsystem, several
reports could be generated as per the security.

5. SYSTEM DESIGN Check


User Enter User Name
5.1 Data Flow Diagram & password Validity

13 If Yes

Main Page
Login

Add/
Remove
Manage
moderator User
Detail DB
Block/
Search

Add/
REGISTRATION DFD Remove
Manage
User
Registration
Block/DB
View

Add/
Admin Manage Delete
Enter User Name
Product Check
User Product
& password Validity
Detail DB

Search Successful

Main Page

ADMIN DFD
View

Manage
Order
14
Product
Delete Order DB
6. SYSTEM IMPLEMENTATION AND TESTING

6.1 SYSTEM IMPLEMENTATION

15
The system after careful analysis has been identified to be presented with the
following modules and roles.

The modules involved are:

 Administrator

 Users

ADMINISTRATOR

The administrator is the super user of this application. Only admin have access
into this admin page. Admin may be the owner of the shop. The administrator has all
the information about all the users and about all products.

This module is divided into different sub-modules.

1. Manage Moderators

2. Manage Products

3. Manage Users

4. Manage Orders

MANAGE MODERATORS

Add Moderator

Only admin is having the privilege to add a moderator. A moderator can be


considered as staffs who manage the orders or owner of a group of products.

Block moderator

Admin can restrict a moderator from managing the orders by blocking them.
Admin can unblock a blocked user if needed.

16
Remove Moderator

Admin has privilege to delete a moderator who was added.

Search moderator

All existing moderators can be viewed by the administrator as a list. If there is


number of moderators and admin need to find one of them, the admin can search for a
moderator by name.

MANAGE PRODUCTS

Add Products

The shopping cart project contains different kind of products. The products can
be classified into different categories by name. Admin can add new products into the
existing system with all its details including an image.

Delete Products

Administrator can delete the products based on the stock of that particular
product.

Search products

Admin will have a list view of all the existing products. He can also search for a
particular product by name.

MANAGE USERS

View Users

The admin will have a list view of all the users registered in the system. Admin
can view all the details of each user in the list except password.
17
Add Users

Admin has privileges to add a user directly by providing the details.

Delete &Block Users

Administrator has a right to delete or block a user. The default status of a new
user registered is set as blocked. The admin must accept the new user by unblocking
him.

MANAGE ORDERS

View Order

Administrator can view the Orders which is generated by the users. He can
verify the details of the purchase.

Delete order

Admin can delete order from the orders list when the product is taken for
delivery.

Users

Registration

A new user will have to register in the system by providing essential details in
order to view the products in the system. The admin must accept a new user by
unblocking him.

18
Login

A user must login with his user name and password to the system after
registration.

View Products

User can view the list of products based on their names after successful login. A
detailed description of a particular product with product name, products details,
product image, price can be viewed by users.

Search Product

Users can search for a particular product in the list by name.

Add to cart:

The user can add the desired product into his cart by clicking add to cart option
on the product. He can view his cart by clicking on the cart button. All products added
by cart can be viewed in the cart. User can remove an item from the cart by clicking
remove.

Submit Cart

After confirming the items in the cart the user can submit the cart by providing a
delivery address. On successful submitting the cart will become empty.

History

In the history the user will have a view of pending orders.

Edit Profile

The user can view and edit the profile.


19
6.2 TESTING

The purpose of testing is to discover errors. Testing is the process of trying to


discover every conceivable fault or weakness in a work product. It provides a way to
check the functionality of components, sub assemblies, assemblies and/or a finished
product It is the process of exercising software with the intent of ensuring that the
Software system meets its requirements and user expectations and does not fail in an
unacceptable manner. There are various types of test. Each test type addresses a
specific testing requirement.

TYPES OF TESTS

Unit testing

Unit testing involves the design of test cases that validate that the internal
program logic is functioning properly, and that program inputs produce valid outputs.
All decision branches and internal code flow should be validated. It is the testing of
individual software units of the application .it is done after the completion of an
individual unit before integration. This is a structural testing, that relies on knowledge
of its construction and is invasive. Unit tests perform basic tests at component level and
test a specific business process, application, and/or system configuration. Unit tests
ensure that each unique path of a business process performs accurately to the
documented specifications and contains clearly defined inputs and expected results.

In computer programming, unit testing is a software testing method by which


individual units of source code, sets of one or more computer program modules
together with associated control data, usage procedures, and operating procedures, are
tested to determine whether they are fit for use. Intuitively, one can view a unit as the
smallest testable part of an application. In procedural programming, a unit could be an
entire module, but it is more commonly an individual function or procedure. In object-
oriented programming, a unit is often an entire interface, such as a class, but could be
20
an individual method. Unit tests are short code fragments created by programmers or
occasionally by white box testers during the development process. It forms the basis
for component testing.

Ideally, each test case is independent from the others. Substitutes such
as method stubs, mock objects, fakes, and test harnesses can be used to assist testing a
module in isolation. Unit tests are typically written and run by software developers to
ensure that code meets its design and behaves as intended.

Unit testing provides a sort of living documentation of the system. Developers


looking to learn what functionality is provided by a unit, and how to use it, can look at
the unit tests to gain a basic understanding of the unit's interface (API).Unit test
cases embody characteristics that are critical to the success of the unit. These
characteristics can indicate appropriate/inappropriate use of a unit as well as negative
behaviors that are to be trapped by the unit. A unit test case, in and of itself, documents
these critical characteristics, although many software development environments do
not rely solely upon code to document the product in development.When software is
developed using a test-driven approach, the combination of writing the unit test to
specify the interface plus the refactoring activities performed after the test is passing,
may take the place of formal design. Each unit test can be seen as a design element
specifying classes, methods, and observable behaviour.

Unit testing involves the design of test cases that validate that the internal
program logic is functioning properly, and that program inputs produce valid outputs.
All decision branches and internal code flow should be validated. It is the testing of
individual software units of the application.

Integration testing
Integration tests are designed to test integrated software components to
determine if they actually run as one program. Testing is event driven and is more
concerned with the basic outcome of screens or fields. Integration tests demonstrate
21
that although the components were individually satisfaction, as shown by successfully
unit testing, the combination of components is correct and consistent. Integration
testing is specifically aimed at exposing the problems that arise from the combination
of components.

Functional test
Functional tests provide systematic demonstrations that functions tested are
available as specified by the business and technical requirements, system
documentation, and user manuals.

Functional testing is centered on the following items:

Valid Input : identified classes of valid input must be accepted.

Invalid Input : identified classes of invalid input must be rejected.

Functions : identified functions must be exercised.

Output : identified classes of application outputs must be exercised.

Systems/Procedures : interfacing systems or procedures must be invoked.

Organization and preparation of functional tests is focused on requirements, key


functions, or special test cases. In addition, systematic coverage pertaining to identify
Business process flows; data fields, predefined processes, and successive processes
must be considered for testing. Before functional testing is complete, additional tests
are identified and the effective value of current tests is determined.

System Test

System testing ensures that the entire integrated software system meets
requirements. It tests a configuration to ensure known and predictable results. An
example of system testing is the configuration oriented system integration test. System

22
testing is based on process descriptions and flows, emphasizing pre-driven process
links and integration points.

White Box Testing

White Box Testing is a testing in which in which the software tester has
knowledge of the inner workings, structure and language of the software, or at least its
purpose. It is purpose. It is used to test areas that cannot be reached from a black box
level.

Black Box Testing

Black Box Testing is testing the software without any knowledge of the inner
workings, structure or language of the module being tested. Black box tests, as most
other kinds of tests, must be written from a definitive source document, such as
specification or requirements document, such as specification or requirements
document. It is a testing in which the software under test is treated, as a black box .you
cannot “see” into it. The test provides inputs and responds to outputs without
considering how the software works.

Black-box testing is a method of software testing that examines the functionality


of an application without peering into its internal structures or workings. This method
of test can be applied to virtually every level of software. It typically comprises most if
not all higher level testing, but can also dominate unit testing as well.

Specific knowledge of the application's code/internal structure and


programming knowledge in general is not required. The tester is aware of what the
software is supposed to do but is not aware of how it does it. For instance, the tester is
aware that a particular input returns a certain, invariable output but is not aware
of how the software produces the output in the first place. Test cases are built around
specifications and requirements, i.e., what the application is supposed to do. Test cases

23
are generally derived from external descriptions of the software, including
specifications, requirements and design parameters. Although the tests used are
primarily functional in nature, non-functional tests may also be used.

Unit Testing

Unit testing is usually conducted as part of a combined code and unit test phase
of the software lifecycle, although it is not uncommon for coding and unit testing to be
conducted as two distinct phases.

Test strategy and approach

Field testing will be performed manually and functional tests will be written in
detail.

Test objectives

 All field entries must work properly.

 Pages must be activated from the identified link.

 The entry screen, messages and responses must not be delayed.

Features to be tested

 Verify that the entries are of the correct format

 No duplicate entries should be allowed

 All links should take the user to the correct page.

24
Integration Testing

Software integration testing is the incremental integration testing of two or more


integrated software components on a single platform to produce failures caused by
interface defects.

The task of the integration test is to check that components or software


applications, e.g. components in a software system or – one step up – software
applications at the company level – interact without error.

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

7. APPENDICES
7.1 Source code

package com.shopit.shopit.activities;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
25
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.shopit.shopit.R;
import com.shopit.shopit.database.EntityPersistenceListener;
import com.shopit.shopit.database.InsertEntityAsyncTask;
import com.shopit.shopit.database.InstantiateDatabase;
import com.shopit.shopit.database.PersistableItem;
import com.shopit.shopit.database.PersistableItemDao;
import java.util.ArrayList;
public class ItemInfoActivity extends AppCompatActivity {
private ImageView itemInfoImage;
private TextView itemInfoName;
private TextView itemInfoPrice;
private FloatingActionButton floatingActionButton;
private TextView size1, size2, size3, size4, size5;
private LinearLayout color1, color2, color3, color4, color5;
private LinearLayout size1Selection, size2Selection, size3Selection, size4Selection,
size5Selection;
private LinearLayout color1Selection, color2Selection, color3Selection,
color4Selection, color5Selection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

26
setContentView(R.layout.activity_item_info);
initViews();
}
private void initViews() {
itemInfoImage = findViewById(R.id.item_info_image);
itemInfoName = findViewById(R.id.item_info_name);
itemInfoPrice = findViewById(R.id.item_info_price);
floatingActionButton = findViewById(R.id.add_to_cart);
final ArrayList<TextView> sizeViews = new ArrayList<TextView>();
final ArrayList<LinearLayout> sizeSelection = new ArrayList<LinearLayout>();
final ArrayList<LinearLayout> colorViews = new ArrayList<LinearLayout>();
final ArrayList<LinearLayout> colorSelection = new ArrayList<LinearLayout>();
initSizeView(sizeViews, sizeSelection);
initColorView(colorViews,colorSelection);
final String itemImageUrl = getIntent().getStringExtra("itemUrl");
final String itemName = getIntent().getStringExtra("itemName");
final Double itemPrice = getIntent().getDoubleExtra("itemPrice", 0.0d);
final String itemId = getIntent().getStringExtra("itemId");
final ArrayList<String> sizes = getIntent().getStringArrayListExtra("sizes");
final ArrayList<String> colors = getIntent().getStringArrayListExtra("colors");
itemInfoName.setText(itemName);
itemInfoPrice.setText(Double.toString(itemPrice));
for (int i = 0; i < sizes.size(); i++) {
sizeViews.get(i).setText(sizes.get(i));
sizeSelection.get(i).setVisibility(View.VISIBLE);
}

for (int i = 0; i < colors.size(); i++) {

27
colorViews.get(i).setBackgroundColor(Color.parseColor(colors.get(i)));
colorSelection.get(i).setVisibility(View.VISIBLE);
}
Glide.with(this)
.load(itemImageUrl)
.into(itemInfoImage);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PersistableItemDao persistableItemDao =
InstantiateDatabase.getDatabaseInstance
(getApplicationContext()).itemsDao();
PersistableItem persistableItem = new PersistableItem();
persistableItem.itemId = itemId;
persistableItem.itemColor = "Green";
persistableItem.itemSize = "L";
new InsertEntityAsyncTask(ItemInfoActivity.this, persistableItem, new
EntityPersistenceListener() {
@Override
public void onEntityPersisted() {
Toast.makeText(ItemInfoActivity.this, "Added to cart",
Toast.LENGTH_LONG).show();
}

@Override
public void onFailureOccured() {
Toast.makeText(ItemInfoActivity.this, "Something went wrong",
Toast.LENGTH_LONG).show();

28
}
}, persistableItemDao).execute();
}
});
}
private void initSizeView(final ArrayList<TextView> sizeViews, final
ArrayList<LinearLayout> sizeSelection) {
size1 = findViewById(R.id.size1);
size2 = findViewById(R.id.size2);
size3 = findViewById(R.id.size3);
size4 = findViewById(R.id.size4);
size5 = findViewById(R.id.size5);
size1Selection = findViewById(R.id.size1_selection);
size2Selection = findViewById(R.id.size2_selection);
size3Selection = findViewById(R.id.size3_selection);
size4Selection = findViewById(R.id.size4_selection);
size5Selection = findViewById(R.id.size5_selection);
sizeViews.add(size1);
sizeViews.add(size2);
sizeViews.add(size3);
sizeViews.add(size4);
sizeViews.add(size5);
sizeSelection.add(size1Selection);
sizeSelection.add(size2Selection);
sizeSelection.add(size3Selection);
sizeSelection.add(size4Selection);
sizeSelection.add(size5Selection);
SizeOnClickListener sizeOnClickListener = new SizeOnClickListener();

29
size1Selection.setOnClickListener(sizeOnClickListener);
size2Selection.setOnClickListener(sizeOnClickListener);
size3Selection.setOnClickListener(sizeOnClickListener);
size4Selection.setOnClickListener(sizeOnClickListener);
size5Selection.setOnClickListener(sizeOnClickListener);
size1Selection.setVisibility(View.GONE);
size2Selection.setVisibility(View.GONE);
size3Selection.setVisibility(View.GONE);
size4Selection.setVisibility(View.GONE);
size5Selection.setVisibility(View.GONE);
}
private void initColorView(final ArrayList<LinearLayout> colorViews, final
ArrayList<LinearLayout> colorSelection) {
color1 = findViewById(R.id.color1);
color2 = findViewById(R.id.color2);
color3 = findViewById(R.id.color3);
color4 = findViewById(R.id.color4);
color5 = findViewById(R.id.color5);
color1Selection = findViewById(R.id.color1_selection);
color2Selection = findViewById(R.id.color2_selection);
color3Selection = findViewById(R.id.color3_selection);
color4Selection = findViewById(R.id.color4_selection);
color5Selection = findViewById(R.id.color5_selection);
colorViews.add(color1);
colorViews.add(color2);
colorViews.add(color3);
colorViews.add(color4);
colorViews.add(color5);

30
colorSelection.add(color1Selection);
colorSelection.add(color2Selection);
colorSelection.add(color3Selection);
colorSelection.add(color4Selection);
colorSelection.add(color5Selection);
ColorOnClickListener colorOnClickListener = new ColorOnClickListener();
color1Selection.setOnClickListener(colorOnClickListener);
color2Selection.setOnClickListener(colorOnClickListener);
color3Selection.setOnClickListener(colorOnClickListener);
color4Selection.setOnClickListener(colorOnClickListener);
color5Selection.setOnClickListener(colorOnClickListener);
color1Selection.setVisibility(View.GONE);
color2Selection.setVisibility(View.GONE);
color3Selection.setVisibility(View.GONE);
color4Selection.setVisibility(View.GONE);
color5Selection.setVisibility(View.GONE);
}
class SizeOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
switch (v.getId()) {

case R.id.size1_selection:
size1Selection.setBackgroundResource(R.color.black);
if (size2Selection.getVisibility() == View.VISIBLE) {
size2Selection.setBackgroundResource(R.color.white);
}
if (size3Selection.getVisibility() == View.VISIBLE) {

31
size3Selection.setBackgroundResource(R.color.white);
}
if (size4Selection.getVisibility() == View.VISIBLE) {
size4Selection.setBackgroundResource(R.color.white);
}
if (size5Selection.getVisibility() == View.VISIBLE) {
size5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.size2_selection:
size2Selection.setBackgroundResource(R.color.black);
if (size1Selection.getVisibility() == View.VISIBLE) {
size1Selection.setBackgroundResource(R.color.white);
}
if (size3Selection.getVisibility() == View.VISIBLE) {
size3Selection.setBackgroundResource(R.color.white);
}
if (size4Selection.getVisibility() == View.VISIBLE) {
size4Selection.setBackgroundResource(R.color.white);
}
if (size5Selection.getVisibility() == View.VISIBLE) {
size5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.size3_selection:
size3Selection.setBackgroundResource(R.color.black);
if (size1Selection.getVisibility() == View.VISIBLE) {
size1Selection.setBackgroundResource(R.color.white);

32
}
if (size2Selection.getVisibility() == View.VISIBLE) {
size2Selection.setBackgroundResource(R.color.white);
}
if (size4Selection.getVisibility() == View.VISIBLE) {
size4Selection.setBackgroundResource(R.color.white);
}
if (size5Selection.getVisibility() == View.VISIBLE) {
size5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.size4_selection:
size4Selection.setBackgroundResource(R.color.black);
if (size1Selection.getVisibility() == View.VISIBLE) {
size1Selection.setBackgroundResource(R.color.white);
}
if (size2Selection.getVisibility() == View.VISIBLE) {
size2Selection.setBackgroundResource(R.color.white);
}
if (size3Selection.getVisibility() == View.VISIBLE) {
size3Selection.setBackgroundResource(R.color.white);
}
if (size5Selection.getVisibility() == View.VISIBLE) {
size5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.size5_selection:
size5Selection.setBackgroundResource(R.color.black);

33
if (size1Selection.getVisibility() == View.VISIBLE) {
size1Selection.setBackgroundResource(R.color.white);
}
if (size2Selection.getVisibility() == View.VISIBLE) {
size2Selection.setBackgroundResource(R.color.white);
}
if (size3Selection.getVisibility() == View.VISIBLE) {
size3Selection.setBackgroundResource(R.color.white);
}
if (size4Selection.getVisibility() == View.VISIBLE) {
size4Selection.setBackgroundResource(R.color.white);
}
break;
}
}
}
class ColorOnClickListener implements View.OnClickListener {

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

case R.id.color1_selection:
color1Selection.setBackgroundResource(R.color.black);
if (color2Selection.getVisibility() == View.VISIBLE) {
color2Selection.setBackgroundResource(R.color.white);
}
if (color3Selection.getVisibility() == View.VISIBLE) {

34
color3Selection.setBackgroundResource(R.color.white);
}
if (color4Selection.getVisibility() == View.VISIBLE) {
color4Selection.setBackgroundResource(R.color.white);
}
if (color5Selection.getVisibility() == View.VISIBLE) {
color5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.color2_selection:
color2Selection.setBackgroundResource(R.color.black);
if (color1Selection.getVisibility() == View.VISIBLE) {
color1Selection.setBackgroundResource(R.color.white);
}
if (color3Selection.getVisibility() == View.VISIBLE) {
color3Selection.setBackgroundResource(R.color.white);
}
if (color4Selection.getVisibility() == View.VISIBLE) {
color4Selection.setBackgroundResource(R.color.white);
}
if (color5Selection.getVisibility() == View.VISIBLE) {
color5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.color3_selection:
color3Selection.setBackgroundResource(R.color.black);
if (color1Selection.getVisibility() == View.VISIBLE) {
color1Selection.setBackgroundResource(R.color.white);

35
}
if (color2Selection.getVisibility() == View.VISIBLE) {
color2Selection.setBackgroundResource(R.color.white);
}
if (color4Selection.getVisibility() == View.VISIBLE) {
color4Selection.setBackgroundResource(R.color.white);
}
if (color5Selection.getVisibility() == View.VISIBLE) {
color5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.color4_selection:
color4Selection.setBackgroundResource(R.color.black);
if (color1Selection.getVisibility() == View.VISIBLE) {
color1Selection.setBackgroundResource(R.color.white);
}
if (color2Selection.getVisibility() == View.VISIBLE) {
color2Selection.setBackgroundResource(R.color.white);
}
if (color3Selection.getVisibility() == View.VISIBLE) {
color3Selection.setBackgroundResource(R.color.white);
}
if (color5Selection.getVisibility() == View.VISIBLE) {
color5Selection.setBackgroundResource(R.color.white);
}
break;
case R.id.color5_selection:
color5Selection.setBackgroundResource(R.color.black);

36
if (color1Selection.getVisibility() == View.VISIBLE) {
color1Selection.setBackgroundResource(R.color.white);
}
if (color2Selection.getVisibility() == View.VISIBLE) {
color2Selection.setBackgroundResource(R.color.white);
}
if (color3Selection.getVisibility() == View.VISIBLE) {
color3Selection.setBackgroundResource(R.color.white);
}
if (color4Selection.getVisibility() == View.VISIBLE) {
size4Selection.setBackgroundResource(R.color.white);
}
break;
}
}
}
}

package com.shopit.shopit.login;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

37
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.shopit.shopit.MainActivity;
import com.shopit.shopit.R;
import com.shopit.shopit.navigation.Navigator;
public class LoginActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private FirebaseAuth auth;
private ProgressDialog progressDialog;
private Button btnSignup, btnLogin, btnReset;
private CoordinatorLayout loginBackground;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Get Firebase auth instance


auth = FirebaseAuth.getInstance();

if (auth.getCurrentUser() != null) {
startActivity(new Intent(LoginActivity.this, Navigator.class));
finish();
}

// set the view now

38
setContentView(R.layout.activity_login);

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


// setSupportActionBar(toolbar);
loginBackground = findViewById(R.id.login_background);
//loginBackground.setAlpha(0.4f);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Signing you in !");
progressDialog.setCanceledOnTouchOutside(false);

btnSignup = (Button) findViewById(R.id.btn_signup);


btnLogin = (Button) findViewById(R.id.btn_login);
btnReset = (Button) findViewById(R.id.btn_reset_password);

//Get Firebase auth instance


auth = FirebaseAuth.getInstance();

btnSignup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, SignUpActivity.class));
finish();
}
});

39
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, ResetPasswordActivity.class));
finish();
}
});

btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();

if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!",
Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!",
Toast.LENGTH_SHORT).show();
return;
}

progressDialog.show();

//authenticate user

40
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(LoginActivity.this, new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
progressDialog.dismiss();
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {

inputPassword.setError(getString(R.string.minimum_password));
} else {
Toast.makeText(LoginActivity.this,
getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
} else {
Intent intent = new Intent(LoginActivity.this, Navigator.class);
startActivity(intent);
finish();
}
}
});
}
});
}

41
}

package com.shopit.shopit.login;

/**
* Created by mohit on 24/9/18.
*/

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.shopit.shopit.R;

public class ResetPasswordActivity extends AppCompatActivity {

private EditText inputEmail;


private Button btnReset, btnBack;

42
private FirebaseAuth auth;
private ProgressDialog progressDialog;

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

inputEmail = (EditText) findViewById(R.id.email);


btnReset = (Button) findViewById(R.id.btn_reset_password);
btnBack = (Button) findViewById(R.id.btn_back);
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Sending email");
progressDialog.setCanceledOnTouchOutside(false);

auth = FirebaseAuth.getInstance();

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

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

43
String email = inputEmail.getText().toString().trim();

if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplication(), "Enter your registered email id",
Toast.LENGTH_SHORT).show();
return;
}

progressDialog.show();
auth.sendPasswordResetEmail(email)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
progressDialog.dismiss();
if (task.isSuccessful()) {
Toast.makeText(ResetPasswordActivity.this, "We have sent you
instructions to reset your password!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ResetPasswordActivity.this, "Failed to send
reset email!", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}

44
}

package com.shopit.shopit.login;

/**
* Created by mohit on 24/9/18.
*/

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.shopit.shopit.MainActivity;
import com.shopit.shopit.R;
import com.shopit.shopit.navigation.Navigator;

public class SignUpActivity extends AppCompatActivity {

45
private EditText inputEmail, inputPassword;
private Button btnSignIn, btnSignUp, btnResetPassword;
private ProgressDialog progressDialog;
private FirebaseAuth auth;

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

//Get Firebase auth instance


auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
startActivity(new Intent(this, Navigator.class));
finish();
}

btnSignIn = (Button) findViewById(R.id.sign_in_button);


btnSignUp = (Button) findViewById(R.id.sign_up_button);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Creating account !");
progressDialog.setCanceledOnTouchOutside(false);
btnResetPassword = (Button) findViewById(R.id.btn_reset_password);

46
btnResetPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SignUpActivity.this, ResetPasswordActivity.class));
finish();
}
});

btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SignUpActivity.this, LoginActivity.class));
finish();
}
});

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

String email = inputEmail.getText().toString().trim();


String password = inputPassword.getText().toString().trim();

if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!",
Toast.LENGTH_SHORT).show();
return;
}

47
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!",
Toast.LENGTH_SHORT).show();
return;
}

if (password.length() < 6) {
Toast.makeText(getApplicationContext(), "Password too short, enter
minimum 6 characters!", Toast.LENGTH_SHORT).show();
return;
}

progressDialog.show();
//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignUpActivity.this, new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(SignUpActivity.this, "Authentication failed." +
task.getException().getMessage(),
Toast.LENGTH_SHORT).show();

48
} else {

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

}
});
}
}

package com.shopit.shopit.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

49
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
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.shopit.shopit.R;
import com.shopit.shopit.model.Category;
import com.shopit.shopit.navigation.FragmentTransactionUtils;
import com.shopit.shopit.viewHolders.CategoryViewHolder;

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

/**
* Created by mohit on 30/9/18.
*/

public class CategoryFragment extends Fragment {

private RecyclerView mRecyclerView;


private GenericRecyclerViewAdapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private DatabaseReference databaseReference;
private ValueEventListener valueEventListener;
private static AppCompatActivity appCompatActivity;

50
private static int navViewId;

public static CategoryFragment getInstance(AppCompatActivity


mAppCompatActivity,int mNavViewId){
appCompatActivity = mAppCompatActivity;
navViewId = mNavViewId;
return new CategoryFragment();
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.item_recyclerview, container, false);
mRecyclerView = rootView.findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
databaseReference =
FirebaseDatabase.getInstance().getReference().child("shopit").child("category");
valueEventListener = new CategoryValueEventListener();
//mAdapter = new DisplayItemRecyclerViewAdapter(getContext());

mAdapter = new
GenericRecyclerViewAdapter<Category,CategoryViewHolder>(new
ViewHolderCreater<CategoryViewHolder>() {
@Override

51
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int
viewType) {
View v=
LayoutInflater.from(getContext()).inflate(R.layout.category_card_layout,parent,false);
return new CategoryViewHolder(v);
}
}, new ViewHolderBinder<Category, CategoryViewHolder>() {
@Override
public void onBindViewHolder(final CategoryViewHolder holder, final
List<Category> categories, final int position) {
Glide.with(getContext())
.load(categories.get(position).getUrl())
.into(new SimpleTarget<GlideDrawable>() {
@Override
public void onResourceReady(GlideDrawable resource,
GlideAnimation<? super GlideDrawable> glideAnimation) {
holder.categoryLinearLayout.setBackground(resource);
}
});
holder.categoryLinearLayout.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
final CategoryTypeFragment categoryTypeFragment =
CategoryTypeFragment.getInstance(appCompatActivity,navViewId);
Bundle bundle = new Bundle();
ArrayList<String> childHierarchy = new ArrayList<String>();
childHierarchy.add("shopit");

52
childHierarchy.add(categories.get(position).getName());
bundle.putStringArrayList("childHierarchy",childHierarchy);
categoryTypeFragment.setArguments(bundle);

FragmentTransactionUtils.changeFragment(appCompatActivity,categoryTypeFragment
,navViewId);
}
});
}
});
mRecyclerView.setAdapter(mAdapter);
return rootView;
}

@Override
public void onStart() {
super.onStart();
databaseReference.addValueEventListener(valueEventListener);
}

@Override
public void onStop() {
super.onStop();
if(valueEventListener!=null)
databaseReference.removeEventListener(valueEventListener);
}

class CategoryValueEventListener implements ValueEventListener{

53
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
List<Category> updates = new ArrayList<>();
for(DataSnapshot itemSnapshot:dataSnapshot.getChildren()){
updates.add(itemSnapshot.getValue(Category.class));
}
mAdapter.onUpdate(updates);
}

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

}
}
}

package com.shopit.shopit.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

54
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.SimpleResource;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
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.shopit.shopit.R;
import com.shopit.shopit.model.Category;
import com.shopit.shopit.model.CategoryType;
import com.shopit.shopit.navigation.FragmentTransactionUtils;
import com.shopit.shopit.viewHolders.CategoryTypeViewHolder;
import com.shopit.shopit.viewHolders.CategoryViewHolder;

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

/**
* Created by mohit on 30/9/18.
*/

public class CategoryTypeFragment extends Fragment {

55
private RecyclerView mRecyclerView;
private GenericRecyclerViewAdapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private DatabaseReference databaseReference;
private ValueEventListener valueEventListener;
private static AppCompatActivity appCompatActivity;
private static int navViewId;

public static CategoryTypeFragment getInstance(AppCompatActivity


mAppCompatActivity, int mNavViewId){
appCompatActivity = mAppCompatActivity;
navViewId = mNavViewId;
return new CategoryTypeFragment();
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.item_recyclerview, container, false);
mRecyclerView = rootView.findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
final Bundle bundle = getArguments();
List<String> childHierarchy = bundle.getStringArrayList("childHierarchy");
databaseReference = FirebaseDatabase.getInstance().getReference();

56
for(String child:childHierarchy){
databaseReference = databaseReference.child(child);
}

valueEventListener = new CategoryTypeValueEventListener();


//mAdapter = new DisplayItemRecyclerViewAdapter(getContext());

mAdapter = new
GenericRecyclerViewAdapter<CategoryType,CategoryTypeViewHolder>(new
ViewHolderCreater<CategoryTypeViewHolder>() {
@Override
public CategoryTypeViewHolder onCreateViewHolder(ViewGroup parent, int
viewType) {
View v=
LayoutInflater.from(getContext()).inflate(R.layout.category_type_cardlayout,parent,fal
se);
return new CategoryTypeViewHolder(v);
}
}, new ViewHolderBinder<CategoryType, CategoryTypeViewHolder>() {
@Override
public void onBindViewHolder(final CategoryTypeViewHolder holder,final
List<CategoryType> categories,final int position) {
Glide.with(getContext())
.load(categories.get(position).getUrl())
.into(holder.categoryTypeImage);
holder.categoryTypeName.setText(categories.get(position).getName());
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override

57
public void onClick(View v) {
DisplayItemsFragment displayItemsFragment =
DisplayItemsFragment.getInstance(appCompatActivity,navViewId);
Bundle bundle = new Bundle();
ArrayList<String> childHierarchy = new ArrayList<String>();
childHierarchy.add("shopit");
childHierarchy.add(categories.get(position).getName());
bundle.putStringArrayList("childHierarchy",childHierarchy);
displayItemsFragment.setArguments(bundle);

FragmentTransactionUtils.changeFragment(appCompatActivity,displayItemsFragment,
navViewId);
}
});

}
});
mRecyclerView.setAdapter(mAdapter);
return rootView;
}

@Override
public void onStart() {
super.onStart();
databaseReference.addValueEventListener(valueEventListener);
}

@Override

58
public void onStop() {
super.onStop();
if(valueEventListener!=null)
databaseReference.removeEventListener(valueEventListener);
}

class CategoryTypeValueEventListener implements ValueEventListener{

@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
List<CategoryType> updates = new ArrayList<>();
for(DataSnapshot itemSnapshot:dataSnapshot.getChildren()){
updates.add(itemSnapshot.getValue(CategoryType.class));
}
mAdapter.onUpdate(updates);
}

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

}
}
}

package com.shopit.shopit.fragments;

59
import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.shopit.shopit.R;
import com.shopit.shopit.model.Item;

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

/**
* Created by mohit on 30/9/18.
*/

public class DisplayItemRecyclerViewAdapter extends


RecyclerView.Adapter<DisplayItemRecyclerViewAdapter.ViewHolder> {

private Context context;


private List<Item> items = new ArrayList<Item>();

60
public DisplayItemRecyclerViewAdapter(Context context){
this.context = context;
}

public static class ViewHolder extends RecyclerView.ViewHolder {


public TextView itemPrice;
public TextView itemName;
public ImageView itemImage;
public CardView itemCardView;

public ViewHolder(View v) {
super(v);
itemImage = v.findViewById(R.id.item_image);
itemPrice = v.findViewById(R.id.item_price);
itemName = v.findViewById(R.id.item_name);
itemCardView = v.findViewById(R.id.item_card_view);
}
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v=
LayoutInflater.from(context).inflate(R.layout.item_cardlayout,parent,false);
return new ViewHolder(v);
}

61
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.itemPrice.setText("$"+items.get(position).getPrice().toString());
holder.itemName.setText(items.get(position).getName().toString());
Glide.with(context)
.load(items.get(position).getUrl())
.into(holder.itemImage);
}

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

public void onUpdate(List<Item> updates){


items.clear();
items.addAll(updates);
notifyDataSetChanged();
}
}

package com.shopit.shopit.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

62
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.google.firebase.database.ChildEventListener;
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.shopit.shopit.R;
import com.shopit.shopit.activities.ItemInfoActivity;
import com.shopit.shopit.model.Item;
import com.shopit.shopit.viewHolders.ItemViewHolder;

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

/**
* Created by mohit on 30/9/18.
*/

63
public class DisplayItemsFragment extends Fragment {

private RecyclerView mRecyclerView;


private GenericRecyclerViewAdapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private DatabaseReference databaseReference;
private List<ValueEventListener> valueEventListeners = new ArrayList<>();
private static final Integer slotSize = 100;

private static AppCompatActivity appCompatActivity;


private static int navViewId;

public static DisplayItemsFragment getInstance(AppCompatActivity


mAppCompatActivity,int mNavViewId){
appCompatActivity = mAppCompatActivity;
navViewId = mNavViewId;
return new DisplayItemsFragment();
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.item_recyclerview, container, false);
mRecyclerView = rootView.findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);

64
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
databaseReference = FirebaseDatabase.getInstance().getReference();

final Bundle bundle = getArguments();


final List<String> childHierarchy = bundle.getStringArrayList("childHierarchy");
databaseReference = FirebaseDatabase.getInstance().getReference();
for(String child:childHierarchy){
databaseReference = databaseReference.child(child);
}
//mAdapter = new DisplayItemRecyclerViewAdapter(getContext());

mAdapter = new GenericRecyclerViewAdapter<Item,ItemViewHolder>(new


ViewHolderCreater<ItemViewHolder>() {
@Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View v=
LayoutInflater.from(getContext()).inflate(R.layout.item_cardlayout,parent,false);
return new ItemViewHolder(v);
}
}, new ViewHolderBinder<Item, ItemViewHolder>() {
@Override
public void onBindViewHolder(ItemViewHolder holder, final List<Item>
items, final int position) {
holder.itemPrice.setText("$"+items.get(position).getPrice().toString());
holder.itemName.setText(items.get(position).getName().toString());
Glide.with(getContext())

65
.load(items.get(position).getUrl())
.into(holder.itemImage);
holder.itemCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), ItemInfoActivity.class);
intent.putExtra("itemUrl",items.get(position).getUrl());
intent.putExtra("itemName",items.get(position).getName());
intent.putExtra("itemPrice",items.get(position).getPrice());
intent.putExtra("itemId",items.get(position).getId());
String sizesAvailable = items.get(position).getSizesAvailable();
String[] sizes = sizesAvailable.split(",");

ArrayList<String> sizeList = new ArrayList<String>();

for(String size:sizes)
sizeList.add(size);

String colorsAvailable = items.get(position).getColorsAvailable();


String[] colors = colorsAvailable.split(",");

ArrayList<String> colorsList = new ArrayList<String>();

for(String color:colors)
colorsList.add(color);

intent.putStringArrayListExtra("sizes",sizeList);
intent.putStringArrayListExtra("colors",colorsList);

66
getContext().startActivity(intent);
}
});
}
});
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if(!recyclerView.canScrollVertically(1)){
Item item = (Item) mAdapter.getLastItem();
String lastKeyReceived = item.getKey();
Log.e("Scrolling Reached last","Attaching new listener from
"+lastKeyReceived);
ValueEventListener nextSlotListener = new ItemValueEventListener();

databaseReference.orderByKey().startAt(lastKeyReceived).limitToFirst(slotSize).addV
alueEventListener(nextSlotListener);
valueEventListeners.add(nextSlotListener);

}
}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}

67
});
return rootView;
}

@Override
public void onStart() {
super.onStart();
ValueEventListener initialValueEventListener = new ItemValueEventListener();
valueEventListeners.add(initialValueEventListener);

databaseReference.orderByKey().limitToFirst(slotSize).addValueEventListener(initialV
alueEventListener);

@Override
public void onStop() {
super.onStop();
for(ValueEventListener listener:valueEventListeners)
databaseReference.removeEventListener(listener);
}

class ItemValueEventListener implements ValueEventListener{

@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot itemSnapshot:dataSnapshot.getChildren()){
Item item = itemSnapshot.getValue(Item.class);

68
item.setKey(itemSnapshot.getKey());
mAdapter.onUpdateSingleItem(item);
}
}

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

}
}
}

package com.shopit.shopit;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.shopit.shopit.login.LoginActivity;

/**

69
* Created by mohit on 24/9/18.
*/

public class MainActivity extends AppCompatActivity{

private TextView loggedinUser;


private FirebaseAuth auth;
FirebaseAuth.AuthStateListener authListener;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loggedinUser = findViewById(R.id.user_loggedin);
auth = FirebaseAuth.getInstance();
authListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
Toast.makeText(MainActivity.this,"Auth State
changed",Toast.LENGTH_SHORT).show();
if (user == null) {
// user auth state is changed - user is null
// launch login activity
startActivity(new Intent(MainActivity.this, LoginActivity.class));
finish();
}
}

70
};

if (auth.getCurrentUser() != null) {
loggedinUser.setText("Hello "+ auth.getCurrentUser().getEmail());
}
}

@Override
protected void onStart() {
super.onStart();
auth.addAuthStateListener(authListener);
}

@Override
protected void onStop() {
super.onStop();
if (authListener != null) {
auth.removeAuthStateListener(authListener);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override

71
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id){
case R.id.signout:
auth.signOut();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

7.2 Screenshot

72
73
74
75
76
77
78
79
8. CONCLUSION
80
The project entitled Online Shopping is developed using android studio as to
computerize the process of online buying and selling of product in a showroom. This
project covers only the basic features required. However a lot of features are already
incorporated in this project. The main beneficiaries are both customers as well as
ADMIN who consume more time while dealing with products. Moreover extra
features can be identified and incorporated in the future In order to accommodate
additional features it will take longer time and effort to understand the requirement
and converting it into computerized system

9. FUTURE ENHANCEMENT

81
The system could be modified suitably to work on a large network. This
involves, among other, resolving used conflicts, protecting database integrity and
ensuring consistency of data if it is distributed across multiple locations. Maintain
attendance details of employee. Maintain product details.

10. BIBLIOGRAPHY

82
 JavaScript Enlightenment,Cody Lindley-First Edition, based onJavaScript 1.5,
ECMA-262, Edition

 Mc GrawHill’s , Java : The complete reference 7thEdition, Herbert Schildit

 Complete CSS Guide ,Maxine Sherrin and John Allsopp-O'ReillyMedia;


September 2012

 http://www.w3schools.com/html/defualt.asp

 http://www.w3schools.com/css/default.asp

 http://www.w3schools.com/js/default.asp

83

You might also like