Download as pdf or txt
Download as pdf or txt
You are on page 1of 161

ST XAVIER’S COLLEGE OF MANAGEMENT

AND TECHNOLOGY

BACHELOR’S IN COMPUTER APPLICATIONS


Session -2017-2020

Project Report
submitted to Aryabhata Knowledge University
for the partial fulfilment of bachelor’s in computer application
(B.C.A)

Rohit Kumar Reg. No: 17303302043

1|Page
Acknowledgment

The satisfaction that accompanies the successful completion of this


project would be incomplete without the mention of people whose
ceaseless co-operation made it possible, whose constant guidance
and encouragement crown all efforts with success.

First of all, I would like to thank the almighty god. We are so busy
in our daily lives that we fail to notice that the almighty is always
there to shower its blessings upon us. All these things would not
have been possible without his will.

I would like to thank the principal of St. Xavier’s College of


Management and Technology, Prof. Fr. Dr. T Nishant S.J.

I would like to thank my parent who supported me by providing a


suitable environment at home for better concentration to develop
this project. My approach may be average but they would always
find my work the best and this would always encourage me to go at
a more advanced level, every time.

Lastly, our sincere regards to Prof. Supriya Ma’am for the


guidance, inspiration, and constructive suggestions that helped us
in the preparation of this project. I convey our sincere thanks to
Prof. Supriya Ma’am for his commendable support towards the
successful completion of our project.

2|Page
Certificate

This is to certify that the project entitled “XO – a social media


application” submitted to Aryabhata Knowledge University in fulfilment
of the requirement for the award of Degree of Bachelors in computer
applications [BCA]; the matter embodied in this project is a genuine work

…………………………. ……………………………….

Signature of the Student who


Signature of the Principal
made this project.
Father Dr. T Nishant, SJ
St. Xavier’s College of
Management and Technology,
Patna – 11

………………………… ………………………………………

Signature of the Project Guide Signature of the Guide


Ms. Supriya Ma’am Aryabhata Knowledge
University
Professor of Dept. of Computer
Science

3|Page
Declaration

I, hereby declare that the work being presented in this project, titled “XO –
a social media application” as a part of course curriculum of bachelor in
Computer Application [BCA], is an authentic record of my own work
carried out under the guidance of Mr. Mukesh, Prof. in the Dept of
Computer Science, St. Xavier’s College of Management And Technology,
Patna.

Name : Rohit Kumar


Course : Bachelor’s in computer application
Reg. No. : 17303302043

4|Page
INDEX

S.no. Topic Page no.

1. Acknowledgement 2
2. Certificate 3
3. Introduction 6
4. Objective 8
5. Tools & Platform used 9
6. SRS 10
7. Flowchart 11
8. DFD 14
9. Design Document 15
10. Source code and screenshots 16
11. Testing 108
12. Limitations 109
12. Future scope 110
13. Bibliography 111

5|Page
XO – a social media application

A social networking service is an online service, platform, or


that focuses on facilitating the building of social networks or
social relations among people who, for example, share interests,
activities, backgrounds, or real-life connections. A social
network service consists of a representation of each user (often a
profile), his/her social links, and a variety of additional services.
Most social network services are web-based and provide means
for users to interact over the Internet, such as email and instant
messaging. Online community services are sometimes
considered as a social network service, though in a broader
sense, social network service usually means an individual-
cantered service whereas online community services are group
entered. Social networking sites allow users to share ideas,
activities, events, and interests within their networks.

Social networking Apps are not only for you to communicate


or interact with other people globally but, this is also one
effective way for business promotion. A lot of business-minded
people these days are now doing business online and use these
social networking sites to respond to customer queries. It isn't
just a social media site used to socialize with your friends but
also, represents a huge pool of information from day to day
living

6|Page
Why are we developing this project?

Social networking provides advancements especially in


communication and self-expression and the use of social
networking is expanding. Social Networking Sites are used by
diverse categories of users for a variety of purposes. The main goal
or motive of Social Networking app is to provide an interactive
environment to communicate with peers and get useful
information.

7|Page
OBJECTIVE

Profile: This is where you tell the word about yourself.


Profiles contain basic information, like where you
live and how old you are, and personality
questions, like who's your favourite actor and
what's your favourite book. Social networks
dedicated to a special theme like music or movies
might ask questions related to that theme.

Friends: Friends are trusted members of the site that are


allowed to post comments on your profile or send
you private messages. You can also keep tabs on
how your friends are using social networking,
such as when they post a new picture or update
their profile. Friends are the heart and soul of
social networking.

Posts: Another feature of some social networks is the


ability to create your post entries.

Comments: Features to comment in posts and share opinions.

8|Page
TOOLS AND PLATFORM

Platform

Smart phone , tablet


Android device with RAM: 1000 MB or more.
Storage Around 1 GB of free disk space.

Tools required

Android studio
firebase

Compatibility

• Android version 8.0 and above

9|Page
System Requirements & Specification (SRS)

SRS is the outcome of the requirements analysis and specification -


phase. It deals with the functional requirements, non-functional -
requirements, and constraints of the system. An SRS should have
characteristics like concise, unambiguous, consistent, complete, well-
structured, etc.

Environment required
• RAM: 1000 MB or more.
• Storage space more than 1 GB

10 | P a g e
Flowchart

Start

Existing
New user Select user user
type

Create login
account

Display post and


Or sign in with texts
google

Chats
Welcome
page

Select user
Give to chat
introduction

logout

11 | P a g e
Display all
Features

posts friends

Chat box
Chats

settings
profile

Search
Search
friends

friend

Search

posts

With friend

Chat

Search
new friend
12 | P a g e
Image

post

video

Chat

friends
Pin

block

Delete
chat

13 | P a g e
DFD

14 | P a g e
Design
well-designed interface and screen is important to the users that’s the
window for them to view the capabilities of the system. It is the vehicle
through which many critical tasks are presented which has a direct impact
on the organization’s relation with the users.

Designing UI

User interface design is an important part of building a positive user experience


with a product or service. Most users determine whether they like a product or
service very quickly based on the design's appearance and accessibility. The
primary responsibility of a designer is to develop interfaces that the user finds
highly efficient and usable. That is why it's imperative for designers to conduct
research in an attempt to fully understand the needs of the user and the context
in which they will be interacting with the product

Effects of a bad screen design are:


1. People will have greater difficulty in doing their job
2. More prone to mistakes
3. Chase people away from the system
4. Lead to aggravation, frustration and stress
Benefits of a good design are:
1. Screens are less crowded
2. Would be less time consuming, 25 percent less time
3. Screen would be 20 percent more productive
4. 25 percent fewer errors
5. Improve decision making time
6. Training cost are lower

15 | P a g e
Activity login

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="8dp" >

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="50dp"

android:layout_height="50dp"

android:id="@+id/image_profile"

android:src="@mipmap/ic_launcher" />

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toEndOf="@id/image_profile"

android:layout_marginStart="5dp"

android:orientation="vertical"

android:layout_centerHorizontal="true"

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

16 | P a g e
android:id="@+id/username"

android:text="username"

android:maxLines="1"

android:textStyle="bold"

android:textColor="@color/design_default_color_primary_dark" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/fullName"

android:text="Full Name "

android:maxLines="1" />

</LinearLayout>

<Button

android:layout_width="wrap_content"

android:layout_height="30dp"

android:background="@drawable/button_background"

android:id="@+id/btn_follow"

android:textColor="@color/colorPrimary"

android:layout_alignParentEnd="true"

android:layout_centerVertical="true"

android:visibility="gone" />

</RelativeLayout>

17 | P a g e
Main Activity
<?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=".MainActivity">

<FrameLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_above="@id/bottom"

android:id="@+id/fragment_container" />

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:id="@+id/bottom" >

<com.google.android.material.bottomnavigation.BottomNavigationView

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:itemIconTint="@color/colorAccent"

app:labelVisibilityMode="unlabeled"

android:background="?android:attr/windowBackground"

app:menu="@menu/bottom_navigation"

18 | P a g e
android:id="@+id/bottom_navigation" />

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

</RelativeLayout>

19 | P a g e
Activity options
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical"

tools:context=".OptionsActivity">

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar" >

</androidx.appcompat.widget.Toolbar>

<View

android:layout_width="match_parent"

android:layout_height="1dp"

android:background="@color/colorAccent" />

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="18sp"

android:layout_margin="8dp"

20 | P a g e
android:textColor="@color/colorPrimaryDark"

android:text="Settings"

android:id="@+id/settings" />

<View

android:layout_width="match_parent"

android:layout_height="1dp"

android:background="@color/colorAccent" />

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="18sp"

android:layout_margin="8dp"

android:textColor="@color/colorPrimaryDark"

android:text="Log Out"

