├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── add_btn.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── add_btn.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── add_btn.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── add_btn.png
│ │ │ │ ├── empty_user.jpg
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── like_grey.png
│ │ │ │ ├── ic_action_add.png
│ │ │ │ ├── like_orange.png
│ │ │ │ ├── ic_image_logout.png
│ │ │ │ ├── ic_image_proile.png
│ │ │ │ ├── ic_image_search.png
│ │ │ │ └── ic_image_settings.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── like_grey.png
│ │ │ │ ├── ic_action_add.png
│ │ │ │ ├── like_orange.png
│ │ │ │ ├── ic_image_logout.png
│ │ │ │ ├── ic_image_proile.png
│ │ │ │ ├── ic_image_search.png
│ │ │ │ └── ic_image_settings.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── like_grey.png
│ │ │ │ ├── like_orange.png
│ │ │ │ ├── ic_action_add.png
│ │ │ │ ├── ic_image_logout.png
│ │ │ │ ├── ic_image_proile.png
│ │ │ │ ├── ic_image_search.png
│ │ │ │ └── ic_image_settings.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── like_grey.png
│ │ │ │ ├── like_orange.png
│ │ │ │ ├── ic_action_add.png
│ │ │ │ ├── backgroun_image.png
│ │ │ │ ├── fire_image_red.png
│ │ │ │ ├── ic_image_logout.png
│ │ │ │ ├── ic_image_proile.png
│ │ │ │ ├── ic_image_search.png
│ │ │ │ └── ic_image_settings.png
│ │ │ ├── drawable
│ │ │ │ ├── login_btn_style.xml
│ │ │ │ ├── signup_btn_style.xml
│ │ │ │ └── tv_style.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_search_activity.xml
│ │ │ │ ├── menu_main.xml
│ │ │ │ └── navigation_drawer.xml
│ │ │ └── layout
│ │ │ │ ├── activity_search.xml
│ │ │ │ ├── activity_image_view.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── navigation_header.xml
│ │ │ │ ├── single_row_search.xml
│ │ │ │ ├── activity_user_profile.xml
│ │ │ │ ├── activity_another_user_profile.xml
│ │ │ │ ├── activity_post.xml
│ │ │ │ ├── activity_sign_up.xml
│ │ │ │ ├── activity_log_in.xml
│ │ │ │ └── single_row_main.xml
│ │ ├── java
│ │ │ ├── com
│ │ │ │ └── example
│ │ │ │ │ └── anujsharma
│ │ │ │ │ └── firebook
│ │ │ │ │ ├── Firebook.java
│ │ │ │ │ ├── ImageViewActivity.java
│ │ │ │ │ ├── SignUpActivity.java
│ │ │ │ │ ├── SearchActivity.java
│ │ │ │ │ ├── UserProfileActivity.java
│ │ │ │ │ ├── PostActivity.java
│ │ │ │ │ ├── AnotherUserProfileActivity.java
│ │ │ │ │ ├── LogInActivity.java
│ │ │ │ │ └── MainActivity.java
│ │ │ └── dataStructures
│ │ │ │ ├── SearchUser.java
│ │ │ │ └── Feed.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── anujsharma
│ │ │ └── firebook
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── anujsharma
│ │ └── firebook
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── google-services.json
└── build.gradle
├── .idea
└── vcs.xml
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/add_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-mdpi/add_btn.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/add_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xhdpi/add_btn.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/add_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxhdpi/add_btn.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/add_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxxhdpi/add_btn.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/like_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/like_grey.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/like_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/like_grey.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/like_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/like_grey.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/ic_action_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/like_orange.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/like_orange.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/ic_action_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/like_orange.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/like_orange.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/like_orange.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/like_orange.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/like_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/like_grey.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/like_orange.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/like_orange.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/empty_user.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxxhdpi/empty_user.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_image_logout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/ic_image_logout.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_image_proile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/ic_image_proile.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_image_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/ic_image_search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_image_logout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/ic_image_logout.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_image_proile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/ic_image_proile.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_image_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/ic_image_search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/ic_action_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/ic_action_add.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_image_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-hdpi/ic_image_settings.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_image_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-mdpi/ic_image_settings.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_image_logout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/ic_image_logout.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_image_proile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/ic_image_proile.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_image_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/ic_image_search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_image_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xhdpi/ic_image_settings.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/backgroun_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/backgroun_image.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/fire_image_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/fire_image_red.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_image_logout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/ic_image_logout.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_image_proile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/ic_image_proile.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_image_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/ic_image_search.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_image_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anuj-Kumar-Sharma/Firebook/HEAD/app/src/main/res/drawable-xxhdpi/ic_image_settings.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFC107
4 | #FFA000
5 | #FF5722
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_btn_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/signup_btn_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tv_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Firebook
2 | Firebook is a social media app. It uses Firebase as back-end database storage.
3 |
Features
4 | With this app, you can:
5 |
6 | - Login/signup using Google
7 | - Search your friends
8 | - Post your photos
9 | - Like your friend's photos
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Firebook
3 | Settings
4 | UserProfileActivity
5 | Open
6 | Close
7 |
8 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/anujsharma/firebook/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_search_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/Firebook.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.firebase.FirebaseApp;
6 | import com.google.firebase.database.FirebaseDatabase;
7 |
8 | public class Firebook extends Application {
9 |
10 | @Override
11 | public void onCreate() {
12 | super.onCreate();
13 |
14 | if (!FirebaseApp.getApps(this).isEmpty()) {
15 | FirebaseDatabase.getInstance().setPersistenceEnabled(true);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/anujsharma/firebook/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.anujsharma.firebook", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/ImageViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.ImageView;
7 |
8 | import com.bumptech.glide.Glide;
9 |
10 | public class ImageViewActivity extends AppCompatActivity {
11 |
12 | private ImageView ivImage;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_image_view);
18 |
19 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
20 | getSupportActionBar().hide();
21 |
22 | Intent intent = getIntent();
23 | String imageUri = intent.getStringExtra("image_uri");
24 |
25 | ivImage = (ImageView) findViewById(R.id.xivFeedImage);
26 | Glide.with(this)
27 | .load(imageUri)
28 | .into(ivImage);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\ANUJ SHARMA\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/java/dataStructures/SearchUser.java:
--------------------------------------------------------------------------------
1 | package dataStructures;
2 |
3 | public class SearchUser {
4 |
5 | private String email, name, profile_image, u_id;
6 |
7 | public SearchUser() {
8 | }
9 |
10 | public SearchUser(String email, String name, String profile_image, String u_id) {
11 | this.email = email;
12 | this.name = name;
13 | this.profile_image = profile_image;
14 | this.u_id = u_id;
15 | }
16 |
17 | public String getEmail() {
18 | return email;
19 | }
20 |
21 | public void setEmail(String email) {
22 | this.email = email;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 |
33 | public String getProfile_image() {
34 | return profile_image;
35 | }
36 |
37 | public void setProfile_image(String profile_image) {
38 | this.profile_image = profile_image;
39 | }
40 |
41 | public String getU_id() {
42 | return u_id;
43 | }
44 |
45 | public void setU_id(String u_id) {
46 | this.u_id = u_id;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/dataStructures/Feed.java:
--------------------------------------------------------------------------------
1 | package dataStructures;
2 |
3 | public class Feed {
4 |
5 | private String desc, image, title, u_id, date;
6 |
7 | public Feed() {
8 | }
9 |
10 |
11 | public Feed(String desc, String image, String title, String date) {
12 | this.desc = desc;
13 | this.image = image;
14 | this.title = title;
15 | this.date = date;
16 | }
17 |
18 | public String getDesc() {
19 | return desc;
20 | }
21 |
22 | public void setDesc(String desc) {
23 | this.desc = desc;
24 | }
25 |
26 | public String getImage() {
27 | return image;
28 | }
29 |
30 | public void setImage(String image) {
31 | this.image = image;
32 | }
33 |
34 | public String getTitle() {
35 | return title;
36 | }
37 |
38 | public void setTitle(String title) {
39 | this.title = title;
40 | }
41 |
42 | public String getU_id() {
43 | return u_id;
44 | }
45 |
46 | public void setU_id(String u_id) {
47 | this.u_id = u_id;
48 | }
49 |
50 | public String getDate() {
51 | return date;
52 | }
53 |
54 | public void setDate(String date) {
55 | this.date = date;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
20 |
21 |
22 |
23 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "997216257732",
4 | "firebase_url": "https://firebook-65bdd.firebaseio.com",
5 | "project_id": "firebook-65bdd",
6 | "storage_bucket": "firebook-65bdd.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:997216257732:android:c5ff430a6a5ca65b",
12 | "android_client_info": {
13 | "package_name": "com.example.anujsharma.firebook"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "997216257732-i2kqeuodn7ivjoui20vljstmbggi5ulv.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.example.anujsharma.firebook",
22 | "certificate_hash": "71a75327eeccc4a5b9131fc8e041c72f5ea44836"
23 | }
24 | },
25 | {
26 | "client_id": "997216257732-hs7j7chn835gv2mn3kao83rb06gjl87b.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyCIQXIWb22j7HZhdM5gRCFhCP_He-4WIJ0"
33 | }
34 | ],
35 | "services": {
36 | "analytics_service": {
37 | "status": 1
38 | },
39 | "appinvite_service": {
40 | "status": 2,
41 | "other_platform_oauth_client": [
42 | {
43 | "client_id": "997216257732-hs7j7chn835gv2mn3kao83rb06gjl87b.apps.googleusercontent.com",
44 | "client_type": 3
45 | }
46 | ]
47 | },
48 | "ads_service": {
49 | "status": 2
50 | }
51 | }
52 | }
53 | ],
54 | "configuration_version": "1"
55 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/navigation_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
30 |
31 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.example.anujsharma.firebook"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.2.0'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
29 | compile 'com.android.support:design:25.2.0'
30 | compile 'com.android.support:recyclerview-v7:25.1.0'
31 | compile 'com.android.support:cardview-v7:25.1.0'
32 | compile 'de.hdodenhof:circleimageview:2.1.0'
33 | compile 'com.google.firebase:firebase-database:10.2.0'
34 | compile 'com.google.firebase:firebase-crash:10.2.0'
35 | compile 'com.google.firebase:firebase-auth:10.2.0'
36 | compile 'com.google.android.gms:play-services-auth:10.2.0'
37 | compile 'com.google.firebase:firebase-storage:10.2.0'
38 | compile 'com.firebaseui:firebase-ui-database:1.2.0'
39 | compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
40 | compile 'com.github.bumptech.glide:glide:3.7.0'
41 | compile 'com.android.support:support-v4:19.1.0'
42 | testCompile 'junit:junit:4.12'
43 | }
44 | apply plugin: 'com.google.gms.google-services'
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/single_row_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
21 |
22 |
23 |
34 |
35 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
37 |
38 |
39 |
42 |
43 |
44 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_user_profile.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
21 |
22 |
32 |
33 |
47 |
48 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_another_user_profile.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
18 |
19 |
29 |
30 |
40 |
41 |
50 |
51 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_post.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
21 |
22 |
36 |
37 |
52 |
53 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/SignUpActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 |
12 | import com.google.android.gms.tasks.OnCompleteListener;
13 | import com.google.android.gms.tasks.Task;
14 | import com.google.firebase.auth.AuthResult;
15 | import com.google.firebase.auth.FirebaseAuth;
16 | import com.google.firebase.database.DatabaseReference;
17 | import com.google.firebase.database.FirebaseDatabase;
18 |
19 | public class SignUpActivity extends AppCompatActivity {
20 |
21 | private EditText etSignUpName, etSignUpEmail, etSignUpPassword;
22 | private Button bnSignUp;
23 |
24 | private FirebaseAuth mFirebaseAuth;
25 | private DatabaseReference mDatabaseRef;
26 |
27 | private ProgressDialog mProgressDialog;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_sign_up);
33 |
34 | mFirebaseAuth = FirebaseAuth.getInstance();
35 | mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("users");
36 |
37 | mProgressDialog = new ProgressDialog(this);
38 |
39 | etSignUpName = (EditText) findViewById(R.id.xetSignUpName);
40 | etSignUpEmail = (EditText) findViewById(R.id.xetSignUpEmail);
41 | etSignUpPassword = (EditText) findViewById(R.id.xetSignUpPassword);
42 | bnSignUp = (Button) findViewById(R.id.xbnSignUp);
43 |
44 | bnSignUp.setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View v) {
47 | doSignUp();
48 | }
49 | });
50 | }
51 |
52 | private void doSignUp() {
53 | final String name = etSignUpName.getText().toString().trim();
54 | final String email = etSignUpEmail.getText().toString().trim();
55 | String pass = etSignUpPassword.getText().toString().trim();
56 |
57 | if (!name.isEmpty() && !email.isEmpty() && !pass.isEmpty()) {
58 |
59 | mProgressDialog.setMessage("Signing Up...");
60 | mProgressDialog.setCanceledOnTouchOutside(false);
61 | mProgressDialog.show();
62 |
63 | mFirebaseAuth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(new OnCompleteListener() {
64 | @Override
65 | public void onComplete(@NonNull Task task) {
66 | String user_id = mFirebaseAuth.getCurrentUser().getUid();
67 |
68 | DatabaseReference userDbRef = mDatabaseRef.child(user_id);
69 | userDbRef.child("name").setValue(name);
70 | userDbRef.child("email").setValue(email);
71 | userDbRef.child("u_id").setValue(user_id);
72 | mProgressDialog.dismiss();
73 | Intent intent = new Intent(SignUpActivity.this, UserProfileActivity.class);
74 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
75 | startActivity(intent);
76 | finish();
77 | }
78 | });
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sign_up.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
26 |
27 |
43 |
44 |
60 |
61 |
75 |
76 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_log_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
28 |
29 |
45 |
46 |
59 |
60 |
69 |
70 |
82 |
83 |
91 |
92 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/single_row_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
18 |
19 |
27 |
28 |
33 |
34 |
42 |
43 |
44 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
65 |
66 |
72 |
73 |
77 |
78 |
82 |
83 |
93 |
94 |
95 |
105 |
106 |
107 |
108 |
111 |
112 |
124 |
125 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/SearchActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v4.view.MenuItemCompat;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.SearchView;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.widget.TextView;
15 |
16 | import com.bumptech.glide.Glide;
17 | import com.firebase.ui.database.FirebaseRecyclerAdapter;
18 | import com.google.firebase.database.DataSnapshot;
19 | import com.google.firebase.database.DatabaseError;
20 | import com.google.firebase.database.DatabaseReference;
21 | import com.google.firebase.database.FirebaseDatabase;
22 | import com.google.firebase.database.Query;
23 | import com.google.firebase.database.ValueEventListener;
24 |
25 | import dataStructures.SearchUser;
26 | import de.hdodenhof.circleimageview.CircleImageView;
27 |
28 | public class SearchActivity extends AppCompatActivity implements SearchView.OnQueryTextListener {
29 |
30 | FirebaseRecyclerAdapter firebaseRecyclerAdapter;
31 | private DatabaseReference mUsersDbRef;
32 | private Query mQuery;
33 | private RecyclerView rvSearch;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_search);
39 |
40 | rvSearch = (RecyclerView) findViewById(R.id.xrvSearch);
41 |
42 | mUsersDbRef = FirebaseDatabase.getInstance().getReference().child("users");
43 | mQuery = mUsersDbRef.orderByChild("name");
44 |
45 | rvSearch.setLayoutManager(new LinearLayoutManager(this));
46 |
47 | }
48 |
49 | @Override
50 | protected void onStart() {
51 | super.onStart();
52 |
53 | attachRecyclerViewAdapter();
54 | }
55 |
56 | public void attachRecyclerViewAdapter() {
57 | firebaseRecyclerAdapter = new FirebaseRecyclerAdapter(
58 | SearchUser.class,
59 | R.layout.single_row_search,
60 | SearchViewHolder.class,
61 | mQuery
62 |
63 | ) {
64 | @Override
65 | protected void populateViewHolder(SearchViewHolder viewHolder, final SearchUser model, int position) {
66 | viewHolder.setSearchUserName(model.getName());
67 | viewHolder.setSearchUserEmail(model.getEmail());
68 | viewHolder.setSearchUserImage(getApplicationContext(), model.getProfile_image());
69 |
70 | viewHolder.mView.setOnClickListener(new View.OnClickListener() {
71 | @Override
72 | public void onClick(View v) {
73 | Intent intent = new Intent(SearchActivity.this, AnotherUserProfileActivity.class);
74 | intent.putExtra("feed_uid", model.getU_id());
75 | startActivity(intent);
76 | }
77 | });
78 | }
79 | };
80 | rvSearch.setAdapter(firebaseRecyclerAdapter);
81 | }
82 |
83 | @Override
84 | public boolean onQueryTextSubmit(String query) {
85 |
86 | mQuery = mUsersDbRef.orderByChild("name").startAt(query).endAt(query + "~").limitToFirst(5);
87 | mQuery.addValueEventListener(new ValueEventListener() {
88 | @Override
89 | public void onDataChange(DataSnapshot dataSnapshot) {
90 |
91 |
92 | }
93 |
94 | @Override
95 | public void onCancelled(DatabaseError databaseError) {
96 |
97 | }
98 | });
99 |
100 | return false;
101 | }
102 |
103 | @Override
104 | public boolean onQueryTextChange(String newText) {
105 |
106 | mQuery = mUsersDbRef.orderByChild("name").startAt(newText).endAt(newText + "~").limitToFirst(5);
107 | attachRecyclerViewAdapter();
108 |
109 | mQuery.addValueEventListener(new ValueEventListener() {
110 | @Override
111 | public void onDataChange(DataSnapshot dataSnapshot) {
112 | }
113 |
114 | @Override
115 | public void onCancelled(DatabaseError databaseError) {
116 |
117 | }
118 | });
119 |
120 | return false;
121 | }
122 |
123 | @Override
124 | public boolean onCreateOptionsMenu(Menu menu) {
125 |
126 | getMenuInflater().inflate(R.menu.menu_search_activity, menu);
127 | MenuItem searchMenu = menu.findItem(R.id.action_search_activity);
128 | SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenu);
129 | searchView.setIconified(false);
130 | searchView.setIconifiedByDefault(false);
131 | searchView.setQueryHint("Search by name...");
132 |
133 | searchView.setOnQueryTextListener(this);
134 | return super.onCreateOptionsMenu(menu);
135 |
136 | }
137 |
138 | public static class SearchViewHolder extends RecyclerView.ViewHolder {
139 |
140 | View mView;
141 |
142 | public SearchViewHolder(View itemView) {
143 | super(itemView);
144 | mView = itemView;
145 | }
146 |
147 | public void setSearchUserName(String name) {
148 | TextView searchUserName = (TextView) mView.findViewById(R.id.search_userName);
149 | searchUserName.setText(name);
150 | }
151 |
152 | public void setSearchUserEmail(String email) {
153 | TextView searchUserName = (TextView) mView.findViewById(R.id.search_userEmail);
154 | searchUserName.setText(email);
155 | }
156 |
157 | public void setSearchUserImage(Context context, String image) {
158 | CircleImageView searchUserImage = (CircleImageView) mView.findViewById(R.id.search_userImage);
159 | Glide.with(context)
160 | .load(image)
161 | .placeholder(R.mipmap.empty_user)
162 | .crossFade()
163 | .dontAnimate()
164 | .into(searchUserImage);
165 | }
166 | }
167 |
168 |
169 | }
170 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/UserProfileActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.ImageButton;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.bumptech.glide.Glide;
15 | import com.google.android.gms.tasks.OnSuccessListener;
16 | import com.google.firebase.auth.FirebaseAuth;
17 | import com.google.firebase.auth.FirebaseUser;
18 | import com.google.firebase.database.DataSnapshot;
19 | import com.google.firebase.database.DatabaseError;
20 | import com.google.firebase.database.DatabaseReference;
21 | import com.google.firebase.database.FirebaseDatabase;
22 | import com.google.firebase.database.ValueEventListener;
23 | import com.google.firebase.storage.FirebaseStorage;
24 | import com.google.firebase.storage.StorageReference;
25 | import com.google.firebase.storage.UploadTask;
26 | import com.theartofdev.edmodo.cropper.CropImage;
27 | import com.theartofdev.edmodo.cropper.CropImageView;
28 |
29 | public class UserProfileActivity extends AppCompatActivity {
30 |
31 | private static final int PICK_IMAGE = 2;
32 | Uri resultUri;
33 | private ImageButton ibUserImage;
34 | private TextView tvUserName, tvUserEmail;
35 | private Button bnPostUserProfile;
36 | private ProgressDialog mProgressDialog;
37 |
38 |
39 | private DatabaseReference mDatabaseRef;
40 | private FirebaseAuth mFirebaseAuth;
41 | private FirebaseUser firebaseUser;
42 | private StorageReference mStorageRef;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_user_profile);
48 |
49 | Intent intent = getIntent();
50 | String feed_uid = intent.getStringExtra("feed_uid");
51 |
52 | ibUserImage = (ImageButton) findViewById(R.id.xibUserImage);
53 | tvUserName = (TextView) findViewById(R.id.xtvUserProfileName);
54 | tvUserEmail = (TextView) findViewById(R.id.xtvUserEmail);
55 | bnPostUserProfile = (Button) findViewById(R.id.xbnPostUserProfile);
56 | mProgressDialog = new ProgressDialog(this);
57 |
58 | mFirebaseAuth = FirebaseAuth.getInstance();
59 | firebaseUser = mFirebaseAuth.getCurrentUser();
60 | mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("users").child(firebaseUser.getUid());
61 | mStorageRef = FirebaseStorage.getInstance().getReference();
62 | mDatabaseRef.keepSynced(true);
63 |
64 | ibUserImage.setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
68 | pickImageIntent.setType("image/*");
69 | startActivityForResult(pickImageIntent, PICK_IMAGE);
70 | }
71 | });
72 |
73 | bnPostUserProfile.setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | if (resultUri != null) {
77 |
78 | mProgressDialog.setMessage("Updating your profile...");
79 | mProgressDialog.setCanceledOnTouchOutside(false);
80 | mProgressDialog.show();
81 | StorageReference mProfileImageRef = mStorageRef.child("profile_images").child(firebaseUser.getUid());
82 | mProfileImageRef.putFile(resultUri).addOnSuccessListener(new OnSuccessListener() {
83 | @Override
84 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
85 |
86 | Toast.makeText(UserProfileActivity.this, "Profile updated successfully", Toast.LENGTH_SHORT).show();
87 | Uri downloadUrl = taskSnapshot.getDownloadUrl();
88 | mDatabaseRef.child("profile_image").setValue(downloadUrl.toString());
89 |
90 | mProgressDialog.dismiss();
91 | }
92 | });
93 | }
94 | }
95 | });
96 |
97 | mDatabaseRef.addValueEventListener(new ValueEventListener() {
98 | @Override
99 | public void onDataChange(DataSnapshot dataSnapshot) {
100 | String name = dataSnapshot.child("name").getValue(String.class);
101 | String email = dataSnapshot.child("email").getValue(String.class);
102 | String imageUrl = dataSnapshot.child("profile_image").getValue(String.class);
103 |
104 | tvUserName.setText(name);
105 | tvUserEmail.setText(email);
106 | if (imageUrl != null) {
107 | Glide.with(UserProfileActivity.this)
108 | .load(imageUrl)
109 | .asBitmap()
110 | .centerCrop()
111 | .into(ibUserImage);
112 |
113 | } else {
114 | Glide.with(UserProfileActivity.this).load(R.mipmap.empty_user).into(ibUserImage);
115 | }
116 | }
117 |
118 | @Override
119 |
120 | public void onCancelled(DatabaseError databaseError) {
121 |
122 | }
123 | });
124 | }
125 |
126 | @Override
127 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
128 | super.onActivityResult(requestCode, resultCode, data);
129 |
130 | if (requestCode == PICK_IMAGE && resultCode == RESULT_OK) {
131 | Uri imageUri = data.getData();
132 | CropImage.activity(imageUri)
133 | .setGuidelines(CropImageView.Guidelines.ON)
134 | .setAspectRatio(1, 1)
135 | .start(this);
136 |
137 | }
138 | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
139 | CropImage.ActivityResult result = CropImage.getActivityResult(data);
140 | if (resultCode == RESULT_OK) {
141 | resultUri = result.getUri();
142 | Glide.with(UserProfileActivity.this).load(resultUri).into(ibUserImage);
143 | } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
144 | Exception error = result.getError();
145 | }
146 | }
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/PostActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 | import android.widget.ImageButton;
13 | import android.widget.Toast;
14 |
15 | import com.google.android.gms.tasks.OnFailureListener;
16 | import com.google.android.gms.tasks.OnSuccessListener;
17 | import com.google.firebase.auth.FirebaseAuth;
18 | import com.google.firebase.auth.FirebaseUser;
19 | import com.google.firebase.database.DatabaseReference;
20 | import com.google.firebase.database.FirebaseDatabase;
21 | import com.google.firebase.storage.FirebaseStorage;
22 | import com.google.firebase.storage.OnProgressListener;
23 | import com.google.firebase.storage.StorageReference;
24 | import com.google.firebase.storage.UploadTask;
25 | import com.theartofdev.edmodo.cropper.CropImage;
26 | import com.theartofdev.edmodo.cropper.CropImageView;
27 |
28 | import java.util.Calendar;
29 |
30 | public class PostActivity extends AppCompatActivity {
31 |
32 | private static final int PICK_IMAGE = 2;
33 | ImageButton ibImage;
34 | Button bnPost;
35 | EditText etTitle, etDesc;
36 | Uri resultUri;
37 | private StorageReference mStorageRef;
38 | private DatabaseReference mDatabaseRef;
39 | private ProgressDialog mProgressDialog;
40 | private FirebaseUser mUser;
41 | private FirebaseAuth mAuth;
42 |
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_post);
48 |
49 | ibImage = (ImageButton) findViewById(R.id.xibImage);
50 | bnPost = (Button) findViewById(R.id.xbnPost);
51 | etTitle = (EditText) findViewById(R.id.xetTitle);
52 | etDesc = (EditText) findViewById(R.id.xetDesc);
53 | mStorageRef = FirebaseStorage.getInstance().getReference();
54 | mAuth = FirebaseAuth.getInstance();
55 | mUser = mAuth.getCurrentUser();
56 | mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("feeds");
57 | mProgressDialog = new ProgressDialog(this);
58 |
59 | ibImage.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 | Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
63 | pickImageIntent.setType("image/*");
64 | startActivityForResult(pickImageIntent, PICK_IMAGE);
65 | }
66 | });
67 |
68 | bnPost.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | postToFirebase();
72 | }
73 | });
74 | }
75 |
76 | private void postToFirebase() {
77 |
78 | final String title = etTitle.getText().toString().trim();
79 | final String desc = etDesc.getText().toString().trim();
80 | mProgressDialog.setTitle("Posting...");
81 | mProgressDialog.setCanceledOnTouchOutside(false);
82 |
83 | if(!title.isEmpty() && !desc.isEmpty() && resultUri!=null) {
84 | mProgressDialog.show();
85 | StorageReference imageRef = mStorageRef.child("firebook_feeeds").child(resultUri.getLastPathSegment());
86 | imageRef.putFile(resultUri).addOnSuccessListener(new OnSuccessListener() {
87 | @Override
88 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
89 | Uri downloadUrl = taskSnapshot.getDownloadUrl();
90 |
91 | Toast.makeText(PostActivity.this, "Uploaded successfully", Toast.LENGTH_SHORT).show();
92 |
93 | DatabaseReference mchildRef = mDatabaseRef.push();
94 | mchildRef.child("title").setValue(title);
95 | mchildRef.child("desc").setValue(desc);
96 | mchildRef.child("u_id").setValue(mUser.getUid());
97 | Calendar c = Calendar.getInstance();
98 | int minute = c.get(Calendar.MINUTE);
99 | String date = c.get(Calendar.HOUR) + ":" + (minute < 10 ? "0" + minute : minute) + (c.get(Calendar.AM_PM) == 1 ? " PM" : " AM") + " "
100 | + c.get(Calendar.DATE) + "/" + c.get(Calendar.MONTH) + "/" + c.get(Calendar.YEAR);
101 |
102 | mchildRef.child("date").setValue(date);
103 | mchildRef.child("image").setValue(downloadUrl.toString());
104 |
105 | mProgressDialog.dismiss();
106 |
107 | Intent intent = new Intent(PostActivity.this, MainActivity.class);
108 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
109 | startActivity(intent);
110 | finish();
111 | }
112 | }).addOnFailureListener(new OnFailureListener() {
113 | @Override
114 | public void onFailure(@NonNull Exception e) {
115 | mProgressDialog.dismiss();
116 | Toast.makeText(PostActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
117 | }
118 | }).addOnProgressListener(new OnProgressListener() {
119 | @Override
120 | public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
121 | double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
122 | mProgressDialog.setMessage((int)progress+"% uploaded...");
123 | }
124 | });
125 |
126 | }
127 | else {
128 | Toast.makeText(this, "Fill both title and description, also add some image.", Toast.LENGTH_SHORT).show();
129 | }
130 | }
131 |
132 | @Override
133 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
134 | super.onActivityResult(requestCode, resultCode, data);
135 |
136 | if(requestCode==PICK_IMAGE && resultCode==RESULT_OK) {
137 | Uri imageUri= data.getData();
138 | CropImage.activity(imageUri)
139 | .setGuidelines(CropImageView.Guidelines.ON)
140 | .setAspectRatio(16, 9)
141 | .start(this);
142 |
143 | }
144 | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
145 | CropImage.ActivityResult result = CropImage.getActivityResult(data);
146 | if (resultCode == RESULT_OK) {
147 | resultUri = result.getUri();
148 | ibImage.setImageURI(resultUri);
149 | } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
150 | Exception error = result.getError();
151 | }
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/AnotherUserProfileActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.View;
10 | import android.widget.ImageButton;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import com.bumptech.glide.Glide;
16 | import com.firebase.ui.database.FirebaseRecyclerAdapter;
17 | import com.google.android.gms.tasks.OnSuccessListener;
18 | import com.google.firebase.auth.FirebaseAuth;
19 | import com.google.firebase.database.DataSnapshot;
20 | import com.google.firebase.database.DatabaseError;
21 | import com.google.firebase.database.DatabaseReference;
22 | import com.google.firebase.database.FirebaseDatabase;
23 | import com.google.firebase.database.Query;
24 | import com.google.firebase.database.ValueEventListener;
25 | import com.google.firebase.storage.FirebaseStorage;
26 | import com.google.firebase.storage.StorageReference;
27 | import com.google.firebase.storage.UploadTask;
28 | import com.theartofdev.edmodo.cropper.CropImage;
29 | import com.theartofdev.edmodo.cropper.CropImageView;
30 |
31 | import dataStructures.Feed;
32 |
33 | public class AnotherUserProfileActivity extends AppCompatActivity {
34 |
35 | private static final int PICK_IMAGE = 3;
36 | private ImageView ivUserImage;
37 | private TextView tvUserName, tvUserEmail;
38 | private ImageButton ibEditImage;
39 | private RecyclerView rvUserProfile;
40 |
41 | private DatabaseReference mUserDbRef, mFeedsDbRef;
42 | private FirebaseAuth mAuth;
43 | private Uri resultUri;
44 | private Query userOnlyQuery;
45 | private String user_id;
46 |
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | setContentView(R.layout.activity_another_user_profile);
51 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
52 | Intent intent = getIntent();
53 |
54 | user_id = intent.getStringExtra("feed_uid");
55 |
56 | ivUserImage = (ImageView) findViewById(R.id.xivAnotherUserImage);
57 | tvUserName = (TextView) findViewById(R.id.xtvAnotherUserName);
58 | tvUserEmail = (TextView) findViewById(R.id.xtvAnotherUserEmail);
59 | ibEditImage = (ImageButton) findViewById(R.id.xibEditImage);
60 | rvUserProfile = (RecyclerView) findViewById(R.id.xrvUserProfile);
61 | LinearLayoutManager layoutManager = new LinearLayoutManager(this);
62 | layoutManager.setReverseLayout(true);
63 | layoutManager.setStackFromEnd(true);
64 | rvUserProfile.setLayoutManager(layoutManager);
65 |
66 | mUserDbRef = FirebaseDatabase.getInstance().getReference().child("users").child(user_id);
67 | mFeedsDbRef = FirebaseDatabase.getInstance().getReference().child("feeds");
68 | mAuth = FirebaseAuth.getInstance();
69 | String current_uid = mAuth.getCurrentUser().getUid();
70 | mUserDbRef.keepSynced(true);
71 | mFeedsDbRef.keepSynced(true);
72 |
73 | userOnlyQuery = mFeedsDbRef.orderByChild("u_id").equalTo(user_id);
74 |
75 | if (current_uid.equals(user_id)) {
76 | ibEditImage.setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
80 | pickImageIntent.setType("image/*");
81 | startActivityForResult(pickImageIntent, PICK_IMAGE);
82 | }
83 | });
84 | } else {
85 | ibEditImage.setVisibility(View.GONE);
86 | }
87 |
88 | mUserDbRef.addValueEventListener(new ValueEventListener() {
89 | @Override
90 | public void onDataChange(DataSnapshot dataSnapshot) {
91 | String name = dataSnapshot.child("name").getValue(String.class);
92 | String email = dataSnapshot.child("email").getValue(String.class);
93 | String image = dataSnapshot.child("profile_image").getValue(String.class);
94 |
95 | getSupportActionBar().setTitle(name);
96 | tvUserName.setText(name);
97 | tvUserEmail.setText(email);
98 | Glide.with(getApplicationContext())
99 | .load(image)
100 | .placeholder(R.mipmap.empty_user)
101 | .crossFade()
102 | .into(ivUserImage);
103 | }
104 |
105 | @Override
106 | public void onCancelled(DatabaseError databaseError) {
107 |
108 | }
109 | });
110 | }
111 |
112 | @Override
113 | protected void onStart() {
114 | super.onStart();
115 |
116 |
117 | FirebaseRecyclerAdapter userProfileFirebaseAdapter = new FirebaseRecyclerAdapter(
118 | Feed.class,
119 | R.layout.single_row_main,
120 | MainActivity.FeedsViewHolder.class,
121 | userOnlyQuery
122 | ) {
123 | @Override
124 | protected void populateViewHolder(final MainActivity.FeedsViewHolder viewHolder, Feed model, int position) {
125 |
126 | final String feedU_id = model.getU_id();
127 | DatabaseReference dbUserRef = FirebaseDatabase.getInstance().getReference().child("users").child(feedU_id);
128 | dbUserRef.keepSynced(true);
129 | dbUserRef.addValueEventListener(new ValueEventListener() {
130 | @Override
131 | public void onDataChange(DataSnapshot dataSnapshot) {
132 |
133 | String userName = dataSnapshot.child("name").getValue(String.class);
134 | String userProfileImage = dataSnapshot.child("profile_image").getValue(String.class);
135 |
136 | viewHolder.setUserName(userName);
137 | viewHolder.setUserImage(AnotherUserProfileActivity.this, userProfileImage);
138 | }
139 |
140 | @Override
141 | public void onCancelled(DatabaseError databaseError) {
142 |
143 | }
144 | });
145 |
146 | viewHolder.setTitle(model.getTitle());
147 | viewHolder.setDesc(model.getDesc());
148 | viewHolder.setDate(model.getDate());
149 | viewHolder.setImage(getApplicationContext(), model.getImage());
150 | }
151 | };
152 |
153 | rvUserProfile.setAdapter(userProfileFirebaseAdapter);
154 | }
155 |
156 | @Override
157 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
158 | super.onActivityResult(requestCode, resultCode, data);
159 |
160 | if (requestCode == PICK_IMAGE && resultCode == RESULT_OK) {
161 | Uri imageUri = data.getData();
162 | CropImage.activity(imageUri)
163 | .setGuidelines(CropImageView.Guidelines.ON)
164 | .setAspectRatio(1, 1)
165 | .start(this);
166 |
167 | }
168 | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
169 | CropImage.ActivityResult result = CropImage.getActivityResult(data);
170 | if (resultCode == RESULT_OK) {
171 | resultUri = result.getUri();
172 | Glide.with(AnotherUserProfileActivity.this).load(resultUri).into(ivUserImage);
173 |
174 | StorageReference mProfileImageRef = FirebaseStorage.getInstance().getReference().child("profile_images")
175 | .child(mAuth.getCurrentUser().getUid());
176 | mProfileImageRef.putFile(resultUri).addOnSuccessListener(new OnSuccessListener() {
177 | @Override
178 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
179 |
180 | Toast.makeText(AnotherUserProfileActivity.this, "Profile updated successfully", Toast.LENGTH_SHORT).show();
181 | Uri downloadUrl = taskSnapshot.getDownloadUrl();
182 | mUserDbRef.child("profile_image").setValue(downloadUrl.toString());
183 |
184 | }
185 | });
186 |
187 | } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
188 | Exception error = result.getError();
189 | }
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/LogInActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import com.google.android.gms.auth.api.Auth;
16 | import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
17 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
18 | import com.google.android.gms.auth.api.signin.GoogleSignInResult;
19 | import com.google.android.gms.common.ConnectionResult;
20 | import com.google.android.gms.common.SignInButton;
21 | import com.google.android.gms.common.api.GoogleApiClient;
22 | import com.google.android.gms.tasks.OnCompleteListener;
23 | import com.google.android.gms.tasks.Task;
24 | import com.google.firebase.auth.AuthCredential;
25 | import com.google.firebase.auth.AuthResult;
26 | import com.google.firebase.auth.FirebaseAuth;
27 | import com.google.firebase.auth.GoogleAuthProvider;
28 | import com.google.firebase.database.DataSnapshot;
29 | import com.google.firebase.database.DatabaseError;
30 | import com.google.firebase.database.DatabaseReference;
31 | import com.google.firebase.database.FirebaseDatabase;
32 | import com.google.firebase.database.ValueEventListener;
33 |
34 | public class LogInActivity extends AppCompatActivity {
35 |
36 | private static final String TAG = "LogInActivity";
37 | private static int RC_SIGN_IN = 5;
38 | private TextView bnNewAccount;
39 | private EditText etEmail, etPassword;
40 | private Button bnLogIn;
41 | private SignInButton bnGoogleSignIn;
42 | private FirebaseAuth mFirebaseAuth;
43 | private FirebaseAuth.AuthStateListener mAuthStateListener;
44 | private DatabaseReference mDatabaseRef;
45 | private GoogleApiClient mGoogleApiClient;
46 | private ProgressDialog mProgressDialog;
47 |
48 | @Override
49 | protected void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | setContentView(R.layout.activity_log_in);
52 |
53 | mFirebaseAuth = FirebaseAuth.getInstance();
54 | mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("users");
55 | mDatabaseRef.keepSynced(true);
56 |
57 | etEmail = (EditText) findViewById(R.id.xetLogInEmail);
58 | etPassword = (EditText) findViewById(R.id.xetLogInPassword);
59 | bnLogIn = (Button) findViewById(R.id.xbnLogIn);
60 | bnNewAccount = (TextView) findViewById(R.id.xbnLogInNewAccount);
61 | bnGoogleSignIn = (SignInButton) findViewById(R.id.xbnGoogleSignIn);
62 | mProgressDialog = new ProgressDialog(this);
63 |
64 | bnLogIn.setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | doLogIn();
68 | }
69 | });
70 |
71 | bnNewAccount.setOnClickListener(new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | Intent intent = new Intent(LogInActivity.this, SignUpActivity.class);
75 | startActivity(intent);
76 | }
77 | });
78 |
79 | // Configure Google Sign In
80 | GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
81 | .requestIdToken(getString(R.string.default_web_client_id))
82 | .requestEmail()
83 | .build();
84 |
85 | mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
86 | .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
87 | @Override
88 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
89 | Toast.makeText(LogInActivity.this, "something went wrong", Toast.LENGTH_SHORT).show();
90 | }
91 | })
92 | .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
93 | .build();
94 |
95 | bnGoogleSignIn.setOnClickListener(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | mProgressDialog.setMessage("Loading...");
99 | mProgressDialog.show();
100 | signIn();
101 | mProgressDialog.dismiss();
102 | }
103 | });
104 |
105 | mAuthStateListener = new FirebaseAuth.AuthStateListener() {
106 | @Override
107 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
108 | if (firebaseAuth.getCurrentUser() != null) {
109 | Intent intent = new Intent(LogInActivity.this, MainActivity.class);
110 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
111 | startActivity(intent);
112 | finish();
113 | }
114 | }
115 | };
116 | }
117 |
118 | @Override
119 | protected void onStart() {
120 | super.onStart();
121 | mFirebaseAuth.addAuthStateListener(mAuthStateListener);
122 | }
123 |
124 | private void doLogIn() {
125 | String email = etEmail.getText().toString().trim();
126 | String password = etPassword.getText().toString().trim();
127 |
128 | if (!email.isEmpty() && !password.isEmpty()) {
129 |
130 | mProgressDialog.setMessage("Logging In...");
131 | mProgressDialog.setCanceledOnTouchOutside(false);
132 | mProgressDialog.show();
133 |
134 | mFirebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() {
135 | @Override
136 | public void onComplete(@NonNull Task task) {
137 |
138 | if (task.isSuccessful()) {
139 | checkUserExists();
140 | } else {
141 | Toast.makeText(LogInActivity.this, "Enter correct email and password", Toast.LENGTH_SHORT).show();
142 | }
143 | mProgressDialog.dismiss();
144 | }
145 | });
146 | }
147 | }
148 |
149 | private void checkUserExists() {
150 | final String user_id = mFirebaseAuth.getCurrentUser().getUid();
151 |
152 | mDatabaseRef.addValueEventListener(new ValueEventListener() {
153 | @Override
154 | public void onDataChange(DataSnapshot dataSnapshot) {
155 | if (dataSnapshot.hasChild(user_id)) {
156 |
157 | mProgressDialog.dismiss();
158 | Intent intent = new Intent(LogInActivity.this, MainActivity.class);
159 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
160 | startActivity(intent);
161 | finish();
162 | } else {
163 | Toast.makeText(LogInActivity.this, "You need to create a new account.", Toast.LENGTH_SHORT).show();
164 | }
165 | }
166 |
167 | @Override
168 | public void onCancelled(DatabaseError databaseError) {
169 |
170 | }
171 | });
172 | }
173 |
174 | // ---------------------- Google Sign in -----------------------------//
175 |
176 | private void signIn() {
177 | Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
178 | startActivityForResult(signInIntent, RC_SIGN_IN);
179 | }
180 |
181 | @Override
182 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
183 | super.onActivityResult(requestCode, resultCode, data);
184 |
185 | mProgressDialog.setMessage("Logging in...");
186 | mProgressDialog.show();
187 | // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
188 | if (requestCode == RC_SIGN_IN) {
189 | GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
190 | if (result.isSuccess()) {
191 | // Google Sign In was successful, authenticate with Firebase
192 | GoogleSignInAccount account = result.getSignInAccount();
193 | firebaseAuthWithGoogle(account);
194 | } else {
195 | // Google Sign In failed, update UI appropriately
196 | // ...
197 | }
198 | }
199 | mProgressDialog.dismiss();
200 | }
201 |
202 | private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
203 | Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
204 |
205 | AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
206 | mFirebaseAuth.signInWithCredential(credential)
207 | .addOnCompleteListener(this, new OnCompleteListener() {
208 | @Override
209 | public void onComplete(@NonNull Task task) {
210 | Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
211 |
212 | // If sign in fails, display a message to the user. If sign in succeeds
213 | // the auth state listener will be notified and logic to handle the
214 | // signed in user can be handled in the listener.
215 | if (!task.isSuccessful()) {
216 | Log.w(TAG, "signInWithCredential", task.getException());
217 | Toast.makeText(LogInActivity.this, "Authentication failed.",
218 | Toast.LENGTH_SHORT).show();
219 | } else {
220 | DatabaseReference userDbRef = mDatabaseRef.child(mFirebaseAuth.getCurrentUser().getUid());
221 | userDbRef.child("email").setValue(acct.getEmail());
222 | userDbRef.child("name").setValue(acct.getDisplayName());
223 | userDbRef.child("profile_image").setValue(acct.getPhotoUrl().toString());
224 | }
225 |
226 | // ...
227 | }
228 | });
229 | mProgressDialog.dismiss();
230 | }
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/anujsharma/firebook/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.anujsharma.firebook;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.os.Parcelable;
9 | import android.os.PersistableBundle;
10 | import android.support.annotation.NonNull;
11 | import android.support.design.widget.FloatingActionButton;
12 | import android.support.design.widget.NavigationView;
13 | import android.support.v4.widget.DrawerLayout;
14 | import android.support.v7.app.ActionBarDrawerToggle;
15 | import android.support.v7.app.AlertDialog;
16 | import android.support.v7.app.AppCompatActivity;
17 | import android.support.v7.widget.LinearLayoutManager;
18 | import android.support.v7.widget.RecyclerView;
19 | import android.support.v7.widget.Toolbar;
20 | import android.view.Menu;
21 | import android.view.MenuItem;
22 | import android.view.View;
23 | import android.widget.ImageButton;
24 | import android.widget.ImageView;
25 | import android.widget.TextView;
26 | import android.widget.Toast;
27 |
28 | import com.bumptech.glide.Glide;
29 | import com.firebase.ui.database.FirebaseRecyclerAdapter;
30 | import com.google.firebase.auth.FirebaseAuth;
31 | import com.google.firebase.auth.FirebaseUser;
32 | import com.google.firebase.database.DataSnapshot;
33 | import com.google.firebase.database.DatabaseError;
34 | import com.google.firebase.database.DatabaseReference;
35 | import com.google.firebase.database.FirebaseDatabase;
36 | import com.google.firebase.database.ValueEventListener;
37 |
38 | import java.util.Calendar;
39 |
40 | import dataStructures.Feed;
41 | import de.hdodenhof.circleimageview.CircleImageView;
42 |
43 | public class MainActivity extends AppCompatActivity {
44 |
45 | private final String LIST_STATE_KEY = "recycler_state";
46 | FloatingActionButton fab;
47 | Parcelable mListState;
48 | private RecyclerView rvMainRecyclerView;
49 | private DrawerLayout mDrawerLayout;
50 | private ActionBarDrawerToggle mToggle;
51 | private NavigationView navigationView;
52 | private TextView navigationUserName, navigationUserEmail;
53 | private CircleImageView navigationUserImage;
54 | private DatabaseReference mDatabaseRef;
55 | private DatabaseReference mDatabaseUsersRef;
56 | private DatabaseReference mDatabaseLikesRef;
57 | private FirebaseAuth mAuth;
58 | private FirebaseAuth.AuthStateListener mAuthStateListener;
59 | private LinearLayoutManager layoutManager;
60 | private boolean mProcessLike = false;
61 |
62 |
63 | @Override
64 | protected void onCreate(Bundle savedInstanceState) {
65 | super.onCreate(savedInstanceState);
66 |
67 | setContentView(R.layout.activity_main);
68 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
69 | setSupportActionBar(toolbar);
70 |
71 |
72 | fab = (FloatingActionButton) findViewById(R.id.fab);
73 | fab.setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View view) {
76 | startActivity(new Intent(MainActivity.this, PostActivity.class));
77 | }
78 | });
79 |
80 |
81 | mDrawerLayout = (DrawerLayout) findViewById(R.id.mainDrawerLayout);
82 | navigationView = (NavigationView) findViewById(R.id.mainNavigationView);
83 | mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close) {
84 | @Override
85 | public void onDrawerSlide(View drawerView, float slideOffset) {
86 | super.onDrawerSlide(drawerView, slideOffset);
87 | fab.setAlpha(1 - slideOffset);
88 | }
89 |
90 | @Override
91 | public void onDrawerOpened(View drawerView) {
92 | super.onDrawerOpened(drawerView);
93 | fab.setVisibility(View.GONE);
94 | }
95 |
96 | @Override
97 | public void onDrawerClosed(View drawerView) {
98 | super.onDrawerClosed(drawerView);
99 | fab.setVisibility(View.VISIBLE);
100 | }
101 | };
102 | mDrawerLayout.addDrawerListener(mToggle);
103 | mToggle.syncState();
104 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
105 | View mview = navigationView.getHeaderView(0);
106 | navigationUserImage = (CircleImageView) mview.findViewById(R.id.xcivUserProfileImage);
107 | navigationUserName = (TextView) mview.findViewById(R.id.xtvUserNameInNavigation);
108 | navigationUserEmail = (TextView) mview.findViewById(R.id.xtvUserEmailInNavigation);
109 |
110 | mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("feeds");
111 | mDatabaseUsersRef = FirebaseDatabase.getInstance().getReference().child("users");
112 | mDatabaseLikesRef = FirebaseDatabase.getInstance().getReference().child("likes");
113 | mDatabaseRef.keepSynced(true);
114 | mDatabaseUsersRef.keepSynced(true);
115 | mDatabaseLikesRef.keepSynced(true);
116 |
117 | rvMainRecyclerView = (RecyclerView) findViewById(R.id.xrvMainRecyclerView);
118 |
119 | layoutManager = new LinearLayoutManager(this);
120 | layoutManager.setReverseLayout(true);
121 | layoutManager.setStackFromEnd(true);
122 | rvMainRecyclerView.setLayoutManager(layoutManager);
123 |
124 | mAuth = FirebaseAuth.getInstance();
125 |
126 | mAuthStateListener = new FirebaseAuth.AuthStateListener() {
127 | @Override
128 | public void onAuthStateChanged(@NonNull final FirebaseAuth firebaseAuth) {
129 |
130 | if (firebaseAuth.getCurrentUser() == null) {
131 | Intent intent = new Intent(MainActivity.this, LogInActivity.class);
132 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
133 | startActivity(intent);
134 | finish();
135 | }
136 | }
137 | };
138 |
139 | mDatabaseUsersRef.addValueEventListener(new ValueEventListener() {
140 | @Override
141 | public void onDataChange(DataSnapshot dataSnapshot) {
142 | FirebaseUser currentUser = mAuth.getCurrentUser();
143 | if (currentUser != null) {
144 | String name = dataSnapshot.child(currentUser.getUid()).child("name").getValue(String.class);
145 | String email = dataSnapshot.child(currentUser.getUid()).child("email").getValue(String.class);
146 | String user_image = dataSnapshot.child(currentUser.getUid()).child("profile_image").getValue(String.class);
147 |
148 | navigationUserName.setText(name);
149 | navigationUserEmail.setText(email);
150 | Glide.with(getApplicationContext())
151 | .load(user_image)
152 | .dontAnimate()
153 | .into(navigationUserImage);
154 | }
155 | }
156 |
157 | @Override
158 | public void onCancelled(DatabaseError databaseError) {
159 |
160 | }
161 | });
162 |
163 | navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
164 | @Override
165 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
166 |
167 | switch (item.getItemId()) {
168 | case R.id.nav_profile:
169 | startActivity(new Intent(MainActivity.this, UserProfileActivity.class));
170 | break;
171 | case R.id.nav_settings:
172 | Toast.makeText(MainActivity.this, "settings", Toast.LENGTH_SHORT).show();
173 | break;
174 | case R.id.nav_logout:
175 |
176 | final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
177 | builder.setMessage("Log Out");
178 | builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
179 | @Override
180 | public void onClick(DialogInterface dialog, int which) {
181 | mAuth.signOut();
182 | Intent intent = new Intent(MainActivity.this, LogInActivity.class);
183 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
184 | startActivity(intent);
185 | finish();
186 | }
187 | });
188 | builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
189 | @Override
190 | public void onClick(DialogInterface dialog, int which) {
191 |
192 | }
193 | });
194 | AlertDialog alertDialog = builder.create();
195 | alertDialog.show();
196 |
197 | }
198 | return true;
199 | }
200 | });
201 | }
202 |
203 | @Override
204 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
205 | super.onSaveInstanceState(outState, outPersistentState);
206 |
207 | mListState = layoutManager.onSaveInstanceState();
208 | outState.putParcelable(LIST_STATE_KEY, mListState);
209 | }
210 |
211 | @Override
212 | public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
213 | super.onRestoreInstanceState(savedInstanceState, persistentState);
214 |
215 | if (savedInstanceState != null)
216 | mListState = savedInstanceState.getParcelable(LIST_STATE_KEY);
217 | }
218 |
219 | @Override
220 | protected void onStart() {
221 | super.onStart();
222 | FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter(
223 |
224 | Feed.class,
225 | R.layout.single_row_main,
226 | FeedsViewHolder.class,
227 | mDatabaseRef
228 | ) {
229 | @Override
230 | protected void populateViewHolder(final FeedsViewHolder viewHolder, final Feed model, int position) {
231 |
232 | final String feedU_id = model.getU_id();
233 | final String feed_key = getRef(position).getKey();
234 | DatabaseReference dbUserRef = FirebaseDatabase.getInstance().getReference().child("users").child(feedU_id);
235 | dbUserRef.keepSynced(true);
236 | dbUserRef.addValueEventListener(new ValueEventListener() {
237 | @Override
238 | public void onDataChange(DataSnapshot dataSnapshot) {
239 |
240 | String userName = dataSnapshot.child("name").getValue(String.class);
241 | String userProfileImage = dataSnapshot.child("profile_image").getValue(String.class);
242 |
243 | viewHolder.setUserName(userName);
244 | viewHolder.setUserImage(MainActivity.this, userProfileImage);
245 | }
246 |
247 | @Override
248 | public void onCancelled(DatabaseError databaseError) {
249 |
250 | }
251 | });
252 |
253 | viewHolder.setTitle(model.getTitle());
254 | viewHolder.setDesc(model.getDesc());
255 | viewHolder.setDate(model.getDate());
256 | viewHolder.setImage(getApplicationContext(), model.getImage());
257 | viewHolder.setLike(feed_key);
258 |
259 | viewHolder.tvUserProfileName.setOnClickListener(new View.OnClickListener() {
260 | @Override
261 | public void onClick(View v) {
262 | Intent intent = new Intent(MainActivity.this, AnotherUserProfileActivity.class);
263 | intent.putExtra("feed_uid", feedU_id);
264 | startActivity(intent);
265 | }
266 | });
267 |
268 | viewHolder.ivUserImage.setOnClickListener(new View.OnClickListener() {
269 | @Override
270 | public void onClick(View v) {
271 | Intent intent = new Intent(MainActivity.this, AnotherUserProfileActivity.class);
272 | intent.putExtra("feed_uid", feedU_id);
273 | startActivity(intent);
274 | }
275 | });
276 |
277 | viewHolder.ivImage.setOnClickListener(new View.OnClickListener() {
278 | @Override
279 | public void onClick(View v) {
280 | Intent intent = new Intent(MainActivity.this, ImageViewActivity.class);
281 | intent.putExtra("image_uri", model.getImage());
282 | startActivity(intent);
283 | }
284 | });
285 |
286 | viewHolder.ibLike.setOnClickListener(new View.OnClickListener() {
287 | @Override
288 | public void onClick(View v) {
289 |
290 | mProcessLike = true;
291 | mDatabaseLikesRef.addValueEventListener(new ValueEventListener() {
292 | @Override
293 | public void onDataChange(DataSnapshot dataSnapshot) {
294 |
295 | if (mProcessLike) {
296 | if (dataSnapshot.child(feed_key).hasChild(mAuth.getCurrentUser().getUid())) {
297 | viewHolder.ibLike.setImageResource(R.drawable.like_grey);
298 | mDatabaseLikesRef.child(feed_key).child(mAuth.getCurrentUser().getUid()).removeValue();
299 | } else {
300 | viewHolder.ibLike.setImageResource(R.drawable.like_orange);
301 | mDatabaseLikesRef.child(feed_key).child(mAuth.getCurrentUser().getUid()).setValue(getCurrentDateTime());
302 | }
303 | mProcessLike = false;
304 | }
305 | }
306 |
307 | @Override
308 | public void onCancelled(DatabaseError databaseError) {
309 |
310 | }
311 | });
312 | }
313 | });
314 | }
315 | };
316 |
317 | rvMainRecyclerView.setAdapter(firebaseRecyclerAdapter);
318 |
319 | mAuth.addAuthStateListener(mAuthStateListener);
320 | }
321 |
322 | @Override
323 | protected void onResume() {
324 | super.onResume();
325 | if (mListState != null) {
326 | layoutManager.onRestoreInstanceState(mListState);
327 | }
328 | }
329 |
330 | @Override
331 | public void onStop() {
332 | super.onStop();
333 | if (mAuthStateListener != null) {
334 | mAuth.removeAuthStateListener(mAuthStateListener);
335 | }
336 | }
337 |
338 | @Override
339 | public boolean onCreateOptionsMenu(Menu menu) {
340 | // Inflate the menu; this adds items to the action bar if it is present.
341 | getMenuInflater().inflate(R.menu.menu_main, menu);
342 | return true;
343 | }
344 |
345 | @Override
346 | public boolean onOptionsItemSelected(MenuItem item) {
347 | // Handle action bar item clicks here. The action bar will
348 | // automatically handle clicks on the Home/Up button, so long
349 | // as you specify a parent activity in AndroidManifest.xml.
350 | int id = item.getItemId();
351 |
352 | //noinspection SimplifiableIfStatement
353 | if (id == R.id.action_search) {
354 | startActivity(new Intent(MainActivity.this, SearchActivity.class));
355 | }
356 |
357 | if (mToggle.onOptionsItemSelected(item)) {
358 | return true;
359 | }
360 |
361 | return super.onOptionsItemSelected(item);
362 | }
363 |
364 | public String getCurrentDateTime() {
365 | Calendar c = Calendar.getInstance();
366 | int minute = c.get(Calendar.MINUTE);
367 | String date = c.get(Calendar.HOUR) + ":" + (minute < 10 ? "0" + minute : minute) + (c.get(Calendar.AM_PM) == 1 ? " PM" : " AM") + " "
368 | + c.get(Calendar.DATE) + "/" + c.get(Calendar.MONTH) + "/" + c.get(Calendar.YEAR);
369 | return date;
370 | }
371 |
372 | public static class FeedsViewHolder extends RecyclerView.ViewHolder {
373 |
374 | View mView;
375 | TextView tvUserProfileName;
376 | CircleImageView ivUserImage;
377 | ImageView ivImage;
378 | ImageButton ibLike;
379 | DatabaseReference dbLikesRef;
380 | FirebaseAuth mAuth;
381 |
382 | public FeedsViewHolder(View itemView) {
383 | super(itemView);
384 | mView = itemView;
385 |
386 | dbLikesRef = FirebaseDatabase.getInstance().getReference().child("likes");
387 | mAuth = FirebaseAuth.getInstance();
388 |
389 | ivUserImage = (CircleImageView) mView.findViewById(R.id.xivUserImageInFeeds);
390 | tvUserProfileName = (TextView) mView.findViewById(R.id.xtvUserNameInFeeds);
391 | ivImage = (ImageView) mView.findViewById(R.id.xivImage);
392 | ibLike = (ImageButton) mView.findViewById(R.id.xibLike);
393 | }
394 |
395 | public void setTitle(String title) {
396 | TextView tvTitle = (TextView) mView.findViewById(R.id.xtvTitle);
397 | tvTitle.setText(title);
398 | }
399 |
400 | public void setDesc(String desc) {
401 | TextView tvDesc = (TextView) mView.findViewById(R.id.xtvDesc);
402 | tvDesc.setText(desc);
403 | }
404 |
405 | public void setImage(Context context, String image) {
406 | Glide.with(context).load(image).into(ivImage);
407 | }
408 |
409 | public void setUserImage(Context context, String userImage) {
410 | Glide.with(context)
411 | .load(userImage)
412 | .placeholder(R.mipmap.empty_user)
413 | .crossFade()
414 | .dontAnimate()
415 | .into(ivUserImage);
416 | }
417 |
418 | public void setUserName(String userProfileName) {
419 | tvUserProfileName.setText(userProfileName);
420 | }
421 |
422 | public void setDate(String date) {
423 | TextView tvDate = (TextView) mView.findViewById(R.id.xtvDate);
424 | tvDate.setText(date);
425 | }
426 |
427 | public void setLike(final String post_key) {
428 |
429 | final TextView tvLikesCount = (TextView) mView.findViewById(R.id.tvLikesCount);
430 | dbLikesRef.addValueEventListener(new ValueEventListener() {
431 | @Override
432 | public void onDataChange(DataSnapshot dataSnapshot) {
433 |
434 | if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())) {
435 | ibLike.setImageResource(R.drawable.like_orange);
436 | tvLikesCount.setTextColor(Color.rgb(252, 176, 48));
437 | } else {
438 | tvLikesCount.setTextColor(Color.rgb(127, 127, 127));
439 | ibLike.setImageResource(R.drawable.like_grey);
440 | }
441 | long likesCount = dataSnapshot.child(post_key).getChildrenCount();
442 | if (likesCount == 0) {
443 | tvLikesCount.setVisibility(View.GONE);
444 | } else {
445 | tvLikesCount.setText(likesCount + "");
446 | tvLikesCount.setVisibility(View.VISIBLE);
447 | }
448 |
449 | }
450 |
451 | @Override
452 | public void onCancelled(DatabaseError databaseError) {
453 |
454 | }
455 | });
456 |
457 | }
458 | }
459 | }
460 |
--------------------------------------------------------------------------------