├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── font
│ │ │ │ ├── montserrat.ttf
│ │ │ │ ├── spectral.ttf
│ │ │ │ ├── vollkorn.ttf
│ │ │ │ ├── font.xml
│ │ │ │ └── my_font.xml
│ │ │ ├── drawable
│ │ │ │ ├── reg_img.png
│ │ │ │ ├── btn_primary.png
│ │ │ │ ├── fpass_img.png
│ │ │ │ ├── input_panel.png
│ │ │ │ ├── login_img.png
│ │ │ │ ├── next_panel.png
│ │ │ │ ├── start_img.png
│ │ │ │ ├── start_panel.png
│ │ │ │ ├── btn_secondary.png
│ │ │ │ ├── tab_background.xml
│ │ │ │ ├── background_right.xml
│ │ │ │ ├── background_left.xml
│ │ │ │ ├── tab_background_selected.xml
│ │ │ │ ├── tab_layout_background.xml
│ │ │ │ ├── tab_layout_selector.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── edit.png
│ │ │ │ ├── mbg.png
│ │ │ │ ├── pbg.png
│ │ │ │ ├── search.png
│ │ │ │ ├── friends.png
│ │ │ │ ├── send_btn.png
│ │ │ │ ├── signout.png
│ │ │ │ └── user_item.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── search.png
│ │ │ │ └── signout.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── default_avatar.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-anydpi
│ │ │ │ └── logout.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_chats.xml
│ │ │ │ ├── bar_layout.xml
│ │ │ │ ├── chat_item_left.xml
│ │ │ │ ├── fragment_users.xml
│ │ │ │ ├── chat_item_right.xml
│ │ │ │ ├── fragment_profile.xml
│ │ │ │ ├── activity_reset_password.xml
│ │ │ │ ├── activity_start.xml
│ │ │ │ ├── user_item.xml
│ │ │ │ ├── activity_message.xml
│ │ │ │ ├── activity_register.xml
│ │ │ │ ├── activity_login.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── ic_launcher-playstore.png
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── dvlnitins
│ │ │ │ └── friends
│ │ │ │ ├── Notifications
│ │ │ │ ├── MyResponse.java
│ │ │ │ ├── Sender.java
│ │ │ │ ├── Token.java
│ │ │ │ ├── Client.java
│ │ │ │ ├── Data.java
│ │ │ │ ├── OreoNotification.java
│ │ │ │ └── MyFirebaseMessaging.java
│ │ │ │ ├── FRIENDS.java
│ │ │ │ ├── Model
│ │ │ │ ├── Chatlist.java
│ │ │ │ ├── Chat.java
│ │ │ │ └── User.java
│ │ │ │ ├── Fragments
│ │ │ │ ├── APIService.java
│ │ │ │ ├── ChatsFragment.java
│ │ │ │ ├── UsersFragment.java
│ │ │ │ └── ProfileFragment.java
│ │ │ │ ├── StartActivity.java
│ │ │ │ ├── ResetPasswordActivity.java
│ │ │ │ ├── Adapter
│ │ │ │ ├── MessageAdapter.java
│ │ │ │ └── UserAdapter.java
│ │ │ │ ├── LoginActivity.java
│ │ │ │ ├── RegisterActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MessageActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dvlnitins
│ │ │ └── friends
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dvlnitins
│ │ └── friends
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── google-services.json
└── build.gradle
├── settings.gradle
├── Mobile_UI.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── render.experimental.xml
├── misc.xml
├── gradle.xml
├── jarRepositories.xml
└── codeStyles
│ └── Project.xml
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='FRIENDS'
3 |
--------------------------------------------------------------------------------
/Mobile_UI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/Mobile_UI.png
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/font/montserrat.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/font/montserrat.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/spectral.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/font/spectral.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/vollkorn.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/font/vollkorn.ttf
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/reg_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/reg_img.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/mbg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/mbg.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/pbg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/pbg.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_primary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/btn_primary.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/fpass_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/fpass_img.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/input_panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/input_panel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/login_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/login_img.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/next_panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/next_panel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/start_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/start_img.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/start_panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/start_panel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_secondary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable/btn_secondary.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/friends.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/send_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/send_btn.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/signout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/signout.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/user_item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxhdpi/user_item.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxxhdpi/search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/signout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xxxhdpi/signout.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/default_avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/drawable-xhdpi/default_avatar.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/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/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/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/nitinrai-dev/FRIENDS/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/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/font/font.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitinrai-dev/FRIENDS/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFB4A2
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/render.experimental.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FRIENDS
3 |
4 |
5 | Hello blank fragment
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/MyResponse.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class MyResponse {
8 |
9 | public int success;
10 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 25 23:33:21 IST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/Sender.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class Sender {
8 | public Data data;
9 | public String to;
10 |
11 | public Sender(Data data, String to) {
12 | this.data = data;
13 | this.to = to;
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/FRIENDS.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.firebase.database.FirebaseDatabase;
6 |
7 | public class FRIENDS extends Application {
8 |
9 | @Override
10 | public void onCreate() {
11 | super.onCreate();
12 |
13 | FirebaseDatabase.getInstance().setPersistenceEnabled(true);
14 |
15 | }}
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_background_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
8 |
9 |
10 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_layout_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
8 |
9 |
10 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/font/my_font.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/com/dvlnitins/friends/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_layout_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Model/Chatlist.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Model;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class Chatlist {
8 | public String id;
9 |
10 | public Chatlist(String id) {
11 | this.id = id;
12 | }
13 |
14 | public Chatlist() {
15 | }
16 |
17 | public String getId() {
18 | return id;
19 | }
20 |
21 | public void setId(String id) {
22 | this.id = id;
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/Token.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class Token {
8 | private String token;
9 |
10 | public Token(String token) {
11 | this.token = token;
12 | }
13 |
14 | public Token() {
15 | }
16 |
17 | public String getToken() {
18 | return token;
19 | }
20 |
21 | public void setToken(String token) {
22 | this.token = token;
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/logout.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_chats.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bar_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/Client.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | import retrofit2.Retrofit;
8 | import retrofit2.converter.gson.GsonConverterFactory;
9 |
10 | public class Client {
11 |
12 | private static Retrofit retrofit = null;
13 |
14 | public static Retrofit getClient(String url){
15 | if (retrofit == null){
16 | retrofit = new Retrofit.Builder()
17 | .baseUrl(url)
18 | .addConverterFactory(GsonConverterFactory.create())
19 | .build();
20 | }
21 | return retrofit;
22 | }
23 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFB4A2
4 | #FFB4A2
5 | #B5838D
6 | #F2F2F2
7 | #FFB4A2
8 | #D34941
9 | #B5838D
10 | #6D6875
11 | #FAF9F9
12 |
13 |
14 | #FFB4A2
15 | #B5838D
16 | #FAF9F9
17 | #F2F2F2
18 | #6D6875
19 | #FFB4A2
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Fragments/APIService.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Fragments;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | import com.dvlnitins.friends.Notifications.MyResponse;
8 | import com.dvlnitins.friends.Notifications.Sender;
9 |
10 | import retrofit2.Call;
11 | import retrofit2.http.Body;
12 | import retrofit2.http.Headers;
13 | import retrofit2.http.POST;
14 |
15 | public interface APIService {
16 | @Headers(
17 | {
18 | "Content-Type:application/json",
19 | "Authorization:key=AAAAb-4KokE:APA91bGl2i1U5ZMbFC9EMRUPmECIDNsLIF9z5k-SL95RSKInyX2hkS8fMQDTagJSBIKlYpqw6gBO9xPB3s6ldnniLvRG597VCeskR5wj-KLaCNulFQ458nh3_kTeEW24W0cFLiJlZ4e_"
20 | }
21 | )
22 |
23 | @POST("fcm/send")
24 | Call sendNotification(@Body Sender body);
25 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dvlnitins/friends/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.dvlnitins.friends", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
17 |
18 |
21 |
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # FRIENDS
6 | > Complete Open Source Real-Time Android Chat Application using Firebase.
7 |
8 | FRIENDS is a project that I started to improve my Android Development knowledge.
9 | Later on I have decided to make it public and open source.
10 |
11 | It uses Firebase's Authentication/Database/Storage/Messaging/CrashReporting libraries for it's implementation
12 | and several other libraries.
13 |
14 | 
15 |
16 | ## Download [APP](https://github.com/dvlnitins/FRIENDS/releases/download/v0.314-beta/FRIENDS-CHAT.apk)
17 |
18 | ## Installation
19 | ```sh
20 | *Setting up project*
21 |
22 | - Download Project
23 | - Create a new [Firebase](https://firebase.google.com) Project in console
24 | - Connect project with Firebase `(Tools/Firebase)` in Android Studio
25 | - Generate, download, paste `google-services.json` into the project
26 |
27 | ```
28 |
29 | ## Upcoming
30 |
31 | - Blocking
32 | - Block user from sending messages
33 |
34 |
35 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Model/Chat.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Model;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class Chat {
8 |
9 | private String sender;
10 | private String receiver;
11 | private String message;
12 | private boolean isseen;
13 |
14 | public Chat(String sender, String receiver, String message, boolean isseen) {
15 | this.sender = sender;
16 | this.receiver = receiver;
17 | this.message = message;
18 | this.isseen = isseen;
19 | }
20 |
21 | public Chat() {
22 | }
23 |
24 | public String getSender() {
25 | return sender;
26 | }
27 |
28 | public void setSender(String sender) {
29 | this.sender = sender;
30 | }
31 |
32 | public String getReceiver() {
33 | return receiver;
34 | }
35 |
36 | public void setReceiver(String receiver) {
37 | this.receiver = receiver;
38 | }
39 |
40 | public String getMessage() {
41 | return message;
42 | }
43 |
44 | public void setMessage(String message) {
45 | this.message = message;
46 | }
47 |
48 | public boolean isIsseen() {
49 | return isseen;
50 | }
51 |
52 | public void setIsseen(boolean isseen) {
53 | this.isseen = isseen;
54 | }
55 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/chat_item_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 | z
13 |
14 |
27 |
28 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/Data.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class Data {
8 | private String user;
9 | private int icon;
10 | private String body;
11 | private String title;
12 | private String sented;
13 |
14 | public Data(String user, int icon, String body, String title, String sented) {
15 | this.user = user;
16 | this.icon = icon;
17 | this.body = body;
18 | this.title = title;
19 | this.sented = sented;
20 | }
21 |
22 | public Data() {
23 | }
24 |
25 | public String getUser() {
26 | return user;
27 | }
28 |
29 | public void setUser(String user) {
30 | this.user = user;
31 | }
32 |
33 | public int getIcon() {
34 | return icon;
35 | }
36 |
37 | public void setIcon(int icon) {
38 | this.icon = icon;
39 | }
40 |
41 | public String getBody() {
42 | return body;
43 | }
44 |
45 | public void setBody(String body) {
46 | this.body = body;
47 | }
48 |
49 | public String getTitle() {
50 | return title;
51 | }
52 |
53 | public void setTitle(String title) {
54 | this.title = title;
55 | }
56 |
57 | public String getSented() {
58 | return sented;
59 | }
60 |
61 | public void setSented(String sented) {
62 | this.sented = sented;
63 | }
64 | }
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "480735044161",
4 | "firebase_url": "https://friends-a2f66.firebaseio.com",
5 | "project_id": "friends-a2f66",
6 | "storage_bucket": "friends-a2f66.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:480735044161:android:8fc4f158392f2701f6dcc0",
12 | "android_client_info": {
13 | "package_name": "com.dvlnitins.friends"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "480735044161-gg0t9k4r53omk3tdaiubh4kbdpqqp7fs.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.dvlnitins.friends",
22 | "certificate_hash": "b902b808cf96882b0427b57d9718b5109997e7b7"
23 | }
24 | },
25 | {
26 | "client_id": "480735044161-c082d2gj3mc3s6rg8ljnlbiu8n8ppae9.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyDBlwA9_QZAhftsRYB4kt3OtDGiT_Z9PiY"
33 | }
34 | ],
35 | "services": {
36 | "appinvite_service": {
37 | "other_platform_oauth_client": [
38 | {
39 | "client_id": "480735044161-c082d2gj3mc3s6rg8ljnlbiu8n8ppae9.apps.googleusercontent.com",
40 | "client_type": 3
41 | }
42 | ]
43 | }
44 | }
45 | }
46 | ],
47 | "configuration_version": "1"
48 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Model/User.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Model;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 |
7 | public class User {
8 |
9 | private String id;
10 | private String username;
11 | private String imageURL;
12 | private String status;
13 | private String search;
14 |
15 | public User(String id, String username, String imageURL, String status, String search) {
16 | this.id = id;
17 | this.username = username;
18 | this.imageURL = imageURL;
19 | this.status = status;
20 | this.search = search;
21 | }
22 |
23 | public User() {
24 |
25 | }
26 |
27 | public String getId() {
28 | return id;
29 | }
30 |
31 | public void setId(String id) {
32 | this.id = id;
33 | }
34 |
35 | public String getUsername() {
36 | return username;
37 | }
38 |
39 | public void setUsername(String username) {
40 | this.username = username;
41 | }
42 |
43 | public String getImageURL() {
44 | return imageURL;
45 | }
46 |
47 | public void setImageURL(String imageURL) {
48 | this.imageURL = imageURL;
49 | }
50 |
51 | public String getStatus() {
52 | return status;
53 | }
54 |
55 | public void setStatus(String status) {
56 | this.status = status;
57 | }
58 |
59 | public String getSearch() {
60 | return search;
61 | }
62 |
63 | public void setSearch(String search) {
64 | this.search = search;
65 | }
66 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_users.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
30 |
31 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/chat_item_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
32 |
33 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.google.gms.google-services'
3 |
4 | android {
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.2"
7 | defaultConfig {
8 | applicationId "com.dvlnitins.friends"
9 | minSdkVersion 21
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 |
26 | implementation 'androidx.appcompat:appcompat:1.0.2'
27 | implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
28 |
29 | implementation 'com.google.android.material:material:1.0.0'
30 | implementation 'androidx.cardview:cardview:1.0.0'
31 | implementation 'com.rengwuxian.materialedittext:library:2.1.4'
32 |
33 | implementation 'com.google.firebase:firebase-auth:19.2.0'
34 | implementation 'com.google.firebase:firebase-database:19.2.0'
35 | implementation 'com.google.firebase:firebase-messaging:20.1.0'
36 | implementation 'com.google.firebase:firebase-storage:19.1.0'
37 |
38 | implementation 'de.hdodenhof:circleimageview:2.2.0'
39 | implementation 'com.github.bumptech.glide:glide:4.8.0'
40 |
41 | //add these libraries
42 | implementation 'com.squareup.retrofit2:retrofit:2.3.0'
43 | implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
44 |
45 | testImplementation 'junit:junit:4.12'
46 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
47 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
48 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
34 |
35 |
38 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/OreoNotification.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.annotation.TargetApi;
6 | import android.app.Notification;
7 | import android.app.NotificationChannel;
8 | import android.app.NotificationManager;
9 | import android.app.PendingIntent;
10 |
11 | import android.content.Context;
12 | import android.content.ContextWrapper;
13 | import android.net.Uri;
14 | import android.os.Build;
15 | import android.os.Bundle;
16 |
17 | public class OreoNotification extends ContextWrapper {
18 |
19 | private static final String CHANNEL_ID = "com.dvlnitins.friends";
20 | private static final String CHANNEL_NAME = "FRIENDS";
21 |
22 | private NotificationManager notificationManager;
23 |
24 | public OreoNotification(Context base) {
25 | super(base);
26 |
27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
28 | createChannel();
29 | }
30 | }
31 |
32 | @TargetApi(Build.VERSION_CODES.O)
33 | private void createChannel() {
34 |
35 | NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
36 | CHANNEL_NAME,
37 | NotificationManager.IMPORTANCE_DEFAULT);
38 | channel.enableLights(false);
39 | channel.enableVibration(true);
40 | channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
41 |
42 | getManager().createNotificationChannel(channel);
43 | }
44 |
45 | public NotificationManager getManager(){
46 | if (notificationManager == null){
47 | notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
48 | }
49 |
50 | return notificationManager;
51 | }
52 |
53 | @TargetApi(Build.VERSION_CODES.O)
54 | public Notification.Builder getOreoNotification(String title, String body,
55 | PendingIntent pendingIntent, Uri soundUri, String icon){
56 | return new Notification.Builder(getApplicationContext(), CHANNEL_ID)
57 | .setContentIntent(pendingIntent)
58 | .setContentTitle(title)
59 | .setContentText(body)
60 | .setSmallIcon(Integer.parseInt(icon))
61 | .setSound(soundUri)
62 | .setAutoCancel(true);
63 | }
64 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/StartActivity.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 |
4 |
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.util.Pair;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.ImageView;
11 |
12 |
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import androidx.core.app.ActivityOptionsCompat;
15 |
16 | import com.google.firebase.auth.FirebaseAuth;
17 | import com.google.firebase.auth.FirebaseUser;
18 |
19 | public class StartActivity extends AppCompatActivity {
20 |
21 | Button login, register;
22 |
23 | FirebaseUser firebaseUser;
24 |
25 | @Override
26 | protected void onStart() {
27 | super.onStart();
28 |
29 | firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
30 |
31 | //check if user is null
32 | if (firebaseUser != null){
33 | Intent intent = new Intent(StartActivity.this, MainActivity.class);
34 | startActivity(intent);
35 | finish();
36 | }
37 | }
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.activity_start);
43 |
44 | login = findViewById(R.id.login);
45 | register = findViewById(R.id.register);
46 |
47 | login.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View view) {
50 | Intent intent = new Intent(StartActivity.this, LoginActivity.class);
51 |
52 | ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(StartActivity.this,findViewById(R.id.login), "myLogin");
53 |
54 | startActivity(intent, optionsCompat.toBundle());
55 | }
56 | });
57 |
58 | register.setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View view) {
61 | Intent intent = new Intent(StartActivity.this, RegisterActivity.class);
62 |
63 | ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(StartActivity.this,findViewById(R.id.register), "myRegister");
64 |
65 | startActivity(intent, optionsCompat.toBundle());
66 | }
67 | });
68 | }
69 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_profile.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
19 |
20 |
24 |
25 |
32 |
33 |
46 |
47 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/ResetPasswordActivity.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.appcompat.widget.Toolbar;
6 | import androidx.core.content.ContextCompat;
7 |
8 | import android.content.Intent;
9 | import android.os.Bundle;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.Toast;
14 |
15 | import com.google.android.gms.tasks.OnCompleteListener;
16 | import com.google.android.gms.tasks.Task;
17 | import com.google.firebase.auth.FirebaseAuth;
18 |
19 | public class ResetPasswordActivity extends AppCompatActivity {
20 |
21 | EditText send_email;
22 | Button btn_reset;
23 |
24 | FirebaseAuth firebaseAuth;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_reset_password);
30 |
31 |
32 | send_email = findViewById(R.id.send_email);
33 | btn_reset = findViewById(R.id.btn_reset);
34 |
35 | firebaseAuth = FirebaseAuth.getInstance();
36 |
37 | btn_reset.setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View view) {
40 | String email = send_email.getText().toString();
41 |
42 | if (email.equals("")){
43 | Toast.makeText(ResetPasswordActivity.this, "All fileds are required!", Toast.LENGTH_SHORT).show();
44 | } else {
45 | firebaseAuth.sendPasswordResetEmail(email).addOnCompleteListener(new OnCompleteListener() {
46 | @Override
47 | public void onComplete(@NonNull Task task) {
48 | if (task.isSuccessful()){
49 | Toast.makeText(ResetPasswordActivity.this, "Please check you Email", Toast.LENGTH_SHORT).show();
50 | startActivity(new Intent(ResetPasswordActivity.this, LoginActivity.class));
51 | } else {
52 | String error = task.getException().getMessage();
53 | Toast.makeText(ResetPasswordActivity.this, error, Toast.LENGTH_SHORT).show();
54 | }
55 | }
56 | });
57 | }
58 | }
59 | });
60 |
61 | }
62 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_reset_password.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
19 |
20 |
25 |
26 |
38 |
39 |
53 |
54 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
24 | z
25 |
41 |
42 |
58 |
59 |
60 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/user_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
25 |
26 |
38 |
39 |
51 |
52 |
63 |
64 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_message.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
19 |
32 |
33 |
43 |
44 |
50 |
51 |
60 |
61 |
74 |
75 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
24 |
25 |
38 |
39 |
52 |
53 |
66 |
67 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
24 |
25 |
37 |
38 |
51 |
52 |
66 |
67 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Adapter/MessageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Adapter;
2 |
3 |
4 |
5 | import android.content.Context;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.NonNull;
13 | import androidx.recyclerview.widget.RecyclerView;
14 |
15 | import com.bumptech.glide.Glide;
16 | import com.dvlnitins.friends.Model.Chat;
17 | import com.dvlnitins.friends.R;
18 | import com.google.firebase.auth.FirebaseAuth;
19 | import com.google.firebase.auth.FirebaseUser;
20 |
21 | import java.util.List;
22 |
23 | public class MessageAdapter extends RecyclerView.Adapter {
24 |
25 | public static final int MSG_TYPE_LEFT = 0;
26 | public static final int MSG_TYPE_RIGHT = 1;
27 |
28 | private Context mContext;
29 | private List mChat;
30 | private String imageurl;
31 |
32 | FirebaseUser fuser;
33 |
34 | public MessageAdapter(Context mContext, List mChat, String imageurl){
35 | this.mChat = mChat;
36 | this.mContext = mContext;
37 | this.imageurl = imageurl;
38 | }
39 |
40 | @NonNull
41 | @Override
42 | public MessageAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
43 | if (viewType == MSG_TYPE_RIGHT) {
44 | View view = LayoutInflater.from(mContext).inflate(R.layout.chat_item_right, parent, false);
45 | return new MessageAdapter.ViewHolder(view);
46 | } else {
47 | View view = LayoutInflater.from(mContext).inflate(R.layout.chat_item_left, parent, false);
48 | return new MessageAdapter.ViewHolder(view);
49 | }
50 | }
51 |
52 | @Override
53 | public void onBindViewHolder(@NonNull MessageAdapter.ViewHolder holder, int position) {
54 |
55 | Chat chat = mChat.get(position);
56 |
57 | holder.show_message.setText(chat.getMessage());
58 |
59 | if (imageurl.equals("default")){
60 | holder.profile_image.setImageResource(R.drawable.default_avatar);
61 | } else {
62 | Glide.with(mContext).load(imageurl).into(holder.profile_image);
63 | }
64 |
65 | if (position == mChat.size()-1){
66 | if (chat.isIsseen()){
67 | holder.txt_seen.setText("Seen");
68 | } else {
69 | holder.txt_seen.setText("Delivered");
70 | }
71 | } else {
72 | holder.txt_seen.setVisibility(View.GONE);
73 | }
74 |
75 | }
76 |
77 | @Override
78 | public int getItemCount() {
79 | return mChat.size();
80 | }
81 |
82 | public class ViewHolder extends RecyclerView.ViewHolder{
83 |
84 | public TextView show_message;
85 | public ImageView profile_image;
86 | public TextView txt_seen;
87 |
88 | public ViewHolder(View itemView) {
89 | super(itemView);
90 |
91 | show_message = itemView.findViewById(R.id.show_message);
92 | profile_image = itemView.findViewById(R.id.profile_image);
93 | txt_seen = itemView.findViewById(R.id.txt_seen);
94 | }
95 | }
96 |
97 | @Override
98 | public int getItemViewType(int position) {
99 | fuser = FirebaseAuth.getInstance().getCurrentUser();
100 | if (mChat.get(position).getSender().equals(fuser.getUid())){
101 | return MSG_TYPE_RIGHT;
102 | } else {
103 | return MSG_TYPE_LEFT;
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
21 |
22 |
27 |
28 |
38 |
39 |
40 |
41 |
49 |
50 |
51 |
52 |
72 |
73 |
74 |
75 |
85 |
86 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.appcompat.widget.Toolbar;
6 | import androidx.core.app.ActivityOptionsCompat;
7 |
8 | import android.app.ProgressDialog;
9 | import android.content.Intent;
10 | import android.os.Bundle;
11 | import android.text.TextUtils;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.google.android.gms.tasks.OnCompleteListener;
18 | import com.google.android.gms.tasks.Task;
19 | import com.google.firebase.auth.AuthResult;
20 | import com.google.firebase.auth.FirebaseAuth;
21 | import com.rengwuxian.materialedittext.MaterialEditText;
22 |
23 | public class LoginActivity extends AppCompatActivity {
24 |
25 | MaterialEditText email, password;
26 | Button btn_login;
27 |
28 | private ProgressDialog mLoginProgress;
29 |
30 | FirebaseAuth auth;
31 | TextView forgot_password;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_login);
37 |
38 | mLoginProgress = new ProgressDialog(this);
39 |
40 | auth = FirebaseAuth.getInstance();
41 |
42 | email = findViewById(R.id.email);
43 | password = findViewById(R.id.password);
44 | btn_login = findViewById(R.id.btn_login);
45 | forgot_password = findViewById(R.id.forgot_password);
46 |
47 | forgot_password.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View view) {
50 | Intent intent = new Intent(LoginActivity.this, ResetPasswordActivity.class);
51 |
52 | ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(LoginActivity.this,findViewById(R.id.forgot_password), "myLogin");
53 |
54 | startActivity(intent, optionsCompat.toBundle());
55 | }
56 | });
57 |
58 | btn_login.setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View view) {
61 | String txt_email = email.getText().toString();
62 | String txt_password = password.getText().toString();
63 |
64 | if (TextUtils.isEmpty(txt_email) || TextUtils.isEmpty(txt_password)){
65 | Toast.makeText(LoginActivity.this, "All fileds are required", Toast.LENGTH_SHORT).show();
66 |
67 | } else {
68 |
69 | mLoginProgress.setTitle("Logging In");
70 | mLoginProgress.setMessage("Please wait while we check your credentials.");
71 | mLoginProgress.setCanceledOnTouchOutside(false);
72 | mLoginProgress.show();
73 |
74 | auth.signInWithEmailAndPassword(txt_email, txt_password)
75 | .addOnCompleteListener(new OnCompleteListener() {
76 | @Override
77 | public void onComplete(@NonNull Task task) {
78 | if (task.isSuccessful()){
79 |
80 | mLoginProgress.dismiss();
81 | Intent intent = new Intent(LoginActivity.this, MainActivity.class);
82 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
83 | startActivity(intent);
84 | finish();
85 | } else {
86 |
87 | mLoginProgress.hide();
88 | Toast.makeText(LoginActivity.this, "Authentication failed!", Toast.LENGTH_SHORT).show();
89 | }
90 | }
91 | });
92 | }
93 | }
94 | });
95 | }
96 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Fragments/ChatsFragment.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Fragments;
2 |
3 |
4 | import android.os.Bundle;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.fragment.app.Fragment;
8 | import androidx.recyclerview.widget.LinearLayoutManager;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 |
15 | import com.dvlnitins.friends.Adapter.UserAdapter;
16 | import com.dvlnitins.friends.Model.Chatlist;
17 | import com.dvlnitins.friends.Model.User;
18 | import com.dvlnitins.friends.Notifications.Token;
19 | import com.dvlnitins.friends.R;
20 | import com.google.firebase.auth.FirebaseAuth;
21 | import com.google.firebase.auth.FirebaseUser;
22 | import com.google.firebase.database.DataSnapshot;
23 | import com.google.firebase.database.DatabaseError;
24 | import com.google.firebase.database.DatabaseReference;
25 | import com.google.firebase.database.FirebaseDatabase;
26 | import com.google.firebase.database.ValueEventListener;
27 | import com.google.firebase.iid.FirebaseInstanceId;
28 |
29 | import java.util.ArrayList;
30 | import java.util.List;
31 |
32 | public class ChatsFragment extends Fragment {
33 |
34 | private RecyclerView recyclerView;
35 |
36 | private UserAdapter userAdapter;
37 | private List mUsers;
38 |
39 | FirebaseUser fuser;
40 | DatabaseReference reference;
41 |
42 | private List usersList;
43 |
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
46 | Bundle savedInstanceState) {
47 | View view = inflater.inflate(R.layout.fragment_chats, container, false);
48 |
49 | recyclerView = view.findViewById(R.id.recycler_view);
50 | recyclerView.setHasFixedSize(true);
51 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
52 |
53 | fuser = FirebaseAuth.getInstance().getCurrentUser();
54 |
55 | usersList = new ArrayList<>();
56 |
57 | reference = FirebaseDatabase.getInstance().getReference("Chatlist").child(fuser.getUid());
58 | reference.keepSynced(true);
59 | reference.addValueEventListener(new ValueEventListener() {
60 | @Override
61 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
62 | usersList.clear();
63 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
64 | Chatlist chatlist = snapshot.getValue(Chatlist.class);
65 | usersList.add(chatlist);
66 | }
67 |
68 | chatList();
69 | }
70 |
71 | @Override
72 | public void onCancelled(@NonNull DatabaseError databaseError) {
73 |
74 | }
75 | });
76 |
77 | updateToken(FirebaseInstanceId.getInstance().getToken());
78 |
79 |
80 | return view;
81 | }
82 |
83 | private void updateToken(String token){
84 | DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
85 | Token token1 = new Token(token);
86 | reference.child(fuser.getUid()).setValue(token1);
87 | }
88 |
89 | private void chatList() {
90 | mUsers = new ArrayList<>();
91 | reference = FirebaseDatabase.getInstance().getReference("Users");
92 | reference.keepSynced(true);
93 | reference.addValueEventListener(new ValueEventListener() {
94 | @Override
95 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
96 | mUsers.clear();
97 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
98 | User user = snapshot.getValue(User.class);
99 | for (Chatlist chatlist : usersList){
100 | if (user.getId().equals(chatlist.getId())){
101 | mUsers.add(user);
102 | }
103 | }
104 | }
105 | userAdapter = new UserAdapter(getContext(), mUsers, true);
106 | recyclerView.setAdapter(userAdapter);
107 | }
108 |
109 | @Override
110 | public void onCancelled(@NonNull DatabaseError databaseError) {
111 |
112 | }
113 | });
114 | }
115 |
116 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Fragments/UsersFragment.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Fragments;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.fragment.app.Fragment;
9 | import androidx.recyclerview.widget.LinearLayoutManager;
10 | import androidx.recyclerview.widget.RecyclerView;
11 |
12 | import android.text.Editable;
13 | import android.text.TextWatcher;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.EditText;
18 |
19 | import com.dvlnitins.friends.Adapter.UserAdapter;
20 | import com.dvlnitins.friends.Model.User;
21 | import com.dvlnitins.friends.R;
22 | import com.google.firebase.auth.FirebaseAuth;
23 | import com.google.firebase.auth.FirebaseUser;
24 | import com.google.firebase.database.DataSnapshot;
25 | import com.google.firebase.database.DatabaseError;
26 | import com.google.firebase.database.DatabaseReference;
27 | import com.google.firebase.database.FirebaseDatabase;
28 | import com.google.firebase.database.Query;
29 | import com.google.firebase.database.ValueEventListener;
30 |
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 |
35 | public class UsersFragment extends Fragment {
36 |
37 | private RecyclerView recyclerView;
38 |
39 | private UserAdapter userAdapter;
40 | private List mUsers;
41 |
42 | EditText search_users;
43 |
44 |
45 | @Override
46 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
47 | Bundle savedInstanceState) {
48 |
49 | View view = inflater.inflate(R.layout.fragment_users, container, false);
50 |
51 | recyclerView = view.findViewById(R.id.recycler_view);
52 | recyclerView.setHasFixedSize(true);
53 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
54 |
55 | mUsers = new ArrayList<>();
56 |
57 | readUsers();
58 |
59 | search_users = view.findViewById(R.id.search_users);
60 | search_users.addTextChangedListener(new TextWatcher() {
61 | @Override
62 | public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
63 |
64 | }
65 |
66 | @Override
67 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
68 | searchUsers(charSequence.toString().toLowerCase());
69 | }
70 |
71 | @Override
72 | public void afterTextChanged(Editable editable) {
73 |
74 | }
75 | });
76 |
77 | return view;
78 | }
79 |
80 | private void searchUsers(String s) {
81 |
82 | final FirebaseUser fuser = FirebaseAuth.getInstance().getCurrentUser();
83 | Query query = FirebaseDatabase.getInstance().getReference("Users").orderByChild("search")
84 | .startAt(s)
85 | .endAt(s+"\uf8ff");
86 |
87 | query.addValueEventListener(new ValueEventListener() {
88 | @Override
89 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
90 | mUsers.clear();
91 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
92 | User user = snapshot.getValue(User.class);
93 |
94 | assert user != null;
95 | assert fuser != null;
96 | if (!user.getId().equals(fuser.getUid())){
97 | mUsers.add(user);
98 | }
99 | }
100 |
101 | userAdapter = new UserAdapter(getContext(), mUsers, false);
102 | recyclerView.setAdapter(userAdapter);
103 | }
104 |
105 | @Override
106 | public void onCancelled(@NonNull DatabaseError databaseError) {
107 |
108 | }
109 | });
110 |
111 | }
112 |
113 | private void readUsers() {
114 |
115 | final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
116 | DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users");
117 |
118 | reference.addValueEventListener(new ValueEventListener() {
119 | @Override
120 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
121 | if (search_users.getText().toString().equals("")) {
122 | mUsers.clear();
123 | for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
124 | User user = snapshot.getValue(User.class);
125 |
126 | if (!user.getId().equals(firebaseUser.getUid())) {
127 | mUsers.add(user);
128 | }
129 |
130 | }
131 |
132 | userAdapter = new UserAdapter(getContext(), mUsers, false);
133 | recyclerView.setAdapter(userAdapter);
134 | }
135 | }
136 |
137 | @Override
138 | public void onCancelled(@NonNull DatabaseError databaseError) {
139 |
140 | }
141 | });
142 | }
143 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/RegisterActivity.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.appcompat.widget.Toolbar;
6 |
7 |
8 | import android.app.ProgressDialog;
9 | import android.content.Intent;
10 | import android.os.Bundle;
11 | import android.text.TextUtils;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.Toast;
15 |
16 | import com.google.android.gms.tasks.OnCompleteListener;
17 | import com.google.android.gms.tasks.Task;
18 | import com.google.firebase.auth.AuthResult;
19 | import com.google.firebase.auth.FirebaseAuth;
20 | import com.google.firebase.auth.FirebaseUser;
21 | import com.google.firebase.database.DatabaseReference;
22 | import com.google.firebase.database.FirebaseDatabase;
23 | import com.rengwuxian.materialedittext.MaterialEditText;
24 |
25 | import java.util.HashMap;
26 |
27 | public class RegisterActivity extends AppCompatActivity {
28 |
29 | MaterialEditText username, email, password;
30 | Button btn_register;
31 |
32 | private ProgressDialog mRegProgress;
33 |
34 | FirebaseAuth auth;
35 | DatabaseReference reference;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_register);
41 |
42 | mRegProgress = new ProgressDialog(this);
43 |
44 | username = findViewById(R.id.username);
45 | email = findViewById(R.id.email);
46 | password = findViewById(R.id.password);
47 | btn_register = findViewById(R.id.btn_register);
48 |
49 | auth = FirebaseAuth.getInstance();
50 |
51 | btn_register.setOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View view) {
54 | String txt_username = username.getText().toString();
55 | String txt_email = email.getText().toString();
56 | String txt_password = password.getText().toString();
57 |
58 | if (TextUtils.isEmpty(txt_username) || TextUtils.isEmpty(txt_email) || TextUtils.isEmpty(txt_password)){
59 | Toast.makeText(RegisterActivity.this, "All fileds are required", Toast.LENGTH_SHORT).show();
60 | } else if (txt_password.length() < 6 ){
61 | Toast.makeText(RegisterActivity.this, "password must be at least 6 characters", Toast.LENGTH_SHORT).show();
62 | } else {
63 |
64 | mRegProgress.setTitle("Registering User");
65 | mRegProgress.setMessage("Please wait while we create your account !");
66 | mRegProgress.setCanceledOnTouchOutside(false);
67 | mRegProgress.show();
68 | register(txt_username, txt_email, txt_password);
69 | }
70 | }
71 | });
72 | }
73 |
74 | private void register(final String username, String email, String password){
75 |
76 | auth.createUserWithEmailAndPassword(email, password)
77 | .addOnCompleteListener(new OnCompleteListener() {
78 | @Override
79 | public void onComplete(@NonNull Task task) {
80 | if (task.isSuccessful()){
81 | FirebaseUser firebaseUser = auth.getCurrentUser();
82 | assert firebaseUser != null;
83 | String userid = firebaseUser.getUid();
84 |
85 | reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
86 |
87 | HashMap hashMap = new HashMap<>();
88 | hashMap.put("id", userid);
89 | hashMap.put("username", username);
90 | hashMap.put("imageURL", "default");
91 | hashMap.put("status", "offline");
92 | hashMap.put("search", username.toLowerCase());
93 |
94 | reference.setValue(hashMap).addOnCompleteListener(new OnCompleteListener() {
95 | @Override
96 | public void onComplete(@NonNull Task task) {
97 | if (task.isSuccessful()){
98 |
99 | mRegProgress.dismiss();
100 | Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
101 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
102 | startActivity(intent);
103 | finish();
104 | }
105 | }
106 | });
107 | } else {
108 | mRegProgress.hide();
109 | Toast.makeText(RegisterActivity.this, "You can't register with this email or password", Toast.LENGTH_SHORT).show();
110 | }
111 | }
112 | });
113 | }
114 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Notifications/MyFirebaseMessaging.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Notifications;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.core.app.NotificationCompat;
5 |
6 | import android.app.Notification;
7 | import android.app.NotificationManager;
8 | import android.app.PendingIntent;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.content.SharedPreferences;
12 | import android.media.RingtoneManager;
13 | import android.net.Uri;
14 | import android.os.Build;
15 | import android.os.Bundle;
16 |
17 | import com.dvlnitins.friends.MessageActivity;
18 | import com.google.firebase.auth.FirebaseAuth;
19 | import com.google.firebase.auth.FirebaseUser;
20 | import com.google.firebase.database.DatabaseReference;
21 | import com.google.firebase.database.FirebaseDatabase;
22 | import com.google.firebase.iid.FirebaseInstanceId;
23 | import com.google.firebase.messaging.FirebaseMessagingService;
24 | import com.google.firebase.messaging.RemoteMessage;
25 |
26 | public class MyFirebaseMessaging extends FirebaseMessagingService {
27 |
28 | @Override
29 | public void onNewToken(String s) {
30 | super.onNewToken(s);
31 | String refreshToken = FirebaseInstanceId.getInstance().getInstanceId().getResult().getToken();
32 | if (refreshToken != null){
33 | updateToken(refreshToken);
34 | }
35 | }
36 |
37 | private void updateToken(String refreshToken) {
38 | if (FirebaseAuth.getInstance().getCurrentUser() != null){
39 | FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
40 |
41 | DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
42 | Token token = new Token(refreshToken);
43 | reference.child(firebaseUser.getUid()).setValue(token);
44 | }
45 | }
46 |
47 | @Override
48 | public void onMessageReceived(RemoteMessage remoteMessage) {
49 | super.onMessageReceived(remoteMessage);
50 |
51 | String sented = remoteMessage.getData().get("sented");
52 | String user = remoteMessage.getData().get("user");
53 |
54 | SharedPreferences preferences = getSharedPreferences("PREFS", MODE_PRIVATE);
55 | String currentUser = preferences.getString("currentuser", "none");
56 |
57 | FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
58 |
59 | if (firebaseUser != null && sented.equals(firebaseUser.getUid())){
60 | if (!currentUser.equals(user)) {
61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
62 | sendOreoNotification(remoteMessage);
63 | } else {
64 | sendNotification(remoteMessage);
65 | }
66 | }
67 | }
68 | }
69 |
70 | private void sendOreoNotification(RemoteMessage remoteMessage){
71 | String user = remoteMessage.getData().get("user");
72 | String icon = remoteMessage.getData().get("icon");
73 | String title = remoteMessage.getData().get("title");
74 | String body = remoteMessage.getData().get("body");
75 |
76 | RemoteMessage.Notification notification = remoteMessage.getNotification();
77 | int j = Integer.parseInt(user.replaceAll("[\\D]", ""));
78 | Intent intent = new Intent(this, MessageActivity.class);
79 | Bundle bundle = new Bundle();
80 | bundle.putString("userid", user);
81 | intent.putExtras(bundle);
82 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
83 | PendingIntent pendingIntent = PendingIntent.getActivity(this, j, intent, PendingIntent.FLAG_ONE_SHOT);
84 | Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
85 |
86 | OreoNotification oreoNotification = new OreoNotification(this);
87 | Notification.Builder builder = oreoNotification.getOreoNotification(title, body, pendingIntent,
88 | defaultSound, icon);
89 |
90 | int i = 0;
91 | if (j > 0){
92 | i = j;
93 | }
94 |
95 | oreoNotification.getManager().notify(i, builder.build());
96 |
97 | }
98 |
99 | private void sendNotification(RemoteMessage remoteMessage) {
100 |
101 | String user = remoteMessage.getData().get("user");
102 | String icon = remoteMessage.getData().get("icon");
103 | String title = remoteMessage.getData().get("title");
104 | String body = remoteMessage.getData().get("body");
105 |
106 | RemoteMessage.Notification notification = remoteMessage.getNotification();
107 | int j = Integer.parseInt(user.replaceAll("[\\D]", ""));
108 | Intent intent = new Intent(this, MessageActivity.class);
109 | Bundle bundle = new Bundle();
110 | bundle.putString("userid", user);
111 | intent.putExtras(bundle);
112 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
113 | PendingIntent pendingIntent = PendingIntent.getActivity(this, j, intent, PendingIntent.FLAG_ONE_SHOT);
114 |
115 | Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
116 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
117 | .setSmallIcon(Integer.parseInt(icon))
118 | .setContentTitle(title)
119 | .setContentText(body)
120 | .setAutoCancel(true)
121 | .setSound(defaultSound)
122 | .setContentIntent(pendingIntent);
123 | NotificationManager noti = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
124 |
125 | int i = 0;
126 | if (j > 0){
127 | i = j;
128 | }
129 |
130 | noti.notify(i, builder.build());
131 | }
132 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Adapter/UserAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Adapter;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.recyclerview.widget.RecyclerView;
6 |
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.os.Bundle;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import com.bumptech.glide.Glide;
17 | import com.dvlnitins.friends.MessageActivity;
18 | import com.dvlnitins.friends.Model.Chat;
19 | import com.dvlnitins.friends.Model.User;
20 | import com.dvlnitins.friends.R;
21 | import com.google.firebase.auth.FirebaseAuth;
22 | import com.google.firebase.auth.FirebaseUser;
23 | import com.google.firebase.database.DataSnapshot;
24 | import com.google.firebase.database.DatabaseError;
25 | import com.google.firebase.database.DatabaseReference;
26 | import com.google.firebase.database.FirebaseDatabase;
27 | import com.google.firebase.database.ValueEventListener;
28 |
29 | import java.util.List;
30 |
31 | public class UserAdapter extends RecyclerView.Adapter {
32 |
33 | private Context mContext;
34 | private List mUsers;
35 | private boolean ischat;
36 |
37 | String theLastMessage;
38 |
39 | public UserAdapter(Context mContext, List mUsers, boolean ischat){
40 | this.mUsers = mUsers;
41 | this.mContext = mContext;
42 | this.ischat = ischat;
43 | }
44 |
45 | @NonNull
46 | @Override
47 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
48 | View view = LayoutInflater.from(mContext).inflate(R.layout.user_item, parent, false);
49 | return new UserAdapter.ViewHolder(view);
50 | }
51 |
52 | @Override
53 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
54 |
55 | final User user = mUsers.get(position);
56 | holder.username.setText(user.getUsername());
57 | if (user.getImageURL().equals("default")){
58 | holder.profile_image.setImageResource(R.drawable.default_avatar);
59 | } else {
60 | Glide.with(mContext).load(user.getImageURL()).into(holder.profile_image);
61 | }
62 |
63 | if (ischat){
64 | lastMessage(user.getId(), holder.last_msg);
65 | } else {
66 | holder.last_msg.setVisibility(View.GONE);
67 | }
68 |
69 | if (ischat){
70 | if (user.getStatus().equals("online")){
71 | holder.img_on.setVisibility(View.VISIBLE);
72 | holder.img_off.setVisibility(View.GONE);
73 | } else {
74 | holder.img_on.setVisibility(View.GONE);
75 | holder.img_off.setVisibility(View.VISIBLE);
76 | }
77 | } else {
78 | holder.img_on.setVisibility(View.GONE);
79 | holder.img_off.setVisibility(View.GONE);
80 | }
81 |
82 | holder.itemView.setOnClickListener(new View.OnClickListener() {
83 | @Override
84 | public void onClick(View view) {
85 | Intent intent = new Intent(mContext, MessageActivity.class);
86 | intent.putExtra("userid", user.getId());
87 | mContext.startActivity(intent);
88 | }
89 | });
90 | }
91 |
92 | @Override
93 | public int getItemCount() {
94 | return mUsers.size();
95 | }
96 |
97 | public class ViewHolder extends RecyclerView.ViewHolder{
98 |
99 | public TextView username;
100 | public ImageView profile_image;
101 | private ImageView img_on;
102 | private ImageView img_off;
103 | private TextView last_msg;
104 |
105 | public ViewHolder(View itemView) {
106 | super(itemView);
107 |
108 | username = itemView.findViewById(R.id.username);
109 | profile_image = itemView.findViewById(R.id.profile_image);
110 | img_on = itemView.findViewById(R.id.img_on);
111 | img_off = itemView.findViewById(R.id.img_off);
112 | last_msg = itemView.findViewById(R.id.last_msg);
113 | }
114 | }
115 |
116 | //check for last message
117 | private void lastMessage(final String userid, final TextView last_msg){
118 | theLastMessage = "default";
119 | final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
120 | DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Chats");
121 |
122 | reference.addValueEventListener(new ValueEventListener() {
123 | @Override
124 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
125 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
126 | Chat chat = snapshot.getValue(Chat.class);
127 | if (firebaseUser != null && chat != null) {
128 | if (chat.getReceiver().equals(firebaseUser.getUid()) && chat.getSender().equals(userid) ||
129 | chat.getReceiver().equals(userid) && chat.getSender().equals(firebaseUser.getUid())) {
130 | theLastMessage = chat.getMessage();
131 | }
132 | }
133 | }
134 |
135 | switch (theLastMessage){
136 | case "default":
137 | last_msg.setText("No Message");
138 | break;
139 |
140 | default:
141 | last_msg.setText(theLastMessage);
142 | break;
143 | }
144 |
145 | theLastMessage = "default";
146 | }
147 |
148 | @Override
149 | public void onCancelled(@NonNull DatabaseError databaseError) {
150 |
151 | }
152 | });
153 | }
154 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/Fragments/ProfileFragment.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends.Fragments;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.ContentResolver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.fragment.app.Fragment;
12 |
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.webkit.MimeTypeMap;
17 | import android.widget.TextView;
18 | import android.widget.Toast;
19 |
20 | import com.bumptech.glide.Glide;
21 | import com.dvlnitins.friends.Model.User;
22 | import com.dvlnitins.friends.R;
23 | import com.google.android.gms.tasks.Continuation;
24 | import com.google.android.gms.tasks.OnCompleteListener;
25 | import com.google.android.gms.tasks.OnFailureListener;
26 | import com.google.android.gms.tasks.Task;
27 | import com.google.firebase.auth.FirebaseAuth;
28 | import com.google.firebase.auth.FirebaseUser;
29 | import com.google.firebase.database.DataSnapshot;
30 | import com.google.firebase.database.DatabaseError;
31 | import com.google.firebase.database.DatabaseReference;
32 | import com.google.firebase.database.FirebaseDatabase;
33 | import com.google.firebase.database.ValueEventListener;
34 | import com.google.firebase.storage.FirebaseStorage;
35 | import com.google.firebase.storage.StorageReference;
36 | import com.google.firebase.storage.StorageTask;
37 | import com.google.firebase.storage.UploadTask;
38 |
39 | import java.util.HashMap;
40 |
41 | import de.hdodenhof.circleimageview.CircleImageView;
42 |
43 | import static android.app.Activity.RESULT_OK;
44 |
45 | public class ProfileFragment extends Fragment {
46 |
47 | CircleImageView image_profile;
48 | TextView username;
49 |
50 | DatabaseReference reference;
51 | FirebaseUser fuser;
52 |
53 | StorageReference storageReference;
54 | private static final int IMAGE_REQUEST = 1;
55 | private Uri imageUri;
56 | private StorageTask uploadTask;
57 |
58 |
59 | @Override
60 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
61 | Bundle savedInstanceState) {
62 | // Inflate the layout for this fragment
63 | View view = inflater.inflate(R.layout.fragment_profile, container, false);
64 |
65 | image_profile = view.findViewById(R.id.profile_image);
66 | username = view.findViewById(R.id.username);
67 |
68 | storageReference = FirebaseStorage.getInstance().getReference("uploads");
69 |
70 | fuser = FirebaseAuth.getInstance().getCurrentUser();
71 | reference = FirebaseDatabase.getInstance().getReference("Users").child(fuser.getUid());
72 | reference.keepSynced(true);
73 |
74 | reference.addValueEventListener(new ValueEventListener() {
75 | @Override
76 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
77 | User user = dataSnapshot.getValue(User.class);
78 | username.setText(user.getUsername());
79 | if (user.getImageURL().equals("default")){
80 | image_profile.setImageResource(R.drawable.default_avatar);
81 | } else {
82 | Glide.with(getContext()).load(user.getImageURL()).into(image_profile);
83 | }
84 | }
85 |
86 | @Override
87 | public void onCancelled(@NonNull DatabaseError databaseError) {
88 |
89 | }
90 | });
91 |
92 | image_profile.setOnClickListener(new View.OnClickListener() {
93 | @Override
94 | public void onClick(View view) {
95 | openImage();
96 | }
97 | });
98 |
99 | return view;
100 | }
101 |
102 | private void openImage() {
103 | Intent intent = new Intent();
104 | intent.setType("image/*");
105 | intent.setAction(Intent.ACTION_GET_CONTENT);
106 | startActivityForResult(intent, IMAGE_REQUEST);
107 | }
108 |
109 | private String getFileExtension(Uri uri){
110 | ContentResolver contentResolver = getContext().getContentResolver();
111 | MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
112 | return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));
113 | }
114 |
115 | private void uploadImage(){
116 | final ProgressDialog pd = new ProgressDialog(getContext());
117 | pd.setMessage("Uploading");
118 | pd.show();
119 |
120 | if (imageUri != null){
121 | final StorageReference fileReference = storageReference.child(System.currentTimeMillis()
122 | +"."+getFileExtension(imageUri));
123 |
124 | uploadTask = fileReference.putFile(imageUri);
125 | uploadTask.continueWithTask(new Continuation>() {
126 | @Override
127 | public Task then(@NonNull Task task) throws Exception {
128 | if (!task.isSuccessful()){
129 | throw task.getException();
130 | }
131 |
132 | return fileReference.getDownloadUrl();
133 | }
134 | }).addOnCompleteListener(new OnCompleteListener() {
135 | @Override
136 | public void onComplete(@NonNull Task task) {
137 | if (task.isSuccessful()){
138 | Uri downloadUri = task.getResult();
139 | String mUri = downloadUri.toString();
140 |
141 | reference = FirebaseDatabase.getInstance().getReference("Users").child(fuser.getUid());
142 | HashMap map = new HashMap<>();
143 | map.put("imageURL", ""+mUri);
144 | reference.updateChildren(map);
145 |
146 | pd.dismiss();
147 | } else {
148 | Toast.makeText(getContext(), "Failed!", Toast.LENGTH_SHORT).show();
149 | pd.dismiss();
150 | }
151 | }
152 | }).addOnFailureListener(new OnFailureListener() {
153 | @Override
154 | public void onFailure(@NonNull Exception e) {
155 | Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
156 | pd.dismiss();
157 | }
158 | });
159 | } else {
160 | Toast.makeText(getContext(), "No image selected", Toast.LENGTH_SHORT).show();
161 | }
162 | }
163 |
164 | @Override
165 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
166 | super.onActivityResult(requestCode, resultCode, data);
167 |
168 | if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK
169 | && data != null && data.getData() != null){
170 | imageUri = data.getData();
171 |
172 | if (uploadTask != null && uploadTask.isInProgress()){
173 | Toast.makeText(getContext(), "Upload in preogress", Toast.LENGTH_SHORT).show();
174 | } else {
175 | uploadImage();
176 | }
177 | }
178 | }
179 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.annotation.Nullable;
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import androidx.appcompat.widget.Toolbar;
7 | import androidx.core.content.ContextCompat;
8 | import androidx.fragment.app.Fragment;
9 | import androidx.fragment.app.FragmentManager;
10 | import androidx.fragment.app.FragmentPagerAdapter;
11 | import androidx.viewpager.widget.ViewPager;
12 |
13 | import android.content.Intent;
14 | import android.os.Bundle;
15 | import android.view.Menu;
16 | import android.view.MenuItem;
17 | import android.view.View;
18 | import android.view.Window;
19 | import android.view.WindowManager;
20 | import android.widget.Button;
21 | import android.widget.TextView;
22 |
23 | import com.bumptech.glide.Glide;
24 | import com.dvlnitins.friends.Fragments.ChatsFragment;
25 | import com.dvlnitins.friends.Fragments.ProfileFragment;
26 | import com.dvlnitins.friends.Fragments.UsersFragment;
27 | import com.dvlnitins.friends.Model.Chat;
28 | import com.dvlnitins.friends.Model.User;
29 | import com.google.android.material.tabs.TabLayout;
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.ArrayList;
39 | import java.util.HashMap;
40 |
41 | import de.hdodenhof.circleimageview.CircleImageView;
42 |
43 | public class MainActivity extends AppCompatActivity {
44 |
45 | CircleImageView profile_image;
46 | TextView username;
47 |
48 | Button logout;
49 |
50 | FirebaseUser firebaseUser;
51 | DatabaseReference reference;
52 |
53 | @Override
54 | protected void onCreate(Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setContentView(R.layout.activity_main);
57 |
58 |
59 | Window window = MainActivity.this.getWindow();
60 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
61 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
62 | window.setStatusBarColor(ContextCompat.getColor(MainActivity.this, R.color.matteBlack));
63 |
64 | Button logout= (Button) findViewById(R.id.btn_logout);
65 | logout.setOnClickListener(new View.OnClickListener() {
66 | @Override
67 | public void onClick(View view) {
68 |
69 | FirebaseAuth.getInstance().signOut();
70 | startActivity(new Intent(MainActivity.this, StartActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
71 | finish();
72 | }
73 | });
74 |
75 | Toolbar toolbar = findViewById(R.id.toolbar);
76 | setSupportActionBar(toolbar);
77 |
78 | profile_image = findViewById(R.id.profile_image);
79 | username = findViewById(R.id.username);
80 |
81 | firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
82 | reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
83 | reference.keepSynced(true);
84 |
85 | reference.addValueEventListener(new ValueEventListener() {
86 | @Override
87 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
88 | User user = dataSnapshot.getValue(User.class);
89 | username.setText(user.getUsername());
90 | if (user.getImageURL().equals("default")){
91 | profile_image.setImageResource(R.drawable.default_avatar);
92 | } else {
93 |
94 | //change this
95 | Glide.with(getApplicationContext()).load(user.getImageURL()).into(profile_image);
96 | }
97 | }
98 |
99 | @Override
100 | public void onCancelled(@NonNull DatabaseError databaseError) {
101 |
102 | }
103 | });
104 |
105 | final TabLayout tabLayout = findViewById(R.id.tab_layout);
106 | final ViewPager viewPager = findViewById(R.id.view_pager);
107 |
108 |
109 | reference = FirebaseDatabase.getInstance().getReference("Chats");
110 | reference.keepSynced(true);
111 | reference.addValueEventListener(new ValueEventListener() {
112 | @Override
113 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
114 | ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
115 | int unread = 0;
116 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
117 | Chat chat = snapshot.getValue(Chat.class);
118 | if (chat.getReceiver().equals(firebaseUser.getUid()) && !chat.isIsseen()){
119 | unread++;
120 | }
121 | }
122 |
123 | if (unread == 0){
124 | viewPagerAdapter.addFragment(new ChatsFragment(), "Chats");
125 | } else {
126 | viewPagerAdapter.addFragment(new ChatsFragment(), "("+unread+") Chats");
127 | }
128 |
129 | viewPagerAdapter.addFragment(new UsersFragment(), "Users");
130 | viewPagerAdapter.addFragment(new ProfileFragment(), "Profile");
131 |
132 | viewPager.setAdapter(viewPagerAdapter);
133 |
134 | tabLayout.setupWithViewPager(viewPager);
135 |
136 | }
137 |
138 | @Override
139 | public void onCancelled(@NonNull DatabaseError databaseError) {
140 |
141 | }
142 | });
143 |
144 |
145 | }
146 |
147 |
148 |
149 |
150 |
151 | /*
152 | @Override
153 | public boolean onCreateOptionsMenu(Menu menu) {
154 | getMenuInflater().inflate(R.menu.menu, menu);
155 | return true;
156 | }
157 |
158 | @Override
159 | public boolean onOptionsItemSelected(MenuItem item) {
160 | switch (item.getItemId()){
161 |
162 | case R.id.btn_logout:
163 | FirebaseAuth.getInstance().signOut();
164 | startActivity(new Intent(MainActivity.this, StartActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
165 | return true;
166 | }
167 |
168 | return false;
169 | }
170 |
171 | */
172 |
173 | class ViewPagerAdapter extends FragmentPagerAdapter {
174 |
175 | private ArrayList fragments;
176 | private ArrayList titles;
177 |
178 | ViewPagerAdapter(FragmentManager fm){
179 | super(fm);
180 | this.fragments = new ArrayList<>();
181 | this.titles = new ArrayList<>();
182 | }
183 |
184 | @Override
185 | public Fragment getItem(int position) {
186 | return fragments.get(position);
187 | }
188 |
189 | @Override
190 | public int getCount() {
191 | return fragments.size();
192 | }
193 |
194 | public void addFragment(Fragment fragment, String title){
195 | fragments.add(fragment);
196 | titles.add(title);
197 | }
198 |
199 | // Ctrl + O
200 |
201 | @Nullable
202 | @Override
203 | public CharSequence getPageTitle(int position) {
204 | return titles.get(position);
205 | }
206 | }
207 |
208 | private void status(String status){
209 | reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
210 |
211 | HashMap hashMap = new HashMap<>();
212 | hashMap.put("status", status);
213 |
214 | reference.updateChildren(hashMap);
215 | }
216 |
217 | @Override
218 | protected void onResume() {
219 | super.onResume();
220 | status("online");
221 | }
222 |
223 | @Override
224 | protected void onPause() {
225 | super.onPause();
226 | status("offline");
227 | }
228 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dvlnitins/friends/MessageActivity.java:
--------------------------------------------------------------------------------
1 | package com.dvlnitins.friends;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.appcompat.widget.Toolbar;
6 | import androidx.core.content.ContextCompat;
7 | import androidx.recyclerview.widget.LinearLayoutManager;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import android.content.Intent;
11 | import android.content.SharedPreferences;
12 | import android.os.Bundle;
13 | import android.view.View;
14 | import android.view.Window;
15 | import android.view.WindowManager;
16 | import android.widget.EditText;
17 | import android.widget.ImageButton;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import com.bumptech.glide.Glide;
22 | import com.dvlnitins.friends.Adapter.MessageAdapter;
23 | import com.dvlnitins.friends.Fragments.APIService;
24 | import com.dvlnitins.friends.Model.Chat;
25 | import com.dvlnitins.friends.Model.User;
26 | import com.dvlnitins.friends.Notifications.Client;
27 | import com.dvlnitins.friends.Notifications.Data;
28 | import com.dvlnitins.friends.Notifications.MyResponse;
29 | import com.dvlnitins.friends.Notifications.Sender;
30 | import com.dvlnitins.friends.Notifications.Token;
31 | import com.google.firebase.auth.FirebaseAuth;
32 | import com.google.firebase.auth.FirebaseUser;
33 | import com.google.firebase.database.DataSnapshot;
34 | import com.google.firebase.database.DatabaseError;
35 | import com.google.firebase.database.DatabaseReference;
36 | import com.google.firebase.database.FirebaseDatabase;
37 | import com.google.firebase.database.Query;
38 | import com.google.firebase.database.ValueEventListener;
39 |
40 | import java.util.ArrayList;
41 | import java.util.HashMap;
42 | import java.util.List;
43 |
44 | import de.hdodenhof.circleimageview.CircleImageView;
45 | import retrofit2.Call;
46 | import retrofit2.Callback;
47 | import retrofit2.Response;
48 |
49 | public class MessageActivity extends AppCompatActivity {
50 |
51 | CircleImageView profile_image;
52 | TextView username;
53 |
54 | FirebaseUser fuser;
55 | DatabaseReference reference;
56 |
57 | ImageButton btn_send;
58 | EditText text_send;
59 |
60 | MessageAdapter messageAdapter;
61 | List mchat;
62 |
63 | RecyclerView recyclerView;
64 |
65 | Intent intent;
66 |
67 | ValueEventListener seenListener;
68 |
69 | String userid;
70 |
71 | APIService apiService;
72 |
73 | boolean notify = false;
74 |
75 | @Override
76 | protected void onCreate(Bundle savedInstanceState) {
77 | super.onCreate(savedInstanceState);
78 | setContentView(R.layout.activity_message);
79 |
80 |
81 | Window window = MessageActivity.this.getWindow();
82 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
83 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
84 | window.setStatusBarColor(ContextCompat.getColor(MessageActivity.this, R.color.matteBlack));
85 |
86 |
87 | apiService = Client.getClient("https://fcm.googleapis.com/").create(APIService.class);
88 |
89 | recyclerView = findViewById(R.id.recycler_view);
90 | recyclerView.setHasFixedSize(true);
91 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
92 | linearLayoutManager.setStackFromEnd(true);
93 | recyclerView.setLayoutManager(linearLayoutManager);
94 |
95 | profile_image = findViewById(R.id.profile_image);
96 | username = findViewById(R.id.username);
97 | btn_send = findViewById(R.id.btn_send);
98 | text_send = findViewById(R.id.text_send);
99 |
100 | intent = getIntent();
101 | userid = intent.getStringExtra("userid");
102 | fuser = FirebaseAuth.getInstance().getCurrentUser();
103 |
104 | btn_send.setOnClickListener(new View.OnClickListener() {
105 | @Override
106 | public void onClick(View view) {
107 | notify = true;
108 | String msg = text_send.getText().toString();
109 | if (!msg.equals("")){
110 | sendMessage(fuser.getUid(), userid, msg);
111 | } else {
112 | Toast.makeText(MessageActivity.this, "You can't send empty message", Toast.LENGTH_SHORT).show();
113 | }
114 | text_send.setText("");
115 | }
116 | });
117 |
118 |
119 | reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
120 |
121 | reference.addValueEventListener(new ValueEventListener() {
122 | @Override
123 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
124 | User user = dataSnapshot.getValue(User.class);
125 | username.setText(user.getUsername());
126 | if (user.getImageURL().equals("default")){
127 | profile_image.setImageResource(R.drawable.default_avatar);
128 | } else {
129 | //and this
130 | Glide.with(getApplicationContext()).load(user.getImageURL()).into(profile_image);
131 | }
132 |
133 | readMesagges(fuser.getUid(), userid, user.getImageURL());
134 | }
135 |
136 | @Override
137 | public void onCancelled(@NonNull DatabaseError databaseError) {
138 |
139 | }
140 | });
141 |
142 | seenMessage(userid);
143 | }
144 |
145 | private void seenMessage(final String userid){
146 | reference = FirebaseDatabase.getInstance().getReference("Chats");
147 | seenListener = reference.addValueEventListener(new ValueEventListener() {
148 | @Override
149 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
150 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
151 | Chat chat = snapshot.getValue(Chat.class);
152 | if (chat.getReceiver().equals(fuser.getUid()) && chat.getSender().equals(userid)){
153 | HashMap hashMap = new HashMap<>();
154 | hashMap.put("isseen", true);
155 | snapshot.getRef().updateChildren(hashMap);
156 | }
157 | }
158 | }
159 |
160 | @Override
161 | public void onCancelled(@NonNull DatabaseError databaseError) {
162 |
163 | }
164 | });
165 | }
166 |
167 | private void sendMessage(String sender, final String receiver, String message){
168 |
169 | DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
170 |
171 | HashMap hashMap = new HashMap<>();
172 | hashMap.put("sender", sender);
173 | hashMap.put("receiver", receiver);
174 | hashMap.put("message", message);
175 | hashMap.put("isseen", false);
176 |
177 | reference.child("Chats").push().setValue(hashMap);
178 |
179 |
180 | // add user to chat fragment
181 | final DatabaseReference chatRef = FirebaseDatabase.getInstance().getReference("Chatlist")
182 | .child(fuser.getUid())
183 | .child(userid);
184 |
185 | chatRef.addListenerForSingleValueEvent(new ValueEventListener() {
186 | @Override
187 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
188 | if (!dataSnapshot.exists()){
189 | chatRef.child("id").setValue(userid);
190 | }
191 | }
192 |
193 | @Override
194 | public void onCancelled(@NonNull DatabaseError databaseError) {
195 |
196 | }
197 | });
198 |
199 | final DatabaseReference chatRefReceiver = FirebaseDatabase.getInstance().getReference("Chatlist")
200 | .child(userid)
201 | .child(fuser.getUid());
202 | chatRefReceiver.child("id").setValue(fuser.getUid());
203 |
204 | final String msg = message;
205 |
206 | reference = FirebaseDatabase.getInstance().getReference("Users").child(fuser.getUid());
207 | reference.addValueEventListener(new ValueEventListener() {
208 | @Override
209 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
210 | User user = dataSnapshot.getValue(User.class);
211 | if (notify) {
212 | sendNotifiaction(receiver, user.getUsername(), msg);
213 | }
214 | notify = false;
215 | }
216 |
217 | @Override
218 | public void onCancelled(@NonNull DatabaseError databaseError) {
219 |
220 | }
221 | });
222 | }
223 |
224 | private void sendNotifiaction(String receiver, final String username, final String message){
225 | DatabaseReference tokens = FirebaseDatabase.getInstance().getReference("Tokens");
226 | Query query = tokens.orderByKey().equalTo(receiver);
227 | query.addValueEventListener(new ValueEventListener() {
228 | @Override
229 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
230 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
231 | Token token = snapshot.getValue(Token.class);
232 | Data data = new Data(fuser.getUid(), R.drawable.default_avatar, username+": "+message, "New Message",
233 | userid);
234 |
235 | Sender sender = new Sender(data, token.getToken());
236 |
237 | apiService.sendNotification(sender)
238 | .enqueue(new Callback() {
239 | @Override
240 | public void onResponse(Call call, Response response) {
241 | if (response.code() == 200){
242 | if (response.body().success != 1){
243 | Toast.makeText(MessageActivity.this, "Failed!", Toast.LENGTH_SHORT).show();
244 | }
245 | }
246 | }
247 |
248 | @Override
249 | public void onFailure(Call call, Throwable t) {
250 |
251 | }
252 | });
253 | }
254 | }
255 |
256 | @Override
257 | public void onCancelled(@NonNull DatabaseError databaseError) {
258 |
259 | }
260 | });
261 | }
262 |
263 | private void readMesagges(final String myid, final String userid, final String imageurl){
264 | mchat = new ArrayList<>();
265 |
266 | reference = FirebaseDatabase.getInstance().getReference("Chats");
267 | reference.addValueEventListener(new ValueEventListener() {
268 | @Override
269 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
270 | mchat.clear();
271 | for (DataSnapshot snapshot : dataSnapshot.getChildren()){
272 | Chat chat = snapshot.getValue(Chat.class);
273 | if (chat.getReceiver().equals(myid) && chat.getSender().equals(userid) ||
274 | chat.getReceiver().equals(userid) && chat.getSender().equals(myid)){
275 | mchat.add(chat);
276 | }
277 |
278 | messageAdapter = new MessageAdapter(MessageActivity.this, mchat, imageurl);
279 | recyclerView.setAdapter(messageAdapter);
280 | }
281 | }
282 |
283 | @Override
284 | public void onCancelled(@NonNull DatabaseError databaseError) {
285 |
286 | }
287 | });
288 | }
289 |
290 | private void currentUser(String userid){
291 | SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();
292 | editor.putString("currentuser", userid);
293 | editor.apply();
294 | }
295 |
296 | private void status(String status){
297 | reference = FirebaseDatabase.getInstance().getReference("Users").child(fuser.getUid());
298 |
299 | HashMap hashMap = new HashMap<>();
300 | hashMap.put("status", status);
301 |
302 | reference.updateChildren(hashMap);
303 | }
304 |
305 | @Override
306 | protected void onResume() {
307 | super.onResume();
308 | status("online");
309 | currentUser(userid);
310 | }
311 |
312 | @Override
313 | protected void onPause() {
314 | super.onPause();
315 | reference.removeEventListener(seenListener);
316 | status("offline");
317 | currentUser("none");
318 | }
319 | }
--------------------------------------------------------------------------------