android:id="@+id/logout" />

<View

android:layout_width="match_parent"

android:layout_height="1dp"

android:background="@color/colorAccent" />

21 | P a g e
Activity post
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

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:orientation="vertical"

tools:context=".PostActivity">

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/bar" >

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar" >

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

22 | P a g e
<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:src="@drawable/ic_close"

android:id="@+id/close" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="POST"

android:textSize="16sp"

android:layout_marginEnd="10dp"

android:layout_centerVertical="true"

android:layout_alignParentEnd="true"

android:textColor="@color/colorPrimary"

android:id="@+id/post" />

</RelativeLayout>

</androidx.appcompat.widget.Toolbar>

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

23 | P a g e
<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="8dp"

android:orientation="vertical" >

<ImageView

android:layout_width="match_parent"

android:layout_height="200dp"

android:scaleType="centerInside"

android:layout_gravity="center"

android:src="@mipmap/ic_launcher"

android:id="@+id/image_added" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:hint="Description"

android:maxLines="5"

android:id="@+id/description" />

24 | P a g e
Activity register
<?xml version="1.0" encoding="utf-8"?>

<androidx.appcompat.widget.LinearLayoutCompat
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:orientation="vertical"

android:gravity="center"

android:padding="10dp"

tools:context=".RegisterActivity">

<ImageView

android:layout_width="wrap_content"

android:layout_height="50dp"

android:src="@drawable/logo" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:background="@drawable/edit_text_background"

android:padding="10dp"

android:hint="User Name"

android:id="@+id/username" />

25 | P a g e
<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:padding="10dp"

android:background="@drawable/edit_text_background"

android:hint="Full Name"

android:id="@+id/fullName" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:background="@drawable/edit_text_background"

android:padding="10dp"

android:hint="Email"

android:inputType="textEmailAddress"

android:id="@+id/email" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:background="@drawable/edit_text_background"

android:padding="10dp"

android:hint="Password"

android:inputType="textPassword"

android:id="@+id/password" />

26 | P a g e
<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:textColor="@color/colorPrimary"

android:background="@drawable/button_background"

android:text="Register"

android:id="@+id/register" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="10dp"

android:text="Already have an account? Log In"

android:id="@+id/textLogin" />

</androidx.appcompat.widget.LinearLayoutCompat>

27 | P a g e
Activity start
<?xml version="1.0" encoding="utf-8"?>

<androidx.appcompat.widget.LinearLayoutCompat
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:gravity="center"

android:orientation="vertical"

android:padding="12dp"

tools:context=".StartActivity">

<!--

gravity - Standard constants and tools for placing an object within a potentially larger container

center - place the object in the center of its container in both teh vertical and horizontal

axis, not changing its size

-->

<ImageView

android:layout_width="wrap_content"

android:layout_height="50dp"

android:src="@drawable/logo" />

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

28 | P a g e
android:textColor="@color/colorPrimary"

android:background="@drawable/button_background"

android:text="Log In"

android:id="@+id/login" />

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:textColor="@color/colorPrimary"

android:background="@drawable/button_background"

android:text="Register"

android:id="@+id/register" />

</androidx.appcompat.widget.LinearLayoutCompat>

29 | P a g e
Activity story
<?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=".StoryActivity">

<ImageView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scaleType="centerCrop"

android:src="@drawable/placeholder"

android:id="@+id/image_story" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal" >

<View

android:layout_width="0dp"

30 | P a g e
android:layout_height="match_parent"

android:layout_weight="1"

android:id="@+id/reverse" />

<View

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:id="@+id/skip" />

</LinearLayout>

<jp.shts.android.storiesprogressview.StoriesProgressView

android:layout_width="match_parent"

android:layout_height="3dp"

android:paddingLeft="8dp"

android:paddingRight="8dp"

android:gravity="top"

android:id="@+id/stories" >

</jp.shts.android.storiesprogressview.StoriesProgressView>

<RelativeLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/stories"

android:layout_margin="10dp" >

31 | P a g e
<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="30dp"

android:layout_height="30dp"

android:layout_centerVertical="true"

android:id="@+id/story_photo" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_toEndOf="@id/story_photo"

android:layout_margin="5dp"

android:textStyle="bold"

android:textColor="#fff"

android:textSize="15sp"

android:text="username"

android:id="@+id/story_username" />

</RelativeLayout>

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:orientation="horizontal"

android:layout_margin="10dp"

android:padding="3dp"

32 | P a g e
android:background="#20000000"

android:id="@+id/container_seen" >

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:src="@drawable/ic_story_view" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="5dp"

android:layout_gravity="center"

android:textStyle="bold"

android:textSize="16sp"

android:textColor="#fff"

android:text="0"

android:id="@+id/seen_number" />

</LinearLayout>

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentEnd="true"

android:layout_margin="10dp

33 | P a g e
Activity story items
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="60dp"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_marginStart="10dp" >

<RelativeLayout

android:layout_width="50dp"

android:layout_height="50dp"

android:layout_gravity="center"

android:layout_marginTop="5dp" >

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="45dp"

android:layout_height="45dp"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:src="@drawable/placeholder"

android:id="@+id/story_photo" />

<de.hdodenhof.circleimageview.CircleImageView

34 | P a g e
android:layout_width="20dp"

android:layout_height="20dp"

android:layout_alignParentBottom="true"

android:layout_alignParentEnd="true"

android:src="@drawable/ic_story_plus"

android:id="@+id/story_plus" />

</RelativeLayout>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/colorPrimaryDark"

android:maxLines="1"

android:id="@+id/add_story_text" />

</LinearLayout>

35 | P a g e
Comments

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="8dp" >

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="40dp"

android:layout_height="40dp"

android:id="@+id/image_profile" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="5dp"

android:orientation="vertical"

android:layout_toEndOf="@id/image_profile" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark"

36 | P a g e
Home

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".Fragment.HomeFragment">

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/bar" >

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar" >

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

37 | P a g e
<ImageView

android:layout_width="180dp"

android:layout_height="35dp"

android:layout_marginLeft="-20dp"

android:layout_alignParentStart="true"

android:src="@drawable/logo" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="10dp"

android:layout_alignParentEnd="true"

android:src="@drawable/ic_inbox" />

</RelativeLayout>

</androidx.appcompat.widget.Toolbar>

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

<androidx.core.widget.NestedScrollView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/bar" >

<LinearLayout

android:layout_width="match_parent"

38 | P a g e
android:layout_height="wrap_content"

android:orientation="vertical" >

<!-- For Stories -->

<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="5dp"

android:id="@+id/recycler_view_story" />

<!-- For Regular Posts -->

<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/recycler_view" />

</LinearLayout>

</androidx.core.widget.NestedScrollView>

<ProgressBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:id="@+id/progress_circular"

39 | P a g e
Notification
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".Fragment.NotificationFragment">

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/bar" >

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar" >

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

40 | P a g e
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Notifications"

android:textSize="18sp"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark" />

</RelativeLayout>

</androidx.appcompat.widget.Toolbar>

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

<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/bar"

android:id="@+id/recycler_view" >

</androidx.recyclerview.widget.RecyclerView>

</RelativeLayout

41 | P a g e
Post details
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".Fragment.PostDetailFragment">

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/bar" >

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar" >

<RelativeLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content" >

42 | P a g e
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="18dp"

android:textStyle="bold"

android:text="Photo"

android:textColor="@color/colorPrimaryDark" />

</RelativeLayout>

</androidx.appcompat.widget.Toolbar>

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

<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/bar"

android:id="@+id/recycler_view" >

</androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>

43 | P a g e
Profiles
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".Fragment.ProfileFragment">

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/bar" >

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar">

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

<TextView

44 | P a g e
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="18sp"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark"

android:maxLines="1"

android:layout_centerHorizontal="true"

android:text="username"

android:id="@+id/username" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_marginEnd="10dp"

android:src="@drawable/ic_options"

android:id="@+id/options" />

</RelativeLayout>

</androidx.appcompat.widget.Toolbar>

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

<ScrollView

android:layout_width="match_parent"

45 | P a g e
android:layout_height="wrap_content"

android:layout_below="@id/bar" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

<!-- *************************************** -->

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:padding="16dp"

android:id="@+id/top_bar" >

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="80dp"

android:layout_height="80dp"

android:id="@+id/image_profile" />

<!-- *************************************** -->

<LinearLayout

android:layout_width="match_parent"

android:layout_height="80dp"

android:paddingLeft="20dp"

android:paddingRight="4dp"

android:orientation="vertical" >

46 | P a g e
<!-- *************************************** -->

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:orientation="horizontal" >

<!-- section for posts -->

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/colorPrimaryDark"

android:layout_gravity="center"

android:textSize="18sp"

android:textStyle="bold"

android:text="0"

android:id="@+id/posts" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="posts" />

</LinearLayout>

<!-- section for followers -->

47 | P a g e
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="35dp"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/colorPrimaryDark"

android:layout_gravity="center"

android:textSize="18sp"

android:textStyle="bold"

android:text="0"

android:id="@+id/followers" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="followers" />

</LinearLayout>

<!-- section for following -->

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="35dp"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@color/colorPrimaryDark"

android:layout_gravity="center"

48 | P a g e
android:textSize="18sp"

android:textStyle="bold"

android:text="0"

android:id="@+id/following" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="following" />

</LinearLayout>

</LinearLayout>

<!-- *************************************** -->

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:background="@drawable/button_black"

android:text="edit profile"

android:id="@+id/edit_profile" />

</LinearLayout>

<!-- *************************************** -->

</LinearLayout>

<!-- *************************************** -->

<LinearLayout

49 | P a g e
android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="12dp"

android:orientation="vertical"

android:id="@+id/mid_bar" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:maxLines="1"

android:textStyle="bold"

android:textSize="16sp"

android:textColor="@color/colorPrimaryDark"

android:text="full name"

android:id="@+id/fullName" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="5dp"

android:maxLines="5"

android:textColor="@color/colorPrimaryDark"

android:text="bio"

android:id="@+id/bio" />

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

50 | P a g e
android:layout_marginTop="10dp"

android:layout_marginLeft="-5dp"

android:layout_marginRight="-5dp"

android:background="@drawable/button_black"

android:orientation="horizontal"

android:id="@+id/last_bar" >

<ImageButton

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

style="?android:buttonBarButtonStyle"

android:src="@drawable/ic_grid"

android:id="@+id/my_photos" />

<ImageButton

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

style="?android:buttonBarButtonStyle"

android:src="@drawable/ic_save"

android:id="@+id/saved_photos" />

</LinearLayout>

51 | P a g e
<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/recycler_view" />

<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:visibility="gone"

android:id="@+id/recycler_view_save"

52 | P a g e
search
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".Fragment.SearchFragment">

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:attr/windowBackground"

android:id="@+id/bar" >

<androidx.appcompat.widget.Toolbar

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?android:windowBackground"

android:id="@+id/toolbar" >

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_search_light" />

53 | P a g e
<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="10dp"

android:layout_marginLeft="10dp"

android:background="@android:color/transparent"

android:hint="Search..."

android:id="@+id/search_bar" />

</androidx.appcompat.widget.Toolbar>

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

<androidx.recyclerview.widget.RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/bar"

android:id="@+id/recyclerView" >

</androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>

54 | P a g e
Notification 2
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="8dp" >

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="50dp"

android:layout_height="50dp"

android:id="@+id/image_profile" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="5dp"

android:orientation="vertical"

android:layout_toEndOf="@id/image_profile"

android:layout_toStartOf="@id/post_image" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark"

android:id="@+id/username" />

55 | P a g e
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:maxLines="5"

android:id="@+id/comment" />

</LinearLayout>

<ImageView

android:layout_width="50dp"

android:layout_height="50dp"

android:layout_alignParentEnd="true"

android:id="@+id/post_image" />

</RelativeLayout>

Photos

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<ImageView

56 | P a g e
Post 2

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_margin="15dp"

android:src="@drawable/ic_more"

android:id="@+id/more" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<de.hdodenhof.circleimageview.CircleImageView

57 | P a g e
android:layout_width="40dp"

android:layout_height="40dp"

android:layout_margin="10dp"

android:id="@+id/image_profile" />

<!-- android:src="@mipmap/ic_launcher" -->

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:textSize="16sp"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark"

android:id="@+id/username" />

</LinearLayout>

<androidx.constraintlayout.widget.ConstraintLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

<ImageView

android:layout_width="match_parent"

android:layout_height="0dp"

app:layout_constraintDimensionRatio="1:1"

android:id="@+id/post_image" />

<!-- android:src="@mipmap/ic_launcher" -->

</androidx.constraintlayout.widget.ConstraintLayout>

58 | P a g e
<RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="8dp" >

<ImageView

android:layout_width="30dp"

android:layout_height="30dp"

android:src="@drawable/ic_like"

android:id="@+id/like" />

<ImageView

android:layout_width="30dp"

android:layout_height="30dp"

android:src="@drawable/ic_comment"

android:layout_toEndOf="@+id/like"

android:layout_marginStart="10dp"

android:id="@+id/comment" />

<ImageView

android:layout_width="30dp"

android:layout_height="30dp"

android:src="@drawable/ic_save_black"

android:layout_alignParentEnd="true"

android:id="@+id/save" />

</RelativeLayout>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="8dp"

android:textStyle="bold"

59 | P a g e
android:textColor="@color/colorPrimaryDark"

android:id="@+id/likes" />

<!-- android:text="10 likes" -->

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="8dp"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark"

android:id="@+id/publisher" />

<!-- android:text="username" -->

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="8dp"

android:textStyle="bold"

android:textColor="@color/colorPrimaryDark"

android:id="@+id/description" />

60 | P a g e
Story 2
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="60dp"

android:layout_height="wrap_content"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="vertical"

android:layout_marginStart="10dp">

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="50dp"

android:layout_height="50dp"

app:civ_border_width="2dp"

app:civ_border_color="#f23b5a"

android:layout_gravity="center"

android:layout_marginTop="5dp"

android:src="@drawable/placeholder"

android:id="@+id/story_photo" />

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="50dp"

android:layout_height="50dp"

app:civ_border_width="2dp"

app:civ_border_color="#afafaf"

android:layout_gravity="center"

android:layout_marginTop="5dp"

61 | P a g e
User
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="8dp" >

<de.hdodenhof.circleimageview.CircleImageView

android:layout_width="50dp"

android:layout_height="50dp"

android:id="@+id/image_profile"

android:src="@mipmap/ic_launcher" />

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toEndOf="@id/image_profile"

android:layout_marginStart="5dp"

android:orientation="vertical"

android:layout_centerHorizontal="true">

62 | P a g e
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/username"

android:text="username"

android:maxLines="1"

android:textStyle="bold"

android:textColor="@color/design_default_color_primary_dark" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/fullName"

android:text="Full Name "

android:maxLines="1" />

</LinearLayout>

<Button

android:layout_width="wrap_content"

android:layout_height="30dp"

android:background="@drawable/button_background"

android:id="@+id/btn_follow"

android:textColor="@color/colorPrimary"

android:layout_alignParentEnd="true"

android:layout_centerVertical="true"

android:visibility="gone" />

</RelativeLayout>

63 | P a g e
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
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=".AddStoryActivity">

</androidx.constraintlayout.widget.ConstraintLayout>

64 | P a g e
Java code for adding story

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;

import android.content.ContentResolver;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.webkit.MimeTypeMap;

import android.widget.ProgressBar;

import android.widget.Toast;

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.auth.FirebaseAuth;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import com.google.firebase.database.ServerValue;

import com.google.firebase.storage.FirebaseStorage;

import com.google.firebase.storage.StorageReference;

import com.google.firebase.storage.StorageTask;

import com.theartofdev.edmodo.cropper.CropImage;

import java.util.HashMap;

65 | P a g e
public class AddStoryActivity extends AppCompatActivity

private Uri mImageUri;

String myUrl = "";

private StorageTask storageTask;

StorageReference storageReference;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_add_story);

storageReference = FirebaseStorage.getInstance().getReference("Story");

CropImage.activity()

.setAspectRatio(9, 16)

.start(AddStoryActivity.this);

private String getFileExtension(Uri uri)

66 | P a g e
ContentResolver contentResolver = getContentResolver();

MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();

return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));

private void publishStory()

final ProgressDialog progressDialog = new ProgressDialog(this);

progressDialog.setMessage("Posting");

progressDialog.show();

if (mImageUri != null)

final StorageReference imageReference = storageReference.child(System.currentTimeMillis() + "."


+ getFileExtension(mImageUri));

storageTask = imageReference.putFile(mImageUri);

storageTask.continueWithTask(new Continuation()

@Override

public Task<Uri> then(@NonNull Task task) throws Exception

if (!task.isSuccessful())

throw task.getException();

67 | P a g e
return imageReference.getDownloadUrl();

}).addOnCompleteListener(new OnCompleteListener<Uri>()

@Override

public void onComplete(@NonNull Task<Uri> task)

if (task.isSuccessful())

Uri downloadUri = task.getResult();

myUrl = downloadUri.toString();

String myId = FirebaseAuth.getInstance().getCurrentUser().getUid();

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

String storyId = reference.push().getKey();

long timeEnd = System.currentTimeMillis() + 86400000; // 86400000 1 day in


milliseconds

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

hashMap.put("imageURL", myUrl);

hashMap.put("timeStart", ServerValue.TIMESTAMP);

hashMap.put("timeEnd", timeEnd);

hashMap.put("storyId", storyId);

68 | P a g e
hashMap.put("userId", myId);

reference.child(storyId).setValue(hashMap);

progressDialog.dismiss();

finish();

else

Toast.makeText(AddStoryActivity.this, "Failed", Toast.LENGTH_SHORT).show();

});

else

Toast.makeText(this, "No image selected", Toast.LENGTH_SHORT).show();

@Override

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

super.onActivityResult(requestCode, resultCode, data);

69 | P a g e
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode ==
RESULT_OK)

CropImage.ActivityResult result = CropImage.getActivityResult(data);

mImageUri = result.getUri();

publishStory();

else

Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show();

startActivity(new Intent(AddStoryActivity.this, MainActivity.class));

70 | P a g e
Java code for adding comments

package com.example.soacial media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.widget.Toolbar;

import androidx.recyclerview.widget.LinearLayoutManager;

import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

import com.bumptech.glide.Glide;

import com.example.instagramclone.Adapter.CommentAdapter;

import com.example.instagramclone.Model.Comment;

import com.example.instagramclone.Model.User;

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;

71 | P a g e
import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Objects;

public class CommentsActivity extends AppCompatActivity

private RecyclerView recyclerView;

private CommentAdapter commentAdapter;

private List<Comment> commentList;

EditText addComment;

ImageView imageProfile;

TextView post;

String postId;

String publisherId;

FirebaseUser firebaseUser;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_comments);

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

setSupportActionBar(toolbar);

Objects.requireNonNull(getSupportActionBar()).setTitle("Comments");

72 | P a g e
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

toolbar.setNavigationOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

finish();

});

Intent intent = getIntent();

postId = intent.getStringExtra("postId");

publisherId = intent.getStringExtra("publisherId");

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

recyclerView = findViewById(R.id.recycler_view);

recyclerView.setHasFixedSize(true);

recyclerView.setLayoutManager(linearLayoutManager);

commentList = new ArrayList<>();

commentAdapter = new CommentAdapter(this, commentList, postId);

73 | P a g e
recyclerView.setAdapter(commentAdapter);

addComment = findViewById(R.id.add_comment);

imageProfile = findViewById(R.id.image_profile);

post = findViewById(R.id.post);

firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

// When user clicks on POST after typing a comment

post.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

if (addComment.getText().toString().equals(""))

Toast.makeText(CommentsActivity.this, "You can't send an empty comment",


Toast.LENGTH_SHORT);

else

addComment();

});

getImage();

readComments();

74 | P a g e
}

private void addComment() // adds comment to firebase database

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

// from database, go to or create "Comments" section if not already created.

// create entry for postId for the photo that was commented on.

String commentId = reference.push().getKey();

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

hashMap.put("comment", addComment.getText().toString()); // get text from addComment


EditText field

hashMap.put("publisher", firebaseUser.getUid()); // get the current user id for the account


who made the comment

hashMap.put("commentId", commentId);

reference.child(commentId).setValue(hashMap); // push info into database for that


postId. postId -> hashMap value

addComment.setText("");

addNotification();

public void addNotification()

75 | P a g e
{

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

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

hashMap.put("userId", firebaseUser.getUid());

hashMap.put("text", "commented: " + addComment.getText().toString());

hashMap.put("postId", postId);

hashMap.put("isPost", true);

reference.push().setValue(hashMap);

// updates the database with values inside the hashMap

private void getImage()

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

// from database, gets the user Id for the current user.

reference.addValueEventListener(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

76 | P a g e
{

// DataSnapShot instance contains data from a Firebase Database location. Anytime you read
Database data, you receive the data as a DataSnapShot.

// They are efficiently generated immutable copies of the data at a Firebase Database location.

// They can't be modified and will never change.

// To modify data at a location, use DatabaseReference reference with setValue(Object) etc...

User user = dataSnapshot.getValue(User.class);

// User - from Model Package

Glide.with(getApplicationContext()).load(user.getImageURL()).into(imageProfile);

// retrieves user profile image and adds it into image_profile section for xml file.

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

private void readComments()

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

77 | P a g e
reference.addValueEventListener(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

commentList.clear();

for (DataSnapshot snapshot : dataSnapshot.getChildren())

Comment comment = snapshot.getValue(Comment.class);

// retrieves the values from Database and converts it into Comment class since the
variables for the class and the keys in database match

// variables for Comment: comment and publisher

// keys in database: comment and publisher

commentList.add(comment);

commentAdapter.notifyDataSetChanged();

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

78 | P a g e
Java code for adding profile

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;

import android.content.ContentResolver;

import android.content.Intent;

import android.net.Uri;

import android.os.Build;

import android.os.Bundle;

import android.view.View;

import android.webkit.MimeTypeMap;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

import com.bumptech.glide.Glide;

import com.example.instagramclone.Model.User;

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.Task;

import com.google.firebase.auth.FirebaseAuth;

import com.google.firebase.auth.FirebaseUser;

import com.google.firebase.database.DataSnapshot;

import com.google.firebase.database.DatabaseError;

79 | P a g e
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.rengwuxian.materialedittext.MaterialEditText;

import com.theartofdev.edmodo.cropper.CropImage;

import com.theartofdev.edmodo.cropper.CropImageView;

import java.util.HashMap;

public class EditProfileActivity extends AppCompatActivity

ImageView close;

ImageView image_profile;

TextView save;

TextView textViewChange;

MaterialEditText fullName;

MaterialEditText username;

MaterialEditText bio;

FirebaseUser firebaseUser;

private Uri mImageUri;

private StorageTask uploadTask;

private StorageReference storageReference;

@Override

protected void onCreate(Bundle savedInstanceState)

80 | P a g e
{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_edit_profile);

close = findViewById(R.id.close);

image_profile = findViewById(R.id.image_profile);

save = findViewById(R.id.save);

textViewChange = findViewById(R.id.textView_change);

fullName = findViewById(R.id.fullName);

username = findViewById(R.id.username);

bio = findViewById(R.id.bio);

firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

storageReference = FirebaseStorage.getInstance().getReference("uploads");

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

// when user inputs value to edit profile

reference.addValueEventListener(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

81 | P a g e
User user = dataSnapshot.getValue(User.class);

fullName.setText(user.getFullName());

username.setText(user.getUserName());

bio.setText(user.getBio());

Glide.with(getApplicationContext()).load(user.getImageURL()).into(image_profile);

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

// when user clicks close button

close.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

finish();

});

7.

// when user clicks on "change profile photo"

textViewChange.setOnClickListener(new View.OnClickListener()

82 | P a g e
@Override

public void onClick(View v)

CropImage.activity()

.setAspectRatio(1,1)

.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ?


CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)

.start(EditProfileActivity.this);

});

// when user clicks on the profile image photo

image_profile.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

CropImage.activity()

.setAspectRatio(1,1)

.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ?


CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)

.start(EditProfileActivity.this);

});

save.setOnClickListener(new View.OnClickListener()

@Override

83 | P a g e
public void onClick(View v)

updateProfile(fullName.getText().toString(), username.getText().toString(),
bio.getText().toString());

});

private void updateProfile(String fullName, String username, String bio)

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

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

hashMap.put("fullName", fullName);

hashMap.put("username", username);

hashMap.put("bio", bio);

reference.updateChildren(hashMap);

private String getFileExtension(Uri uri)

84 | P a g e
ContentResolver contentResolver = getContentResolver();

MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();

return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));

private void uploadImage()

final ProgressDialog progressDialog = new ProgressDialog(this);

progressDialog.setMessage("Uploading");

progressDialog.show();

if (mImageUri != null)

final StorageReference fileReference = storageReference.child(System.currentTimeMillis() + "." +


getFileExtension(mImageUri));

uploadTask = fileReference.putFile(mImageUri);

uploadTask.continueWithTask(new Continuation()

@Override

public Object then(@NonNull Task task) throws Exception

if (! task.isSuccessful())

throw task.getException();

85 | P a g e
}

return fileReference.getDownloadUrl();

}).addOnCompleteListener(new OnCompleteListener<Uri>()

@Override

public void onComplete(@NonNull Task<Uri> task)

if (task.isSuccessful())

Uri downloadUri = task.getResult();

String myUrl = downloadUri.toString();

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

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

hashMap.put("imageURL", "" + myUrl);

reference.updateChildren(hashMap);

progressDialog.dismiss();

else

Toast.makeText(EditProfileActivity.this, "Failed", Toast.LENGTH_SHORT).show();

86 | P a g e
}

}).addOnFailureListener(new OnFailureListener()

@Override

public void onFailure(@NonNull Exception e)

Toast.makeText(EditProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();

});

else

Toast.makeText(this, "No images selected", Toast.LENGTH_SHORT).show();

// ctr + o to get onActivityResult function

@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)

CropImage.ActivityResult result = CropImage.getActivityResult(data);

mImageUri = result.get

87 | P a g e
Java code for adding profile

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;

import android.content.ContentResolver;

import android.content.Intent;

import android.net.Uri;

import android.os.Build;

import android.os.Bundle;

import android.view.View;

import android.webkit.MimeTypeMap;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

import com.bumptech.glide.Glide;

import com.example.instagramclone.Model.User;

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.Task;

import com.google.firebase.auth.FirebaseAuth;

import com.google.firebase.auth.FirebaseUser;

import com.google.firebase.database.DataSnapshot;

88 | P a g e
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.rengwuxian.materialedittext.MaterialEditText;

import com.theartofdev.edmodo.cropper.CropImage;

import com.theartofdev.edmodo.cropper.CropImageView;

import java.util.HashMap;

public class EditProfileActivity extends AppCompatActivity

ImageView close;

ImageView image_profile;

TextView save;

TextView textViewChange;

MaterialEditText fullName;

MaterialEditText username;

MaterialEditText bio;

FirebaseUser firebaseUser;

private Uri mImageUri;

private StorageTask uploadTask;

private StorageReference storageReference;

89 | P a g e
@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_edit_profile);

close = findViewById(R.id.close);

image_profile = findViewById(R.id.image_profile);

save = findViewById(R.id.save);

textViewChange = findViewById(R.id.textView_change);

fullName = findViewById(R.id.fullName);

username = findViewById(R.id.username);

bio = findViewById(R.id.bio);

firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

storageReference = FirebaseStorage.getInstance().getReference("uploads");

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

// when user inputs value to edit profile

reference.addValueEventListener(new ValueEventListener()

90 | P a g e
{

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

User user = dataSnapshot.getValue(User.class);

fullName.setText(user.getFullName());

username.setText(user.getUserName());

bio.setText(user.getBio());

Glide.with(getApplicationContext()).load(user.getImageURL()).into(image_profile);

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

// when user clicks close button

close.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

finish();

});

91 | P a g e
// when user clicks on "change profile photo"

textViewChange.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

CropImage.activity()

.setAspectRatio(1,1)

.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ?


CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)

.start(EditProfileActivity.this);

});

// when user clicks on the profile image photo

image_profile.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

CropImage.activity()

.setAspectRatio(1,1)

.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ?


CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)

.start(EditProfileActivity.this);

92 | P a g e
});

save.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

updateProfile(fullName.getText().toString(), username.getText().toString(),
bio.getText().toString());

});

private void updateProfile(String fullName, String username, String bio)

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

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

hashMap.put("fullName", fullName);

hashMap.put("username", username);

hashMap.put("bio", bio);

93 | P a g e
reference.updateChildren(hashMap);

private String getFileExtension(Uri uri)

ContentResolver contentResolver = getContentResolver();

MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();

return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));

private void uploadImage()

final ProgressDialog progressDialog = new ProgressDialog(this);

progressDialog.setMessage("Uploading");

progressDialog.show();

if (mImageUri != null)

final StorageReference fileReference = storageReference.child(System.currentTimeMillis() + "." +


getFileExtension(mImageUri));

uploadTask = fileReference.putFile(mImageUri);

uploadTask.continueWithTask(new Continuation()

94 | P a g e
{

@Override

public Object then(@NonNull Task task) throws Exception

if (! task.isSuccessful())

throw task.getException();

return fileReference.getDownloadUrl();

}).addOnCompleteListener(new OnCompleteListener<Uri>()

@Override

public void onComplete(@NonNull Task<Uri> task)

if (task.isSuccessful())

Uri downloadUri = task.getResult();

String myUrl = downloadUri.toString();

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

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

95 | P a g e
else

Toast.makeText(EditProfileActivity.this, "Failed", Toast.LENGTH_SHORT).show();

}).addOnFailureListener(new OnFailureListener()

@Override

public void onFailure(@NonNull Exception e)

Toast.makeText(EditProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();

});

else

Toast.makeText(this, "No images selected", Toast.LENGTH_SHORT).show();

// ctr + o to get onActivityResult function

@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)

96 | P a g e
Java code for followers

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.widget.Toolbar;

import androidx.recyclerview.widget.LinearLayoutManager;

import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;

import android.os.Bundle;

import android.renderscript.Sampler;

import android.view.View;

import com.example.instagramclone.Adapter.UserAdapter;

import com.example.instagramclone.Model.User;

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 java.lang.reflect.Array;

import java.util.ArrayList;

import java.util.List;

public class FollowersActivity extends AppCompatActivity

String id;

String title;

97 | P a g e
List<String> idList;

RecyclerView recyclerView;

UserAdapter userAdapter;

List<User> userList;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_followers);

Intent intent = getIntent();

id = intent.getStringExtra("id");

title = intent.getStringExtra("title");

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

setSupportActionBar(toolbar);

getSupportActionBar().setTitle(title);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

toolbar.setNavigationOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

98 | P a g e
{

finish();

});

recyclerView = findViewById(R.id.recycler_view);

recyclerView.setHasFixedSize(true);

recyclerView.setLayoutManager(new LinearLayoutManager(this));

userList = new ArrayList<>();

userAdapter = new UserAdapter(this, userList, false);

recyclerView.setAdapter(userAdapter);

idList = new ArrayList<>();

switch(title)

case "Likes":

getLikes();

break;

case "Following":

getFollowing();

break;

case "Followers":

99 | P a g e
getFollowers();

break;

case "Views":

getViews();

break;

private void getViews()

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Story").child(id).child(getIntent().getStringExtra("storyId"
)).child("Views");

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

idList.clear();

for (DataSnapshot snapshot: dataSnapshot.getChildren())

idList.add(snapshot.getKey());

100 | P a g e
showUsers();

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

private void getLikes()

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

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

idList.clear();

for (DataSnapshot snapshot: dataSnapshot.getChildren())

idList.add(snapshot.getKey());

showUsers();

101 | P a g e
@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

private void getFollowing()

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Follow").child(id).child("Following");

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

idList.clear();

for (DataSnapshot snapshot: dataSnapshot.getChildren())

idList.add(snapshot.getKey());

showUsers();

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

102 | P a g e
{

});

private void getFollowers()

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Follow").child(id).child("Followers");

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

idList.clear();

for (DataSnapshot snapshot: dataSnapshot.getChildren())

idList.add(snapshot.getKey());

showUsers();

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

103 | P a g e
}

private void showUsers()

DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users");

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

userList.clear();

for (DataSnapshot snapshot: dataSnapshot.getChildren())

User user = snapshot.getValue(User.class);

for (String id: idList)

if (user.getId().equals(id))

userList.add(user);

userAdapter.notifyDataSetChanged();

104 | P a g e
@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

Java code for login

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.Bundle;

import android.text.TextUtils;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

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.google.firebase.database.DataSnapshot;

import com.google.firebase.database.DatabaseError;

105 | P a g e
import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import com.google.firebase.database.ValueEventListener;

import org.w3c.dom.Text;

public class LoginActivity extends AppCompatActivity

EditText email;

EditText password;

Button login;

TextView textSignUp;

FirebaseAuth auth;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_login);

email = findViewById(R.id.email);

password = findViewById(R.id.password);

login = findViewById(R.id.login);

textSignUp = findViewById(R.id.textSignUp);

auth = FirebaseAuth.getInstance();

106 | P a g e
textSignUp.setOnClickListener(new View.OnClickListener() // when user clicks on "Don't have
an account? Sign Up" TextView.

@Override

public void onClick(View v)

startActivity(new Intent(LoginActivity.this, RegisterActivity.class));

});

login.setOnClickListener(new View.OnClickListener() // when user clicks on login button

@Override

public void onClick(View v)

final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);

progressDialog.setMessage("Please wait...");

progressDialog.show();

String emailAsString = email.getText().toString();

String passwordAsString = password.getText().toString();

if (TextUtils.isEmpty(emailAsString) || TextUtils.isEmpty(passwordAsString))

Toast.makeText(LoginActivity.this, "All fields are required!", Toast.LENGTH_SHORT).show();

else

107 | P a g e
{

// sign into account using firebase authorization

auth.signInWithEmailAndPassword(emailAsString,
passwordAsString).addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>()

@Override

public void onComplete(@NonNull Task<AuthResult> task)

if (task.isSuccessful())

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference().child("Users").child(auth.getCurrentUser().getUid());

reference.addValueEventListener(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

progressDialog.dismiss();

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

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

startActivity(intent);

finish();

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

108 | P a g e
{

});

else

progressDialog.dismiss();

Toast.makeText(LoginActivity.this, "Authentication failed",


Toast.LENGTH_SHORT).show();

});

});

109 | P a g e
Java code for main activity

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import androidx.fragment.app.Fragment;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Bundle;

import android.view.MenuItem;

import com.example.instagramclone.Fragment.HomeFragment;

import com.example.instagramclone.Fragment.NotificationFragment;

import com.example.instagramclone.Fragment.ProfileFragment;

import com.example.instagramclone.Fragment.SearchFragment;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity

BottomNavigationView bottomNavigationView;

Fragment selectedFragment = null;

// Bottom navigation view

// Home, Search, add photos, likes, profile

110 | P a g e
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener =
new BottomNavigationView.OnNavigationItemSelectedListener()

@Override

public boolean onNavigationItemSelected(@NonNull MenuItem menuItem)

switch (menuItem.getItemId())

case R.id.nav_home:

selectedFragment = new HomeFragment();

break;

case R.id.nav_search:

selectedFragment = new SearchFragment();

break;

case R.id.nav_add:

selectedFragment = null;

startActivity(new Intent(MainActivity.this, PostActivity.class));

break;

case R.id.nav_heart:

selectedFragment = new NotificationFragment();

break;

case R.id.nav_profile:

SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();

editor.putString("profileid", FirebaseAuth.getInstance().getCurrentUser().getUid());

editor.apply();

selectedFragment = new ProfileFragment();

111 | P a g e
break;

if (selectedFragment != null)

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
selectedFragment).commit();

return true;

};

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

bottomNavigationView = findViewById(R.id.bottom_navigation);

bottomNavigationView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);

Bundle intent = getIntent().getExtras();

112 | P a g e
// Intent describes the activity to be executed.

// An Intent can also contain data, described as a Bundle.

// The Bundle object is used to pas data between activities.

// This data can be retrieved from the Intent through getExtras().

if (intent != null)

String publisher = intent.getString("publisherid");

SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();

editor.putString("profileid", publisher);

editor.apply();

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new
ProfileFragment()).commit();

else

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new
HomeFragment()).commit();

113 | P a g e
Java code for options

package com.example.social media app;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.widget.Toolbar;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;

import com.google.firebase.database.FirebaseDatabase;

import org.w3c.dom.Text;

public class OptionsActivity extends AppCompatActivity

TextView logout;

TextView settings;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_options);

114 | P a g e
logout = findViewById(R.id.logout);

settings = findViewById(R.id.settings);

// back button to go back to previous screen

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

setSupportActionBar(toolbar);

getSupportActionBar().setTitle("Options");

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

toolbar.setNavigationOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

finish();

});

// when user clicks log out

logout.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)

FirebaseAuth.getInstance().signOut();

startActivity(new Intent(OptionsActivity.this,
StartActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

});

115 | P a g e
Java code for posts

package com.example.social media app;

import android.app.ProgressDialog;

import android.content.ContentResolver;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

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.Task;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import com.google.android.material.snackbar.Snackbar;

import com.google.firebase.auth.FirebaseAuth;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import com.google.firebase.storage.FirebaseStorage;

import com.google.firebase.storage.StorageReference;

import com.google.firebase.storage.StorageTask;

import com.theartofdev.edmodo.cropper.CropImage;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.widget.Toolbar;

116 | P a g e
import android.view.View;

import android.webkit.MimeTypeMap;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

import java.util.HashMap;

public class PostActivity extends AppCompatActivity

Uri imageUri;

String myUrl = "";

StorageTask uploadTask;

StorageReference storageReference;

ImageView close;

ImageView image_added;

TextView post;

EditText description;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_post);

117 | P a g e
close = findViewById(R.id.close);

image_added = findViewById(R.id.image_added);

post = findViewById(R.id.post);

description = findViewById(R.id.description);

storageReference = FirebaseStorage.getInstance().getReference("Posts");

close.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

startActivity(new Intent(PostActivity.this, MainActivity.class));

finish();

});

post.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

uploadImage();

});

118 | P a g e
// from image cropper library

CropImage.activity()

.setAspectRatio(1,1)

.start(PostActivity.this);

private String getFileExtension(Uri uri)

ContentResolver contentResolver = getContentResolver();

MimeTypeMap mime = MimeTypeMap.getSingleton();

return mime.getExtensionFromMimeType(contentResolver.getType(uri));

private void uploadImage()

final ProgressDialog progressDialog = new ProgressDialog(this);

progressDialog.setMessage("Posting");

progressDialog.show();

if (imageUri != null)

119 | P a g e
final StorageReference fileReference = storageReference.child(System.currentTimeMillis() + "." +
getFileExtension(imageUri));

uploadTask = fileReference.putFile(imageUri);

uploadTask.continueWithTask(new Continuation()

@Override

public Object then(@NonNull Task task) throws Exception

if (! task.isSuccessful())

throw task.getException();

return fileReference.getDownloadUrl();

}).addOnCompleteListener(new OnCompleteListener<Uri>()

@Override

public void onComplete(@NonNull Task<Uri> task)

if (task.isSuccessful())

Uri downloadUri = task.getResult();

120 | P a g e
myUrl = downloadUri.toString();

DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Posts");

String postId = reference.push().getKey();

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

hashMap.put("postId", postId);

hashMap.put("postImage", myUrl);

hashMap.put("description", description.getText().toString());

hashMap.put("publisher", FirebaseAuth.getInstance().getCurrentUser().getUid());

reference.child(postId).setValue(hashMap);

progressDialog.dismiss();

startActivity(new Intent(PostActivity.this, MainActivity.class));

finish();

else

Toast.makeText(PostActivity.this, "Upload Failed", Toast.LENGTH_SHORT).show();

121 | P a g e
}).addOnFailureListener(new OnFailureListener()

@Override

public void onFailure(@NonNull Exception e)

Toast.makeText(PostActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();

});

else

Toast.makeText(PostActivity.this, "No Image Selected", Toast.LENGTH_SHORT).show();

// ctrl + O to find override functions

@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)

CropImage.ActivityResult result = CropImage.getActivityResult(data);

imageUri = result.getUri();

122 | P a g e
image_added.setImageURI(imageUri);

else

Toast.makeText(this, "Something went wrong!", Toast.LENGTH_SHORT).show();

startActivity(new Intent(PostActivity.this, MainActivity.class));

finish();

123 | P a g e
Java code for posts

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

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.ProgressBar;

import android.widget.TextView;

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.google.firebase.auth.FirebaseUser;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import org.w3c.dom.Text;

import java.util.HashMap;

124 | P a g e
public class RegisterActivity extends AppCompatActivity

EditText userName;

EditText fullName;

EditText email;

EditText password;

Button register;

TextView textLogin;

FirebaseAuth auth;

DatabaseReference reference;

ProgressDialog progressDialog;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_register);

// connect variables with UI nodes

userName = findViewById(R.id.username);

fullName = findViewById(R.id.fullName);

email = findViewById(R.id.email);

password = findViewById(R.id.password);

register = findViewById(R.id.register);

textLogin = findViewById(R.id.textLogin);

auth = FirebaseAuth.getInstance();

125 | P a g e
textLogin.setOnClickListener(new View.OnClickListener() // When user clicks on the "Already have
an Account? login" TextView

@Override

public void onClick(View view)

startActivity(new Intent(RegisterActivity.this, LoginActivity.class));

});

register.setOnClickListener(new View.OnClickListener() // When user clicks on the "register"


button after filling out the info.

@Override

public void onClick(View v)

progressDialog = new ProgressDialog(RegisterActivity.this);

progressDialog.setMessage("Please Wait...");

progressDialog.show();

String usernameAsString = userName.getText().toString();

String fullNameAsString = fullName.getText().toString();

String emailAsString = email.getText().toString();

String passwordAsString = password.getText().toString();

if (TextUtils.isEmpty(usernameAsString) || TextUtils.isEmpty(fullNameAsString) ||
TextUtils.isEmpty(emailAsString) || TextUtils.isEmpty(passwordAsString))

126 | P a g e
{

Toast.makeText(RegisterActivity.this, "All fields are required!",


Toast.LENGTH_SHORT).show();

else if (passwordAsString.length() < 6)

Toast.makeText(RegisterActivity.this, "Password must be at least 6 characters long",


Toast.LENGTH_SHORT).show();

else

register(usernameAsString, fullNameAsString, emailAsString, passwordAsString);

});

private void register(final String username, final String fullName, String email, String password)

auth.createUserWithEmailAndPassword(email,
password).addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>()

@Override

public void onComplete(@NonNull Task<AuthResult> task)

if (task.isSuccessful())

// registration of user is successful

FirebaseUser firebaseUser = auth.getCurrentUser();

String userId = firebaseUser.getUid();

127 | P a g e
reference = FirebaseDatabase.getInstance().getReference().child("Users").child(userId);

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

hashMap.put("id", userId);

hashMap.put("username", username.toLowerCase());

hashMap.put("fullName", fullName);

hashMap.put("bio", "");

hashMap.put("imageURL", "https://firebasestorage.googleapis.com/v0/b/instagram-
clone-ea6ff.appspot.com/o/placeholder.png?alt=media&token=68bc014d-29e3-49fa-96db-
eb9c642cf034");

// add the newly created user account to Firebase database

reference.setValue(hashMap).addOnCompleteListener(new
OnCompleteListener<Void>()

@Override

public void onComplete(@NonNull Task<Void> task)

if (task.isSuccessful())

progressDialog.dismiss();

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

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

startActivity(intent);

// operator ( | ) is the "bitwise OR"

// the output of bitwise OR on two bits is 1 if either bit is 1, or 0 if both bits are 0.

128 | P a g e
// Intent

// - messaging object used to request an action from another app component

// - facilitates communication between different components

// 1) Explicit Intent - 2 activities inside the same application setClass(Context,


Class) which provides the exact class to be run.

// 2) Implicit Intent - 2 activities of different application

// Using Intent Flags

// - When starting an activity, you can modify the default association of an


activity to its task by including flags in the intent that you deliver to startActivity()

// Task

// - collection of activities that users interact with when performing a certain


job.

// - The activities are arranged in a stack (back stack) in the order in which each
activity is opened.

// - if user presses the back button, the activity that was just added us now
finished and popped off the stack.

});

else

progressDialog.dismiss();

Toast.makeText(RegisterActivity.this, "You can't register with this email or password",


Toast.LENGTH_SHORT).show();

129 | P a g e
Java code for register

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

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.ProgressBar;

import android.widget.TextView;

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.google.firebase.auth.FirebaseUser;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import org.w3c.dom.Text;

import java.util.HashMap;

130 | P a g e
public class RegisterActivity extends AppCompatActivity

EditText userName;

EditText fullName;

EditText email;

EditText password;

Button register;

TextView textLogin;

FirebaseAuth auth;

DatabaseReference reference;

ProgressDialog progressDialog;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_register);

// connect variables with UI nodes

userName = findViewById(R.id.username);

fullName = findViewById(R.id.fullName);

email = findViewById(R.id.email);

password = findViewById(R.id.password);

register = findViewById(R.id.register);

textLogin = findViewById(R.id.textLogin);

auth = FirebaseAuth.getInstance();

131 | P a g e
textLogin.setOnClickListener(new View.OnClickListener() // When user clicks on the "Already have
an Account? login" TextView

@Override

public void onClick(View view)

startActivity(new Intent(RegisterActivity.this, LoginActivity.class));

});

register.setOnClickListener(new View.OnClickListener() // When user clicks on the "register"


button after filling out the info.

@Override

public void onClick(View v)

progressDialog = new ProgressDialog(RegisterActivity.this);

progressDialog.setMessage("Please Wait...");

progressDialog.show();

String usernameAsString = userName.getText().toString();

String fullNameAsString = fullName.getText().toString();

String emailAsString = email.getText().toString();

String passwordAsString = password.getText().toString();

if (TextUtils.isEmpty(usernameAsString) || TextUtils.isEmpty(fullNameAsString) ||
TextUtils.isEmpty(emailAsString) || TextUtils.isEmpty(passwordAsString))

132 | P a g e
Toast.makeText(RegisterActivity.this, "All fields are required!",
Toast.LENGTH_SHORT).show();

else if (passwordAsString.length() < 6)

Toast.makeText(RegisterActivity.this, "Password must be at least 6 characters long",


Toast.LENGTH_SHORT).show();

else

register(usernameAsString, fullNameAsString, emailAsString, passwordAsString);

});

private void register(final String username, final String fullName, String email, String password)

auth.createUserWithEmailAndPassword(email,
password).addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>()

@Override

public void onComplete(@NonNull Task<AuthResult> task)

if (task.isSuccessful())

// registration of user is successful

FirebaseUser firebaseUser = auth.getCurrentUser();

String userId = firebaseUser.getUid();

reference = FirebaseDatabase.getInstance().getReference().child("Users").child(userId);

133 | P a g e
HashMap<String, Object> hashMap = new HashMap<>();

hashMap.put("id", userId);

hashMap.put("username", username.toLowerCase());

hashMap.put("fullName", fullName);

hashMap.put("bio", "");

hashMap.put("imageURL", "https://firebasestorage.googleapis.com/v0/b/instagram-
clone-ea6ff.appspot.com/o/placeholder.png?alt=media&token=68bc014d-29e3-49fa-96db-
eb9c642cf034");

// add the newly created user account to Firebase database

reference.setValue(hashMap).addOnCompleteListener(new
OnCompleteListener<Void>()

@Override

public void onComplete(@NonNull Task<Void> task)

if (task.isSuccessful())

progressDialog.dismiss();

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

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

startActivity(intent);

// operator ( | ) is the "bitwise OR"

// the output of bitwise OR on two bits is 1 if either bit is 1, or 0 if both bits are 0.

134 | P a g e
// Intent

// - messaging object used to request an action from another app component

// - facilitates communication between different components

// 1) Explicit Intent - 2 activities inside the same application setClass(Context,


Class) which provides the exact class to be run.

// 2) Implicit Intent - 2 activities of different application

// Using Intent Flags

// - When starting an activity, you can modify the default association of an


activity to its task by including flags in the intent that you deliver to startActivity()

// Task

// - collection of activities that users interact with when performing a certain


job.

// - The activities are arranged in a stack (back stack) in the order in which each
activity is opened.

// - if user presses the back button, the activity that was just added us now
finished and popped off the stack.

});

else

progressDialog.dismiss();

Toast.makeText(RegisterActivity.this, "You can't register with this email or password",


Toast.LENGTH_SHORT).show();

135 | P a g e
Java code for start

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

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.ProgressBar;

import android.widget.TextView;

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.google.firebase.auth.FirebaseUser;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import org.w3c.dom.Text;

import java.util.HashMap;

136 | P a g e
public class RegisterActivity extends AppCompatActivity

EditText userName;

EditText fullName;

EditText email;

EditText password;

Button register;

TextView textLogin;

FirebaseAuth auth;

DatabaseReference reference;

ProgressDialog progressDialog;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_register);

// connect variables with UI nodes

userName = findViewById(R.id.username);

fullName = findViewById(R.id.fullName);

email = findViewById(R.id.email);

password = findViewById(R.id.password);

register = findViewById(R.id.register);

textLogin = findViewById(R.id.textLogin);

auth = FirebaseAuth.getInstance();

137 | P a g e
textLogin.setOnClickListener(new View.OnClickListener() // When user clicks on the "Already have
an Account? login" TextView

@Override

public void onClick(View view)

startActivity(new Intent(RegisterActivity.this, LoginActivity.class));

});

register.setOnClickListener(new View.OnClickListener() // When user clicks on the "register"


button after filling out the info.

@Override

public void onClick(View v)

progressDialog = new ProgressDialog(RegisterActivity.this);

progressDialog.setMessage("Please Wait...");

progressDialog.show();

String usernameAsString = userName.getText().toString();

String fullNameAsString = fullName.getText().toString();

String emailAsString = email.getText().toString();

String passwordAsString = password.getText().toString();

if (TextUtils.isEmpty(usernameAsString) || TextUtils.isEmpty(fullNameAsString) ||
TextUtils.isEmpty(emailAsString) || TextUtils.isEmpty(passwordAsString))

138 | P a g e
{

Toast.makeText(RegisterActivity.this, "All fields are required!",


Toast.LENGTH_SHORT).show();

else if (passwordAsString.length() < 6)

Toast.makeText(RegisterActivity.this, "Password must be at least 6 characters long",


Toast.LENGTH_SHORT).show();

else

register(usernameAsString, fullNameAsString, emailAsString, passwordAsString);

});

private void register(final String username, final String fullName, String email, String password)

auth.createUserWithEmailAndPassword(email,
password).addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>()

@Override

public void onComplete(@NonNull Task<AuthResult> task)

if (task.isSuccessful())

// registration of user is successful

FirebaseUser firebaseUser = auth.getCurrentUser();

String userId = firebaseUser.getUid();

139 | P a g e
reference = FirebaseDatabase.getInstance().getReference().child("Users").child(userId);

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

hashMap.put("id", userId);

hashMap.put("username", username.toLowerCase());

hashMap.put("fullName", fullName);

hashMap.put("bio", "");

hashMap.put("imageURL", "https://firebasestorage.googleapis.com/v0/b/instagram-
clone-ea6ff.appspot.com/o/placeholder.png?alt=media&token=68bc014d-29e3-49fa-96db-
eb9c642cf034");

// add the newly created user account to Firebase database

reference.setValue(hashMap).addOnCompleteListener(new
OnCompleteListener<Void>()

@Override

public void onComplete(@NonNull Task<Void> task)

if (task.isSuccessful())

progressDialog.dismiss();

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

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

startActivity(intent);

// operator ( | ) is the "bitwise OR"

// the output of bitwise OR on two bits is 1 if either bit is 1, or 0 if both bits are 0.

140 | P a g e
// Intent

// - messaging object used to request an action from another app component

// - facilitates communication between different components

// 1) Explicit Intent - 2 activities inside the same application setClass(Context,


Class) which provides the exact class to be run.

// 2) Implicit Intent - 2 activities of different application

// Using Intent Flags

// - When starting an activity, you can modify the default association of an


activity to its task by including flags in the intent that you deliver to startActivity()

// Task

// - collection of activities that users interact with when performing a certain


job.

// - The activities are arranged in a stack (back stack) in the order in which each
activity is opened.

// - if user presses the back button, the activity that was just added us now
finished and popped off the stack.

});

else

progressDialog.dismiss();

Toast.makeText(RegisterActivity.this, "You can't register with this email or password",


Toast.LENGTH_SHORT).show();

141 | P a g e
Java code for story

package com.example.social media app;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.view.MotionEvent;

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.example.instagramclone.Model.Story;

import com.example.instagramclone.Model.User;

import com.google.android.gms.tasks.OnCompleteListener;

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 java.lang.reflect.Array;

142 | P a g e
import java.util.ArrayList;

import java.util.List;

import jp.shts.android.storiesprogressview.StoriesProgressView;

public class StoryActivity extends AppCompatActivity implements StoriesProgressView.StoriesListener

int counter = 0;

long pressTime = 0L;

long limit = 500L;

StoriesProgressView storiesProgressView;

ImageView image;

ImageView storyPhoto;

TextView storyUsername;

List<String> images;

List<String> storyIds;

String userId;

LinearLayout containerSeen;

TextView seenNumber;

ImageView storyDelete;

143 | P a g e
private View.OnTouchListener onTouchListener = new View.OnTouchListener() // swiping up and
down on the screen

@Override

public boolean onTouch(View v, MotionEvent event)

switch (event.getAction())

case MotionEvent.ACTION_DOWN:

pressTime = System.currentTimeMillis();

storiesProgressView.pause();

return false;

case MotionEvent.ACTION_UP:

long now = System.currentTimeMillis();

storiesProgressView.resume();

return limit < now - pressTime;

return false;

};

@Override

protected void onCreate(Bundle savedInstanceState)

144 | P a g e
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_story);

storiesProgressView = findViewById(R.id.stories);

image = findViewById(R.id.image_story);

storyPhoto = findViewById(R.id.story_photo);

storyUsername = findViewById(R.id.story_username);

userId = getIntent().getStringExtra("userId");

containerSeen = findViewById(R.id.container_seen);

seenNumber = findViewById(R.id.seen_number);

storyDelete = findViewById(R.id.story_delete);

containerSeen.setVisibility(View.GONE);

storyDelete.setVisibility(View.GONE);

if (userId.equals(FirebaseAuth.getInstance().getCurrentUser().getUid()))

containerSeen.setVisibility(View.VISIBLE);

storyDelete.setVisibility(View.VISIBLE);

145 | P a g e
getStories(userId);

userInfo(userId);

// reverse - tapping on left side of the screen

View reverse = findViewById(R.id.reverse);

reverse.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

storiesProgressView.reverse();

});

reverse.setOnTouchListener(onTouchListener);

// skip - tapping on the right side of the screen

View skip = findViewById(R.id.skip);

skip.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

storiesProgressView.skip();

146 | P a g e
}

});

skip.setOnTouchListener(onTouchListener);

containerSeen.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

Intent intent = new Intent(StoryActivity.this, FollowersActivity.class);

intent.putExtra("id", userId);

intent.putExtra("storyId", storyIds.get(counter));

intent.putExtra("title", "Views");

startActivity(intent);

});

storyDelete.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Story").child(userId).child(storyIds.get(counter));

reference.removeValue().addOnCompleteListener(new OnCompleteListener<Void>()

147 | P a g e
@Override

public void onComplete(@NonNull Task<Void> task)

Toast.makeText(StoryActivity.this, "Deleted!", Toast.LENGTH_SHORT).show();

finish();

});

});

@Override

public void onNext()

Glide.with(getApplicationContext()).load(images.get(++counter)).into(image);

addView(storyIds.get(counter));

seenNumber(storyIds.get(counter));

@Override

public void onPrev()

if ((counter - 1) < 0)

return;

148 | P a g e
Glide.with(getApplicationContext()).load(images.get(--counter)).into(image);

seenNumber(storyIds.get(counter));

@Override

public void onComplete()

finish();

@Override

protected void onDestroy()

storiesProgressView.destroy();

super.onDestroy();

@Override

protected void onPause()

storiesProgressView.pause();

super.onPause();

149 | P a g e
@Override

protected void onResume()

storiesProgressView.resume();

super.onResume();

private void getStories(String userId)

images = new ArrayList<>();

storyIds = new ArrayList<>();

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

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

images.clear();

storyIds.clear();

for (DataSnapshot snapshot: dataSnapshot.getChildren())

Story story = snapshot.getValue(Story.class);

long timeCurrent = System.currentTimeMillis();

150 | P a g e
if (timeCurrent > story.getTimeStart() && timeCurrent < story.getTimeEnd())

images.add(story.getImageURL());

storyIds.add(story.getStoryId());

storiesProgressView.setStoriesCount(images.size());

storiesProgressView.setStoryDuration(5000L);

storiesProgressView.setStoriesListener(StoryActivity.this);

storiesProgressView.startStories(counter);

Glide.with(getApplicationContext()).load(images.get(counter)).into(image);

addView(storyIds.get(counter));

seenNumber(storyIds.get(counter));

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

private void userInfo(String userId)

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

151 | P a g e
reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

User user = dataSnapshot.getValue(User.class);

Glide.with(getApplicationContext()).load(user.getImageURL()).into(storyPhoto);

storyUsername.setText(user.getUserName());

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

private void addView(String storyId)

FirebaseDatabase.getInstance().getReference("Story").child(userId).child(storyId).child("Views").child(Fir
ebaseAuth.getInstance().getCurrentUser().getUid()).setValue(true);

152 | P a g e
private void seenNumber(String storyId)

DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("Story").child(userId).child(storyId).child("Views");

reference.addListenerForSingleValueEvent(new ValueEventListener()

@Override

public void onDataChange(@NonNull DataSnapshot dataSnapshot)

seenNumber.setText("" + dataSnapshot.getChildrenCount());

@Override

public void onCancelled(@NonNull DatabaseError databaseError)

});

8.

153 | P a g e
Home

154 | P a g e
Profile

155 | P a g e
Story

156 | P a g e
Chat

157 | P a g e
TESTING

Black Box Testing

Black Box Testing, also known as Behavioural Testing, is a software


testing method in which the internal structure/design/implementation
of the item being tested is not known to the tester. These tests can be
functional or non-functional, though usually functional.

Unit Testing

Unit Testing is a level of testing where individual units/components


of the software are tested. The purpose is to validate that each unit of
the software performs as designed. A unit is the smallest testable part
of any software. Is usually has one or a few inputs and usually a
single output.

Integration Testing

Integration testing is a level of software testing where individual units


are combined and tested as a group. The purpose of this level testing
is to expose faults in the interaction between integrated units. Test
drivers and test stubs are used to assist in Integration testing.

158 | P a g e
Limitations

• No backup of data if an account is lost


• Small database
• No video calling
• No live streaming

Future Scopes

• Limit the usage of the app to get rid of over usage of this
or to not get addicted
• Live to stream
• Sharing contacts through NFC (near field communication)
• Dark mode
• Inbuilt music ecosystem

159 | P a g e
CONCLUSION

Social Networking is a nice form of entertainment, great for


meeting people with similar interests, and can be a very effective
business technique for entrepreneurs, writers, actors, musicians, or
artists. This structure includes having profiles, friends, blog posts,
etc., and usually something unique to that particular social
networking.

160 | P a g e
BIBLIOGRAPHY

https://www.android.com/
https://developer.android.com/
https://www.behance.net/
https://dribbble.com/
https://developer.android.com/training/basics/firstapp
https://developer.android.com/studio
https://developer.android.com/guide/components/activities

161 | P a g e

You might also like