users) {
34 | mView.onGetAllUsersSuccess(users);
35 | }
36 |
37 | @Override
38 | public void onGetAllUsersFailure(String message) {
39 | mView.onGetAllUsersFailure(message);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/events/PushNotificationEvent.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.events;
2 |
3 | /**
4 | * Author: Kartik Sharma
5 | * Created on: 10/18/2016 , 10:16 PM
6 | * Project: FirebaseChat
7 | */
8 |
9 | public class PushNotificationEvent {
10 | private String title;
11 | private String message;
12 | private String username;
13 | private String uid;
14 | private String fcmToken;
15 |
16 | public PushNotificationEvent() {
17 | }
18 |
19 | public PushNotificationEvent(String title, String message, String username, String uid, String fcmToken) {
20 | this.title = title;
21 | this.message = message;
22 | this.username = username;
23 | this.uid = uid;
24 | this.fcmToken = fcmToken;
25 | }
26 |
27 | public String getTitle() {
28 | return title;
29 | }
30 |
31 | public void setTitle(String title) {
32 | this.title = title;
33 | }
34 |
35 | public String getMessage() {
36 | return message;
37 | }
38 |
39 | public void setMessage(String message) {
40 | this.message = message;
41 | }
42 |
43 | public String getUsername() {
44 | return username;
45 | }
46 |
47 | public void setUsername(String username) {
48 | this.username = username;
49 | }
50 |
51 | public String getUid() {
52 | return uid;
53 | }
54 |
55 | public void setUid(String uid) {
56 | this.uid = uid;
57 | }
58 |
59 | public String getFcmToken() {
60 | return fcmToken;
61 | }
62 |
63 | public void setFcmToken(String fcmToken) {
64 | this.fcmToken = fcmToken;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/fcm/FcmNotificationBuilder.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.fcm;
2 |
3 | import android.util.Log;
4 |
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.io.IOException;
9 |
10 | import okhttp3.Call;
11 | import okhttp3.Callback;
12 | import okhttp3.MediaType;
13 | import okhttp3.OkHttpClient;
14 | import okhttp3.Request;
15 | import okhttp3.RequestBody;
16 | import okhttp3.Response;
17 |
18 | /**
19 | * Author: Kartik Sharma
20 | * Created on: 10/16/2016 , 1:53 PM
21 | * Project: FirebaseChat
22 | */
23 |
24 | public class FcmNotificationBuilder {
25 | public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
26 | private static final String TAG = "FcmNotificationBuilder";
27 | private static final String SERVER_API_KEY = "YOUR_SERVER_API_KEY";
28 | private static final String CONTENT_TYPE = "Content-Type";
29 | private static final String APPLICATION_JSON = "application/json";
30 | private static final String AUTHORIZATION = "Authorization";
31 | private static final String AUTH_KEY = "key=" + SERVER_API_KEY;
32 | private static final String FCM_URL = "https://fcm.googleapis.com/fcm/send";
33 | // json related keys
34 | private static final String KEY_TO = "to";
35 | private static final String KEY_NOTIFICATION = "notification";
36 | private static final String KEY_TITLE = "title";
37 | private static final String KEY_TEXT = "text";
38 | private static final String KEY_DATA = "data";
39 | private static final String KEY_USERNAME = "username";
40 | private static final String KEY_UID = "uid";
41 | private static final String KEY_FCM_TOKEN = "fcm_token";
42 |
43 | private String mTitle;
44 | private String mMessage;
45 | private String mUsername;
46 | private String mUid;
47 | private String mFirebaseToken;
48 | private String mReceiverFirebaseToken;
49 |
50 | private FcmNotificationBuilder() {
51 |
52 | }
53 |
54 | public static FcmNotificationBuilder initialize() {
55 | return new FcmNotificationBuilder();
56 | }
57 |
58 | public FcmNotificationBuilder title(String title) {
59 | mTitle = title;
60 | return this;
61 | }
62 |
63 | public FcmNotificationBuilder message(String message) {
64 | mMessage = message;
65 | return this;
66 | }
67 |
68 | public FcmNotificationBuilder username(String username) {
69 | mUsername = username;
70 | return this;
71 | }
72 |
73 | public FcmNotificationBuilder uid(String uid) {
74 | mUid = uid;
75 | return this;
76 | }
77 |
78 | public FcmNotificationBuilder firebaseToken(String firebaseToken) {
79 | mFirebaseToken = firebaseToken;
80 | return this;
81 | }
82 |
83 | public FcmNotificationBuilder receiverFirebaseToken(String receiverFirebaseToken) {
84 | mReceiverFirebaseToken = receiverFirebaseToken;
85 | return this;
86 | }
87 |
88 | public void send() {
89 | RequestBody requestBody = null;
90 | try {
91 | requestBody = RequestBody.create(MEDIA_TYPE_JSON, getValidJsonBody().toString());
92 | } catch (JSONException e) {
93 | e.printStackTrace();
94 | }
95 |
96 | Request request = new Request.Builder()
97 | .addHeader(CONTENT_TYPE, APPLICATION_JSON)
98 | .addHeader(AUTHORIZATION, AUTH_KEY)
99 | .url(FCM_URL)
100 | .post(requestBody)
101 | .build();
102 |
103 | Call call = new OkHttpClient().newCall(request);
104 | call.enqueue(new Callback() {
105 | @Override
106 | public void onFailure(Call call, IOException e) {
107 | Log.e(TAG, "onGetAllUsersFailure: " + e.getMessage());
108 | }
109 |
110 | @Override
111 | public void onResponse(Call call, Response response) throws IOException {
112 | Log.e(TAG, "onResponse: " + response.body().string());
113 | }
114 | });
115 | }
116 |
117 | private JSONObject getValidJsonBody() throws JSONException {
118 | JSONObject jsonObjectBody = new JSONObject();
119 | jsonObjectBody.put(KEY_TO, mReceiverFirebaseToken);
120 |
121 | JSONObject jsonObjectData = new JSONObject();
122 | jsonObjectData.put(KEY_TITLE, mTitle);
123 | jsonObjectData.put(KEY_TEXT, mMessage);
124 | jsonObjectData.put(KEY_USERNAME, mUsername);
125 | jsonObjectData.put(KEY_UID, mUid);
126 | jsonObjectData.put(KEY_FCM_TOKEN, mFirebaseToken);
127 | jsonObjectBody.put(KEY_DATA, jsonObjectData);
128 |
129 | return jsonObjectBody;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/fcm/MyFirebaseInstanceIDService.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.fcm;
2 |
3 | import android.util.Log;
4 |
5 | import com.crazyhitty.chdev.ks.firebasechat.utils.Constants;
6 | import com.crazyhitty.chdev.ks.firebasechat.utils.SharedPrefUtil;
7 | import com.google.firebase.auth.FirebaseAuth;
8 | import com.google.firebase.database.FirebaseDatabase;
9 | import com.google.firebase.iid.FirebaseInstanceId;
10 | import com.google.firebase.iid.FirebaseInstanceIdService;
11 |
12 | public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
13 | private static final String TAG = "MyFirebaseIIDService";
14 |
15 | /**
16 | * Called if InstanceID token is updated. This may occur if the security of
17 | * the previous token had been compromised. Note that this is called when the InstanceID token
18 | * is initially generated so this is where you would retrieve the token.
19 | */
20 | // [START refresh_token]
21 | @Override
22 | public void onTokenRefresh() {
23 | // Get updated InstanceID token.
24 | String refreshedToken = FirebaseInstanceId.getInstance().getToken();
25 | Log.d(TAG, "Refreshed token: " + refreshedToken);
26 |
27 | // If you want to send messages to this application instance or
28 | // manage this apps subscriptions on the server side, send the
29 | // Instance ID token to your app server.
30 | sendRegistrationToServer(refreshedToken);
31 | }
32 | // [END refresh_token]
33 |
34 | /**
35 | * Persist token to third-party servers.
36 | *
37 | * Modify this method to associate the user's FCM InstanceID token with any server-side account
38 | * maintained by your application.
39 | *
40 | * @param token The new token.
41 | */
42 | private void sendRegistrationToServer(final String token) {
43 | new SharedPrefUtil(getApplicationContext()).saveString(Constants.ARG_FIREBASE_TOKEN, token);
44 |
45 | if (FirebaseAuth.getInstance().getCurrentUser() != null) {
46 | FirebaseDatabase.getInstance()
47 | .getReference()
48 | .child(Constants.ARG_USERS)
49 | .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
50 | .child(Constants.ARG_FIREBASE_TOKEN)
51 | .setValue(token);
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/fcm/MyFirebaseMessagingService.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.fcm;
2 |
3 | import android.app.NotificationManager;
4 | import android.app.PendingIntent;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.media.RingtoneManager;
8 | import android.net.Uri;
9 | import android.support.v4.app.NotificationCompat;
10 | import android.util.Log;
11 |
12 | import com.crazyhitty.chdev.ks.firebasechat.FirebaseChatMainApp;
13 | import com.crazyhitty.chdev.ks.firebasechat.R;
14 | import com.crazyhitty.chdev.ks.firebasechat.events.PushNotificationEvent;
15 | import com.crazyhitty.chdev.ks.firebasechat.ui.activities.ChatActivity;
16 | import com.crazyhitty.chdev.ks.firebasechat.utils.Constants;
17 | import com.google.firebase.messaging.FirebaseMessagingService;
18 | import com.google.firebase.messaging.RemoteMessage;
19 |
20 | import org.greenrobot.eventbus.EventBus;
21 |
22 | public class MyFirebaseMessagingService extends FirebaseMessagingService {
23 |
24 | private static final String TAG = "MyFirebaseMsgService";
25 |
26 | /**
27 | * Called when message is received.
28 | *
29 | * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
30 | */
31 | @Override
32 | public void onMessageReceived(RemoteMessage remoteMessage) {
33 |
34 | // TODO(developer): Handle FCM messages here.
35 | // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
36 | Log.d(TAG, "From: " + remoteMessage.getFrom());
37 |
38 | // Check if message contains a data payload.
39 | if (remoteMessage.getData().size() > 0) {
40 | Log.d(TAG, "Message data payload: " + remoteMessage.getData());
41 |
42 | String title = remoteMessage.getData().get("title");
43 | String message = remoteMessage.getData().get("text");
44 | String username = remoteMessage.getData().get("username");
45 | String uid = remoteMessage.getData().get("uid");
46 | String fcmToken = remoteMessage.getData().get("fcm_token");
47 |
48 | // Don't show notification if chat activity is open.
49 | if (!FirebaseChatMainApp.isChatActivityOpen()) {
50 | sendNotification(title,
51 | message,
52 | username,
53 | uid,
54 | fcmToken);
55 | } else {
56 | EventBus.getDefault().post(new PushNotificationEvent(title,
57 | message,
58 | username,
59 | uid,
60 | fcmToken));
61 | }
62 | }
63 | }
64 |
65 | /**
66 | * Create and show a simple notification containing the received FCM message.
67 | */
68 | private void sendNotification(String title,
69 | String message,
70 | String receiver,
71 | String receiverUid,
72 | String firebaseToken) {
73 | Intent intent = new Intent(this, ChatActivity.class);
74 | intent.putExtra(Constants.ARG_RECEIVER, receiver);
75 | intent.putExtra(Constants.ARG_RECEIVER_UID, receiverUid);
76 | intent.putExtra(Constants.ARG_FIREBASE_TOKEN, firebaseToken);
77 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
78 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
79 | PendingIntent.FLAG_ONE_SHOT);
80 |
81 | Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
82 | NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
83 | .setSmallIcon(R.drawable.ic_messaging)
84 | .setContentTitle(title)
85 | .setContentText(message)
86 | .setAutoCancel(true)
87 | .setSound(defaultSoundUri)
88 | .setContentIntent(pendingIntent);
89 |
90 | NotificationManager notificationManager =
91 | (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
92 |
93 | notificationManager.notify(0, notificationBuilder.build());
94 | }
95 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/models/Chat.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.models;
2 |
3 | import com.google.firebase.database.IgnoreExtraProperties;
4 |
5 | /**
6 | * Author: Kartik Sharma
7 | * Created on: 9/4/2016 , 12:43 PM
8 | * Project: FirebaseChat
9 | */
10 |
11 | @IgnoreExtraProperties
12 | public class Chat {
13 | public String sender;
14 | public String receiver;
15 | public String senderUid;
16 | public String receiverUid;
17 | public String message;
18 | public long timestamp;
19 |
20 | public Chat() {
21 | }
22 |
23 | public Chat(String sender, String receiver, String senderUid, String receiverUid, String message, long timestamp) {
24 | this.sender = sender;
25 | this.receiver = receiver;
26 | this.senderUid = senderUid;
27 | this.receiverUid = receiverUid;
28 | this.message = message;
29 | this.timestamp = timestamp;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/models/User.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.models;
2 |
3 | import com.google.firebase.database.IgnoreExtraProperties;
4 |
5 | /**
6 | * Author: Kartik Sharma
7 | * Created on: 9/1/2016 , 8:35 PM
8 | * Project: FirebaseChat
9 | */
10 |
11 | @IgnoreExtraProperties
12 | public class User {
13 | public String uid;
14 | public String email;
15 | public String firebaseToken;
16 |
17 | public User() {
18 | }
19 |
20 | public User(String uid, String email, String firebaseToken) {
21 | this.uid = uid;
22 | this.email = email;
23 | this.firebaseToken = firebaseToken;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/models/Users.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.models;
2 |
3 | /**
4 | * Author: Kartik Sharma
5 | * Created on: 8/28/2016 , 2:25 PM
6 | * Project: FirebaseChat
7 | */
8 |
9 | public class Users {
10 | private String emailId;
11 | private String lastMessage;
12 | private int notifCount;
13 |
14 | public String getEmailId() {
15 | return emailId;
16 | }
17 |
18 | public void setEmailId(String emailId) {
19 | this.emailId = emailId;
20 | }
21 |
22 | public String getLastMessage() {
23 | return lastMessage;
24 | }
25 |
26 | public void setLastMessage(String lastMessage) {
27 | this.lastMessage = lastMessage;
28 | }
29 |
30 | public int getNotifCount() {
31 | return notifCount;
32 | }
33 |
34 | public void setNotifCount(int notifCount) {
35 | this.notifCount = notifCount;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/activities/ChatActivity.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 |
10 | import com.crazyhitty.chdev.ks.firebasechat.FirebaseChatMainApp;
11 | import com.crazyhitty.chdev.ks.firebasechat.R;
12 | import com.crazyhitty.chdev.ks.firebasechat.ui.fragments.ChatFragment;
13 | import com.crazyhitty.chdev.ks.firebasechat.utils.Constants;
14 |
15 | public class ChatActivity extends AppCompatActivity {
16 | private Toolbar mToolbar;
17 |
18 | public static void startActivity(Context context,
19 | String receiver,
20 | String receiverUid,
21 | String firebaseToken) {
22 | Intent intent = new Intent(context, ChatActivity.class);
23 | intent.putExtra(Constants.ARG_RECEIVER, receiver);
24 | intent.putExtra(Constants.ARG_RECEIVER_UID, receiverUid);
25 | intent.putExtra(Constants.ARG_FIREBASE_TOKEN, firebaseToken);
26 | context.startActivity(intent);
27 | }
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_chat);
33 | bindViews();
34 | init();
35 | }
36 |
37 | private void bindViews() {
38 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
39 | }
40 |
41 | private void init() {
42 | // set the toolbar
43 | setSupportActionBar(mToolbar);
44 |
45 | // set toolbar title
46 | mToolbar.setTitle(getIntent().getExtras().getString(Constants.ARG_RECEIVER));
47 |
48 | // set the register screen fragment
49 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
50 | fragmentTransaction.replace(R.id.frame_layout_content_chat,
51 | ChatFragment.newInstance(getIntent().getExtras().getString(Constants.ARG_RECEIVER),
52 | getIntent().getExtras().getString(Constants.ARG_RECEIVER_UID),
53 | getIntent().getExtras().getString(Constants.ARG_FIREBASE_TOKEN)),
54 | ChatFragment.class.getSimpleName());
55 | fragmentTransaction.commit();
56 | }
57 |
58 | @Override
59 | protected void onResume() {
60 | super.onResume();
61 | FirebaseChatMainApp.setChatActivityOpen(true);
62 | }
63 |
64 | @Override
65 | protected void onPause() {
66 | super.onPause();
67 | FirebaseChatMainApp.setChatActivityOpen(false);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/activities/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 |
10 | import com.crazyhitty.chdev.ks.firebasechat.R;
11 | import com.crazyhitty.chdev.ks.firebasechat.ui.fragments.LoginFragment;
12 |
13 | public class LoginActivity extends AppCompatActivity {
14 | private Toolbar mToolbar;
15 |
16 | public static void startIntent(Context context) {
17 | Intent intent = new Intent(context, LoginActivity.class);
18 | context.startActivity(intent);
19 | }
20 |
21 | public static void startIntent(Context context, int flags) {
22 | Intent intent = new Intent(context, LoginActivity.class);
23 | intent.setFlags(flags);
24 | context.startActivity(intent);
25 | }
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_login);
31 | bindViews();
32 | init();
33 | }
34 |
35 | private void bindViews() {
36 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
37 | }
38 |
39 | private void init() {
40 | // set the toolbar
41 | setSupportActionBar(mToolbar);
42 |
43 | // set the login screen fragment
44 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
45 | fragmentTransaction.replace(R.id.frame_layout_content_login,
46 | LoginFragment.newInstance(),
47 | LoginFragment.class.getSimpleName());
48 | fragmentTransaction.commit();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/activities/RegisterActivity.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 |
10 | import com.crazyhitty.chdev.ks.firebasechat.R;
11 | import com.crazyhitty.chdev.ks.firebasechat.ui.fragments.RegisterFragment;
12 |
13 | public class RegisterActivity extends AppCompatActivity {
14 | private Toolbar mToolbar;
15 |
16 | public static void startActivity(Context context) {
17 | Intent intent = new Intent(context, RegisterActivity.class);
18 | context.startActivity(intent);
19 | }
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_register);
25 | bindViews();
26 | init();
27 | }
28 |
29 | private void bindViews() {
30 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
31 | }
32 |
33 | private void init() {
34 | // set the toolbar
35 | setSupportActionBar(mToolbar);
36 |
37 | // set the register screen fragment
38 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
39 | fragmentTransaction.replace(R.id.frame_layout_content_register,
40 | RegisterFragment.newInstance(),
41 | RegisterFragment.class.getSimpleName());
42 | fragmentTransaction.commit();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/activities/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.activities;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import com.crazyhitty.chdev.ks.firebasechat.R;
8 | import com.google.firebase.auth.FirebaseAuth;
9 |
10 | public class SplashActivity extends AppCompatActivity {
11 | private static final int SPLASH_TIME_MS = 2000;
12 | private Handler mHandler;
13 | private Runnable mRunnable;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_splash);
19 |
20 | mHandler = new Handler();
21 |
22 | mRunnable = new Runnable() {
23 | @Override
24 | public void run() {
25 | // check if user is already logged in or not
26 | if (FirebaseAuth.getInstance().getCurrentUser() != null) {
27 | // if logged in redirect the user to user listing activity
28 | UserListingActivity.startActivity(SplashActivity.this);
29 | } else {
30 | // otherwise redirect the user to login activity
31 | LoginActivity.startIntent(SplashActivity.this);
32 | }
33 | finish();
34 | }
35 | };
36 |
37 | mHandler.postDelayed(mRunnable, SPLASH_TIME_MS);
38 | }
39 |
40 | /*@Override
41 | protected void onPause() {
42 | super.onPause();
43 | mHandler.removeCallbacks(mRunnable);
44 | }
45 |
46 | @Override
47 | protected void onResume() {
48 | super.onResume();
49 | mHandler.postDelayed(mRunnable, SPLASH_TIME_MS);
50 | }*/
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/activities/UserListingActivity.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.activities;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.support.design.widget.TabLayout;
8 | import android.support.v4.view.ViewPager;
9 | import android.support.v7.app.AlertDialog;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.widget.Toast;
15 |
16 | import com.crazyhitty.chdev.ks.firebasechat.R;
17 | import com.crazyhitty.chdev.ks.firebasechat.core.logout.LogoutContract;
18 | import com.crazyhitty.chdev.ks.firebasechat.core.logout.LogoutPresenter;
19 | import com.crazyhitty.chdev.ks.firebasechat.ui.adapters.UserListingPagerAdapter;
20 |
21 | public class UserListingActivity extends AppCompatActivity implements LogoutContract.View {
22 | private Toolbar mToolbar;
23 | private TabLayout mTabLayoutUserListing;
24 | private ViewPager mViewPagerUserListing;
25 |
26 | private LogoutPresenter mLogoutPresenter;
27 |
28 | public static void startActivity(Context context) {
29 | Intent intent = new Intent(context, UserListingActivity.class);
30 | context.startActivity(intent);
31 | }
32 |
33 | public static void startActivity(Context context, int flags) {
34 | Intent intent = new Intent(context, UserListingActivity.class);
35 | intent.setFlags(flags);
36 | context.startActivity(intent);
37 | }
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.activity_user_listing);
43 | bindViews();
44 | init();
45 | }
46 |
47 | private void bindViews() {
48 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
49 | mTabLayoutUserListing = (TabLayout) findViewById(R.id.tab_layout_user_listing);
50 | mViewPagerUserListing = (ViewPager) findViewById(R.id.view_pager_user_listing);
51 | }
52 |
53 | private void init() {
54 | // set the toolbar
55 | setSupportActionBar(mToolbar);
56 |
57 | // set the view pager adapter
58 | UserListingPagerAdapter userListingPagerAdapter = new UserListingPagerAdapter(getSupportFragmentManager());
59 | mViewPagerUserListing.setAdapter(userListingPagerAdapter);
60 |
61 | // attach tab layout with view pager
62 | mTabLayoutUserListing.setupWithViewPager(mViewPagerUserListing);
63 |
64 | mLogoutPresenter = new LogoutPresenter(this);
65 | }
66 |
67 | @Override
68 | public boolean onCreateOptionsMenu(Menu menu) {
69 | getMenuInflater().inflate(R.menu.menu_user_listing, menu);
70 | return super.onCreateOptionsMenu(menu);
71 | }
72 |
73 | @Override
74 | public boolean onOptionsItemSelected(MenuItem item) {
75 | switch (item.getItemId()) {
76 | case R.id.action_logout:
77 | logout();
78 | break;
79 | }
80 | return super.onOptionsItemSelected(item);
81 | }
82 |
83 | private void logout() {
84 | new AlertDialog.Builder(this)
85 | .setTitle(R.string.logout)
86 | .setMessage(R.string.are_you_sure)
87 | .setPositiveButton(R.string.logout, new DialogInterface.OnClickListener() {
88 | @Override
89 | public void onClick(DialogInterface dialog, int which) {
90 | dialog.dismiss();
91 | mLogoutPresenter.logout();
92 | }
93 | })
94 | .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
95 | @Override
96 | public void onClick(DialogInterface dialog, int which) {
97 | dialog.dismiss();
98 | }
99 | })
100 | .show();
101 | }
102 |
103 | @Override
104 | public void onLogoutSuccess(String message) {
105 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
106 | LoginActivity.startIntent(this,
107 | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
108 | }
109 |
110 | @Override
111 | public void onLogoutFailure(String message) {
112 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/adapters/ChatRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.adapters;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.text.TextUtils;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import com.crazyhitty.chdev.ks.firebasechat.R;
11 | import com.crazyhitty.chdev.ks.firebasechat.models.Chat;
12 | import com.google.firebase.auth.FirebaseAuth;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Author: Kartik Sharma
18 | * Created on: 10/16/2016 , 10:36 AM
19 | * Project: FirebaseChat
20 | */
21 |
22 | public class ChatRecyclerAdapter extends RecyclerView.Adapter {
23 | private static final int VIEW_TYPE_ME = 1;
24 | private static final int VIEW_TYPE_OTHER = 2;
25 |
26 | private List mChats;
27 |
28 | public ChatRecyclerAdapter(List chats) {
29 | mChats = chats;
30 | }
31 |
32 | public void add(Chat chat) {
33 | mChats.add(chat);
34 | notifyItemInserted(mChats.size() - 1);
35 | }
36 |
37 | @Override
38 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
39 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
40 | RecyclerView.ViewHolder viewHolder = null;
41 | switch (viewType) {
42 | case VIEW_TYPE_ME:
43 | View viewChatMine = layoutInflater.inflate(R.layout.item_chat_mine, parent, false);
44 | viewHolder = new MyChatViewHolder(viewChatMine);
45 | break;
46 | case VIEW_TYPE_OTHER:
47 | View viewChatOther = layoutInflater.inflate(R.layout.item_chat_other, parent, false);
48 | viewHolder = new OtherChatViewHolder(viewChatOther);
49 | break;
50 | }
51 | return viewHolder;
52 | }
53 |
54 | @Override
55 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
56 | if (TextUtils.equals(mChats.get(position).senderUid,
57 | FirebaseAuth.getInstance().getCurrentUser().getUid())) {
58 | configureMyChatViewHolder((MyChatViewHolder) holder, position);
59 | } else {
60 | configureOtherChatViewHolder((OtherChatViewHolder) holder, position);
61 | }
62 | }
63 |
64 | private void configureMyChatViewHolder(MyChatViewHolder myChatViewHolder, int position) {
65 | Chat chat = mChats.get(position);
66 |
67 | String alphabet = chat.sender.substring(0, 1);
68 |
69 | myChatViewHolder.txtChatMessage.setText(chat.message);
70 | myChatViewHolder.txtUserAlphabet.setText(alphabet);
71 | }
72 |
73 | private void configureOtherChatViewHolder(OtherChatViewHolder otherChatViewHolder, int position) {
74 | Chat chat = mChats.get(position);
75 |
76 | String alphabet = chat.sender.substring(0, 1);
77 |
78 | otherChatViewHolder.txtChatMessage.setText(chat.message);
79 | otherChatViewHolder.txtUserAlphabet.setText(alphabet);
80 | }
81 |
82 | @Override
83 | public int getItemCount() {
84 | if (mChats != null) {
85 | return mChats.size();
86 | }
87 | return 0;
88 | }
89 |
90 | @Override
91 | public int getItemViewType(int position) {
92 | if (TextUtils.equals(mChats.get(position).senderUid,
93 | FirebaseAuth.getInstance().getCurrentUser().getUid())) {
94 | return VIEW_TYPE_ME;
95 | } else {
96 | return VIEW_TYPE_OTHER;
97 | }
98 | }
99 |
100 | private static class MyChatViewHolder extends RecyclerView.ViewHolder {
101 | private TextView txtChatMessage, txtUserAlphabet;
102 |
103 | public MyChatViewHolder(View itemView) {
104 | super(itemView);
105 | txtChatMessage = (TextView) itemView.findViewById(R.id.text_view_chat_message);
106 | txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
107 | }
108 | }
109 |
110 | private static class OtherChatViewHolder extends RecyclerView.ViewHolder {
111 | private TextView txtChatMessage, txtUserAlphabet;
112 |
113 | public OtherChatViewHolder(View itemView) {
114 | super(itemView);
115 | txtChatMessage = (TextView) itemView.findViewById(R.id.text_view_chat_message);
116 | txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/adapters/UserListingPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.adapters;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import com.crazyhitty.chdev.ks.firebasechat.ui.fragments.UsersFragment;
8 |
9 | /**
10 | * Author: Kartik Sharma
11 | * Created on: 9/4/2016 , 12:03 PM
12 | * Project: FirebaseChat
13 | */
14 |
15 | public class UserListingPagerAdapter extends FragmentPagerAdapter {
16 | private static final Fragment[] sFragments = new Fragment[]{/*UsersFragment.newInstance(UsersFragment.TYPE_CHATS),*/
17 | UsersFragment.newInstance(UsersFragment.TYPE_ALL)};
18 | private static final String[] sTitles = new String[]{/*"Chats",*/
19 | "All Users"};
20 |
21 | public UserListingPagerAdapter(FragmentManager fm) {
22 | super(fm);
23 | }
24 |
25 | @Override
26 | public Fragment getItem(int position) {
27 | return sFragments[position];
28 | }
29 |
30 | @Override
31 | public int getCount() {
32 | return sFragments.length;
33 | }
34 |
35 | @Override
36 | public CharSequence getPageTitle(int position) {
37 | return sTitles[position];
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/adapters/UserListingRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.adapters;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.crazyhitty.chdev.ks.firebasechat.R;
10 | import com.crazyhitty.chdev.ks.firebasechat.models.User;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Author: Kartik Sharma
16 | * Created on: 8/28/2016 , 2:23 PM
17 | * Project: FirebaseChat
18 | */
19 |
20 | public class UserListingRecyclerAdapter extends RecyclerView.Adapter {
21 | private List mUsers;
22 |
23 | public UserListingRecyclerAdapter(List users) {
24 | this.mUsers = users;
25 | }
26 |
27 | public void add(User user) {
28 | mUsers.add(user);
29 | notifyItemInserted(mUsers.size() - 1);
30 | }
31 |
32 | @Override
33 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
34 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_all_user_listing, parent, false);
35 | return new ViewHolder(view);
36 | }
37 |
38 | @Override
39 | public void onBindViewHolder(ViewHolder holder, int position) {
40 | User user = mUsers.get(position);
41 |
42 | String alphabet = user.email.substring(0, 1);
43 |
44 | holder.txtUsername.setText(user.email);
45 | holder.txtUserAlphabet.setText(alphabet);
46 | }
47 |
48 | @Override
49 | public int getItemCount() {
50 | if (mUsers != null) {
51 | return mUsers.size();
52 | }
53 | return 0;
54 | }
55 |
56 | public User getUser(int position) {
57 | return mUsers.get(position);
58 | }
59 |
60 | static class ViewHolder extends RecyclerView.ViewHolder {
61 | private TextView txtUserAlphabet, txtUsername;
62 |
63 | ViewHolder(View itemView) {
64 | super(itemView);
65 | txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
66 | txtUsername = (TextView) itemView.findViewById(R.id.text_view_username);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/fragments/ChatFragment.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.fragments;
2 |
3 | import android.app.ProgressDialog;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.KeyEvent;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.inputmethod.EditorInfo;
13 | import android.widget.EditText;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.crazyhitty.chdev.ks.firebasechat.R;
18 | import com.crazyhitty.chdev.ks.firebasechat.core.chat.ChatContract;
19 | import com.crazyhitty.chdev.ks.firebasechat.core.chat.ChatPresenter;
20 | import com.crazyhitty.chdev.ks.firebasechat.events.PushNotificationEvent;
21 | import com.crazyhitty.chdev.ks.firebasechat.models.Chat;
22 | import com.crazyhitty.chdev.ks.firebasechat.ui.adapters.ChatRecyclerAdapter;
23 | import com.crazyhitty.chdev.ks.firebasechat.utils.Constants;
24 | import com.google.firebase.auth.FirebaseAuth;
25 |
26 | import org.greenrobot.eventbus.EventBus;
27 | import org.greenrobot.eventbus.Subscribe;
28 |
29 | import java.util.ArrayList;
30 |
31 | /**
32 | * Author: Kartik Sharma
33 | * Created on: 8/28/2016 , 10:36 AM
34 | * Project: FirebaseChat
35 | */
36 |
37 | public class ChatFragment extends Fragment implements ChatContract.View, TextView.OnEditorActionListener {
38 | private RecyclerView mRecyclerViewChat;
39 | private EditText mETxtMessage;
40 |
41 | private ProgressDialog mProgressDialog;
42 |
43 | private ChatRecyclerAdapter mChatRecyclerAdapter;
44 |
45 | private ChatPresenter mChatPresenter;
46 |
47 | public static ChatFragment newInstance(String receiver,
48 | String receiverUid,
49 | String firebaseToken) {
50 | Bundle args = new Bundle();
51 | args.putString(Constants.ARG_RECEIVER, receiver);
52 | args.putString(Constants.ARG_RECEIVER_UID, receiverUid);
53 | args.putString(Constants.ARG_FIREBASE_TOKEN, firebaseToken);
54 | ChatFragment fragment = new ChatFragment();
55 | fragment.setArguments(args);
56 | return fragment;
57 | }
58 |
59 | @Override
60 | public void onStart() {
61 | super.onStart();
62 | EventBus.getDefault().register(this);
63 | }
64 |
65 | @Override
66 | public void onStop() {
67 | super.onStop();
68 | EventBus.getDefault().unregister(this);
69 | }
70 |
71 | @Nullable
72 | @Override
73 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
74 | View fragmentView = inflater.inflate(R.layout.fragment_chat, container, false);
75 | bindViews(fragmentView);
76 | return fragmentView;
77 | }
78 |
79 | private void bindViews(View view) {
80 | mRecyclerViewChat = (RecyclerView) view.findViewById(R.id.recycler_view_chat);
81 | mETxtMessage = (EditText) view.findViewById(R.id.edit_text_message);
82 | }
83 |
84 | @Override
85 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
86 | super.onActivityCreated(savedInstanceState);
87 | init();
88 | }
89 |
90 | private void init() {
91 | mProgressDialog = new ProgressDialog(getActivity());
92 | mProgressDialog.setTitle(getString(R.string.loading));
93 | mProgressDialog.setMessage(getString(R.string.please_wait));
94 | mProgressDialog.setIndeterminate(true);
95 |
96 | mETxtMessage.setOnEditorActionListener(this);
97 |
98 | mChatPresenter = new ChatPresenter(this);
99 | mChatPresenter.getMessage(FirebaseAuth.getInstance().getCurrentUser().getUid(),
100 | getArguments().getString(Constants.ARG_RECEIVER_UID));
101 | }
102 |
103 | @Override
104 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
105 | if (actionId == EditorInfo.IME_ACTION_SEND) {
106 | sendMessage();
107 | return true;
108 | }
109 | return false;
110 | }
111 |
112 | private void sendMessage() {
113 | String message = mETxtMessage.getText().toString();
114 | String receiver = getArguments().getString(Constants.ARG_RECEIVER);
115 | String receiverUid = getArguments().getString(Constants.ARG_RECEIVER_UID);
116 | String sender = FirebaseAuth.getInstance().getCurrentUser().getEmail();
117 | String senderUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
118 | String receiverFirebaseToken = getArguments().getString(Constants.ARG_FIREBASE_TOKEN);
119 | Chat chat = new Chat(sender,
120 | receiver,
121 | senderUid,
122 | receiverUid,
123 | message,
124 | System.currentTimeMillis());
125 | mChatPresenter.sendMessage(getActivity().getApplicationContext(),
126 | chat,
127 | receiverFirebaseToken);
128 | }
129 |
130 | @Override
131 | public void onSendMessageSuccess() {
132 | mETxtMessage.setText("");
133 | Toast.makeText(getActivity(), "Message sent", Toast.LENGTH_SHORT).show();
134 | }
135 |
136 | @Override
137 | public void onSendMessageFailure(String message) {
138 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
139 | }
140 |
141 | @Override
142 | public void onGetMessagesSuccess(Chat chat) {
143 | if (mChatRecyclerAdapter == null) {
144 | mChatRecyclerAdapter = new ChatRecyclerAdapter(new ArrayList());
145 | mRecyclerViewChat.setAdapter(mChatRecyclerAdapter);
146 | }
147 | mChatRecyclerAdapter.add(chat);
148 | mRecyclerViewChat.smoothScrollToPosition(mChatRecyclerAdapter.getItemCount() - 1);
149 | }
150 |
151 | @Override
152 | public void onGetMessagesFailure(String message) {
153 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
154 | }
155 |
156 | @Subscribe
157 | public void onPushNotificationEvent(PushNotificationEvent pushNotificationEvent) {
158 | if (mChatRecyclerAdapter == null || mChatRecyclerAdapter.getItemCount() == 0) {
159 | mChatPresenter.getMessage(FirebaseAuth.getInstance().getCurrentUser().getUid(),
160 | pushNotificationEvent.getUid());
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/fragments/LoginFragment.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.fragments;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.Toast;
14 |
15 | import com.crazyhitty.chdev.ks.firebasechat.R;
16 | import com.crazyhitty.chdev.ks.firebasechat.core.login.LoginContract;
17 | import com.crazyhitty.chdev.ks.firebasechat.core.login.LoginPresenter;
18 | import com.crazyhitty.chdev.ks.firebasechat.ui.activities.RegisterActivity;
19 | import com.crazyhitty.chdev.ks.firebasechat.ui.activities.UserListingActivity;
20 |
21 | /**
22 | * Author: Kartik Sharma
23 | * Created on: 8/28/2016 , 10:36 AM
24 | * Project: FirebaseChat
25 | */
26 |
27 | public class LoginFragment extends Fragment implements View.OnClickListener, LoginContract.View {
28 | private LoginPresenter mLoginPresenter;
29 |
30 | private EditText mETxtEmail, mETxtPassword;
31 | private Button mBtnLogin, mBtnRegister;
32 |
33 | private ProgressDialog mProgressDialog;
34 |
35 | public static LoginFragment newInstance() {
36 | Bundle args = new Bundle();
37 | LoginFragment fragment = new LoginFragment();
38 | fragment.setArguments(args);
39 | return fragment;
40 | }
41 |
42 | @Nullable
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
45 | View fragmentView = inflater.inflate(R.layout.fragment_login, container, false);
46 | bindViews(fragmentView);
47 | return fragmentView;
48 | }
49 |
50 | private void bindViews(View view) {
51 | mETxtEmail = (EditText) view.findViewById(R.id.edit_text_email_id);
52 | mETxtPassword = (EditText) view.findViewById(R.id.edit_text_password);
53 | mBtnLogin = (Button) view.findViewById(R.id.button_login);
54 | mBtnRegister = (Button) view.findViewById(R.id.button_register);
55 | }
56 |
57 | @Override
58 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
59 | super.onActivityCreated(savedInstanceState);
60 | init();
61 | }
62 |
63 | private void init() {
64 | mLoginPresenter = new LoginPresenter(this);
65 |
66 | mProgressDialog = new ProgressDialog(getActivity());
67 | mProgressDialog.setTitle(getString(R.string.loading));
68 | mProgressDialog.setMessage(getString(R.string.please_wait));
69 | mProgressDialog.setIndeterminate(true);
70 |
71 | mBtnLogin.setOnClickListener(this);
72 | mBtnRegister.setOnClickListener(this);
73 |
74 | setDummyCredentials();
75 | }
76 |
77 | private void setDummyCredentials() {
78 | mETxtEmail.setText("test@test.com");
79 | mETxtPassword.setText("123456");
80 | }
81 |
82 | @Override
83 | public void onClick(View view) {
84 | int viewId = view.getId();
85 |
86 | switch (viewId) {
87 | case R.id.button_login:
88 | onLogin(view);
89 | break;
90 | case R.id.button_register:
91 | onRegister(view);
92 | break;
93 | }
94 | }
95 |
96 | private void onLogin(View view) {
97 | String emailId = mETxtEmail.getText().toString();
98 | String password = mETxtPassword.getText().toString();
99 |
100 | mLoginPresenter.login(getActivity(), emailId, password);
101 | mProgressDialog.show();
102 | }
103 |
104 | private void onRegister(View view) {
105 | RegisterActivity.startActivity(getActivity());
106 | }
107 |
108 | @Override
109 | public void onLoginSuccess(String message) {
110 | mProgressDialog.dismiss();
111 | Toast.makeText(getActivity(), "Logged in successfully", Toast.LENGTH_SHORT).show();
112 | UserListingActivity.startActivity(getActivity(),
113 | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
114 | }
115 |
116 | @Override
117 | public void onLoginFailure(String message) {
118 | mProgressDialog.dismiss();
119 | Toast.makeText(getActivity(), "Error: " + message, Toast.LENGTH_SHORT).show();
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/fragments/RegisterFragment.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.fragments;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | import com.crazyhitty.chdev.ks.firebasechat.R;
17 | import com.crazyhitty.chdev.ks.firebasechat.core.registration.RegisterContract;
18 | import com.crazyhitty.chdev.ks.firebasechat.core.registration.RegisterPresenter;
19 | import com.crazyhitty.chdev.ks.firebasechat.core.users.add.AddUserContract;
20 | import com.crazyhitty.chdev.ks.firebasechat.core.users.add.AddUserPresenter;
21 | import com.crazyhitty.chdev.ks.firebasechat.ui.activities.UserListingActivity;
22 | import com.google.firebase.auth.FirebaseUser;
23 |
24 | /**
25 | * Author: Kartik Sharma
26 | * Created on: 8/28/2016 , 10:36 AM
27 | * Project: FirebaseChat
28 | */
29 |
30 | public class RegisterFragment extends Fragment implements View.OnClickListener, RegisterContract.View, AddUserContract.View {
31 | private static final String TAG = RegisterFragment.class.getSimpleName();
32 |
33 | private RegisterPresenter mRegisterPresenter;
34 | private AddUserPresenter mAddUserPresenter;
35 |
36 | private EditText mETxtEmail, mETxtPassword;
37 | private Button mBtnRegister;
38 |
39 | private ProgressDialog mProgressDialog;
40 |
41 | public static RegisterFragment newInstance() {
42 | Bundle args = new Bundle();
43 | RegisterFragment fragment = new RegisterFragment();
44 | fragment.setArguments(args);
45 | return fragment;
46 | }
47 |
48 | @Nullable
49 | @Override
50 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
51 | View fragmentView = inflater.inflate(R.layout.fragment_register, container, false);
52 | bindViews(fragmentView);
53 | return fragmentView;
54 | }
55 |
56 | private void bindViews(View view) {
57 | mETxtEmail = (EditText) view.findViewById(R.id.edit_text_email_id);
58 | mETxtPassword = (EditText) view.findViewById(R.id.edit_text_password);
59 | mBtnRegister = (Button) view.findViewById(R.id.button_register);
60 | }
61 |
62 | @Override
63 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
64 | super.onActivityCreated(savedInstanceState);
65 | init();
66 | }
67 |
68 | private void init() {
69 | mRegisterPresenter = new RegisterPresenter(this);
70 | mAddUserPresenter = new AddUserPresenter(this);
71 |
72 | mProgressDialog = new ProgressDialog(getActivity());
73 | mProgressDialog.setTitle(getString(R.string.loading));
74 | mProgressDialog.setMessage(getString(R.string.please_wait));
75 | mProgressDialog.setIndeterminate(true);
76 |
77 | mBtnRegister.setOnClickListener(this);
78 | }
79 |
80 | @Override
81 | public void onClick(View view) {
82 | int viewId = view.getId();
83 |
84 | switch (viewId) {
85 | case R.id.button_register:
86 | onRegister(view);
87 | break;
88 | }
89 | }
90 |
91 | private void onRegister(View view) {
92 | String emailId = mETxtEmail.getText().toString();
93 | String password = mETxtPassword.getText().toString();
94 |
95 | mRegisterPresenter.register(getActivity(), emailId, password);
96 | mProgressDialog.show();
97 | }
98 |
99 | @Override
100 | public void onRegistrationSuccess(FirebaseUser firebaseUser) {
101 | mProgressDialog.setMessage(getString(R.string.adding_user_to_db));
102 | Toast.makeText(getActivity(), "Registration Successful!", Toast.LENGTH_SHORT).show();
103 | mAddUserPresenter.addUser(getActivity().getApplicationContext(), firebaseUser);
104 | }
105 |
106 | @Override
107 | public void onRegistrationFailure(String message) {
108 | mProgressDialog.dismiss();
109 | mProgressDialog.setMessage(getString(R.string.please_wait));
110 | Log.e(TAG, "onRegistrationFailure: " + message);
111 | Toast.makeText(getActivity(), "Registration failed!+\n" + message, Toast.LENGTH_LONG).show();
112 | }
113 |
114 | @Override
115 | public void onAddUserSuccess(String message) {
116 | mProgressDialog.dismiss();
117 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
118 | UserListingActivity.startActivity(getActivity(),
119 | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
120 | }
121 |
122 | @Override
123 | public void onAddUserFailure(String message) {
124 | mProgressDialog.dismiss();
125 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/ui/fragments/UsersFragment.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.ui.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.text.TextUtils;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.Toast;
13 |
14 | import com.crazyhitty.chdev.ks.firebasechat.R;
15 | import com.crazyhitty.chdev.ks.firebasechat.core.users.get.all.GetUsersContract;
16 | import com.crazyhitty.chdev.ks.firebasechat.core.users.get.all.GetUsersPresenter;
17 | import com.crazyhitty.chdev.ks.firebasechat.models.User;
18 | import com.crazyhitty.chdev.ks.firebasechat.ui.activities.ChatActivity;
19 | import com.crazyhitty.chdev.ks.firebasechat.ui.adapters.UserListingRecyclerAdapter;
20 | import com.crazyhitty.chdev.ks.firebasechat.utils.ItemClickSupport;
21 |
22 | import java.util.List;
23 |
24 | /**
25 | * Author: Kartik Sharma
26 | * Created on: 8/28/2016 , 10:36 AM
27 | * Project: FirebaseChat
28 | */
29 |
30 | public class UsersFragment extends Fragment implements GetUsersContract.View, ItemClickSupport.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
31 | public static final String ARG_TYPE = "type";
32 | public static final String TYPE_CHATS = "type_chats";
33 | public static final String TYPE_ALL = "type_all";
34 |
35 | private SwipeRefreshLayout mSwipeRefreshLayout;
36 | private RecyclerView mRecyclerViewAllUserListing;
37 |
38 | private UserListingRecyclerAdapter mUserListingRecyclerAdapter;
39 |
40 | private GetUsersPresenter mGetUsersPresenter;
41 |
42 | public static UsersFragment newInstance(String type) {
43 | Bundle args = new Bundle();
44 | args.putString(ARG_TYPE, type);
45 | UsersFragment fragment = new UsersFragment();
46 | fragment.setArguments(args);
47 | return fragment;
48 | }
49 |
50 | @Nullable
51 | @Override
52 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
53 | View fragmentView = inflater.inflate(R.layout.fragment_users, container, false);
54 | bindViews(fragmentView);
55 | return fragmentView;
56 | }
57 |
58 | private void bindViews(View view) {
59 | mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
60 | mRecyclerViewAllUserListing = (RecyclerView) view.findViewById(R.id.recycler_view_all_user_listing);
61 | }
62 |
63 | @Override
64 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
65 | super.onActivityCreated(savedInstanceState);
66 | init();
67 | }
68 |
69 | private void init() {
70 | mGetUsersPresenter = new GetUsersPresenter(this);
71 | getUsers();
72 | mSwipeRefreshLayout.post(new Runnable() {
73 | @Override
74 | public void run() {
75 | mSwipeRefreshLayout.setRefreshing(true);
76 | }
77 | });
78 |
79 | ItemClickSupport.addTo(mRecyclerViewAllUserListing)
80 | .setOnItemClickListener(this);
81 |
82 | mSwipeRefreshLayout.setOnRefreshListener(this);
83 | }
84 |
85 | @Override
86 | public void onRefresh() {
87 | getUsers();
88 | }
89 |
90 | private void getUsers() {
91 | if (TextUtils.equals(getArguments().getString(ARG_TYPE), TYPE_CHATS)) {
92 |
93 | } else if (TextUtils.equals(getArguments().getString(ARG_TYPE), TYPE_ALL)) {
94 | mGetUsersPresenter.getAllUsers();
95 | }
96 | }
97 |
98 | @Override
99 | public void onItemClicked(RecyclerView recyclerView, int position, View v) {
100 | ChatActivity.startActivity(getActivity(),
101 | mUserListingRecyclerAdapter.getUser(position).email,
102 | mUserListingRecyclerAdapter.getUser(position).uid,
103 | mUserListingRecyclerAdapter.getUser(position).firebaseToken);
104 | }
105 |
106 | @Override
107 | public void onGetAllUsersSuccess(List users) {
108 | mSwipeRefreshLayout.post(new Runnable() {
109 | @Override
110 | public void run() {
111 | mSwipeRefreshLayout.setRefreshing(false);
112 | }
113 | });
114 | mUserListingRecyclerAdapter = new UserListingRecyclerAdapter(users);
115 | mRecyclerViewAllUserListing.setAdapter(mUserListingRecyclerAdapter);
116 | mUserListingRecyclerAdapter.notifyDataSetChanged();
117 | }
118 |
119 | @Override
120 | public void onGetAllUsersFailure(String message) {
121 | mSwipeRefreshLayout.post(new Runnable() {
122 | @Override
123 | public void run() {
124 | mSwipeRefreshLayout.setRefreshing(false);
125 | }
126 | });
127 | Toast.makeText(getActivity(), "Error: " + message, Toast.LENGTH_SHORT).show();
128 | }
129 |
130 | @Override
131 | public void onGetChatUsersSuccess(List users) {
132 |
133 | }
134 |
135 | @Override
136 | public void onGetChatUsersFailure(String message) {
137 |
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/utils/Constants.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.utils;
2 |
3 | /**
4 | * Author: Kartik Sharma
5 | * Created on: 9/2/2016 , 10:12 PM
6 | * Project: FirebaseChat
7 | */
8 |
9 | public class Constants {
10 | public static final String ARG_USERS = "users";
11 | public static final String ARG_RECEIVER = "receiver";
12 | public static final String ARG_RECEIVER_UID = "receiver_uid";
13 | public static final String ARG_CHAT_ROOMS = "chat_rooms";
14 | public static final String ARG_FIREBASE_TOKEN = "firebaseToken";
15 | public static final String ARG_FRIENDS = "friends";
16 | public static final String ARG_UID = "uid";
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/utils/ItemClickSupport.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.utils;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | import com.crazyhitty.chdev.ks.firebasechat.R;
7 |
8 | public class ItemClickSupport {
9 | private final RecyclerView mRecyclerView;
10 | private OnItemClickListener mOnItemClickListener;
11 | private OnItemLongClickListener mOnItemLongClickListener;
12 | private View.OnClickListener mOnClickListener = new View.OnClickListener() {
13 | @Override
14 | public void onClick(View v) {
15 | if (mOnItemClickListener != null) {
16 | RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
17 | mOnItemClickListener.onItemClicked(mRecyclerView, holder.getAdapterPosition(), v);
18 | }
19 | }
20 | };
21 | private View.OnLongClickListener mOnLongClickListener = new View.OnLongClickListener() {
22 | @Override
23 | public boolean onLongClick(View v) {
24 | if (mOnItemLongClickListener != null) {
25 | RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
26 | return mOnItemLongClickListener.onItemLongClicked(mRecyclerView, holder.getAdapterPosition(), v);
27 | }
28 | return false;
29 | }
30 | };
31 | private RecyclerView.OnChildAttachStateChangeListener mAttachListener
32 | = new RecyclerView.OnChildAttachStateChangeListener() {
33 | @Override
34 | public void onChildViewAttachedToWindow(View view) {
35 | if (mOnItemClickListener != null) {
36 | view.setOnClickListener(mOnClickListener);
37 | }
38 | if (mOnItemLongClickListener != null) {
39 | view.setOnLongClickListener(mOnLongClickListener);
40 | }
41 | }
42 |
43 | @Override
44 | public void onChildViewDetachedFromWindow(View view) {
45 |
46 | }
47 | };
48 |
49 | private ItemClickSupport(RecyclerView recyclerView) {
50 | mRecyclerView = recyclerView;
51 | mRecyclerView.setTag(R.id.item_click_support, this);
52 | mRecyclerView.addOnChildAttachStateChangeListener(mAttachListener);
53 | }
54 |
55 | public static ItemClickSupport addTo(RecyclerView view) {
56 | ItemClickSupport support = (ItemClickSupport) view.getTag(R.id.item_click_support);
57 | if (support == null) {
58 | support = new ItemClickSupport(view);
59 | }
60 | return support;
61 | }
62 |
63 | public static ItemClickSupport removeFrom(RecyclerView view) {
64 | ItemClickSupport support = (ItemClickSupport) view.getTag(R.id.item_click_support);
65 | if (support != null) {
66 | support.detach(view);
67 | }
68 | return support;
69 | }
70 |
71 | public ItemClickSupport setOnItemClickListener(OnItemClickListener listener) {
72 | mOnItemClickListener = listener;
73 | return this;
74 | }
75 |
76 | public ItemClickSupport setOnItemLongClickListener(OnItemLongClickListener listener) {
77 | mOnItemLongClickListener = listener;
78 | return this;
79 | }
80 |
81 | private void detach(RecyclerView view) {
82 | view.removeOnChildAttachStateChangeListener(mAttachListener);
83 | view.setTag(R.id.item_click_support, null);
84 | }
85 |
86 | public interface OnItemClickListener {
87 |
88 | void onItemClicked(RecyclerView recyclerView, int position, View v);
89 | }
90 |
91 | public interface OnItemLongClickListener {
92 |
93 | boolean onItemLongClicked(RecyclerView recyclerView, int position, View v);
94 | }
95 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/utils/NetworkConnectionUtil.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.utils;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.net.ConnectivityManager;
7 | import android.net.NetworkInfo;
8 | import android.provider.Settings;
9 | import android.support.v7.app.AlertDialog;
10 |
11 | import com.crazyhitty.chdev.ks.firebasechat.R;
12 |
13 | /**
14 | * Utility class for network related queries.
15 | *
16 | * Author Kartik Sharma
17 | * Created on: 8/7/2016 , 9:15 AM
18 | * Project: FinalProject
19 | */
20 |
21 | public class NetworkConnectionUtil {
22 | public static final String ERR_DIALOG_TITLE = "No internet connection detected !";
23 | private static final String ERR_DIALOG_MSG = "Looks like our application is not able to detect an active internet connection, " +
24 | "please check your device's network settings.";
25 | private static final String ERR_DIALOG_POSITIVE_BTN = "Settings";
26 | private static final String ERR_DIALOG_NEGATIVE_BTN = "Dismiss";
27 |
28 | /**
29 | * Check if the device is connected to internet or not.
30 | *
31 | * @param context Current context of the application
32 | * @return true if device is connected to internet, otherwise false
33 | */
34 | public static boolean isConnectedToInternet(Context context) {
35 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
36 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
37 | return networkInfo != null && networkInfo.isConnectedOrConnecting();
38 | }
39 |
40 | /**
41 | * Check if the device is connected to internet via wifi or not.
42 | *
43 | * @param context Current context of the application
44 | * @return true if device is connected to internet via wifi, otherwise false
45 | */
46 | public static boolean isConnectedToWifi(Context context) {
47 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
48 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
49 | return networkInfo != null &&
50 | networkInfo.isConnectedOrConnecting() &&
51 | networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
52 | }
53 |
54 | /**
55 | * Check if the device is connected to internet via mobile network or not.
56 | *
57 | * @param context Current context of the application
58 | * @return true if device is connected to internet via mobile network, otherwise false
59 | */
60 | public static boolean isConnectedToMobileNetwork(Context context) {
61 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
62 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
63 | return networkInfo != null &&
64 | networkInfo.isConnectedOrConnecting() &&
65 | networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
66 | }
67 |
68 | /**
69 | * Show a error dialog representing that no internet connection is available currently.
70 | *
71 | * @param context Current context of the application
72 | */
73 | public static void showNoInternetAvailableErrorDialog(final Context context) {
74 | new AlertDialog.Builder(context)
75 | .setTitle(ERR_DIALOG_TITLE)
76 | .setMessage(ERR_DIALOG_MSG)
77 | .setIcon(R.drawable.ic_error_24dp)
78 | .setPositiveButton(ERR_DIALOG_POSITIVE_BTN, new DialogInterface.OnClickListener() {
79 | @Override
80 | public void onClick(DialogInterface dialogInterface, int i) {
81 | dialogInterface.dismiss();
82 | Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
83 | context.startActivity(intent);
84 | }
85 | })
86 | .setNegativeButton(ERR_DIALOG_NEGATIVE_BTN, new DialogInterface.OnClickListener() {
87 | @Override
88 | public void onClick(DialogInterface dialogInterface, int i) {
89 | dialogInterface.dismiss();
90 | }
91 | })
92 | .show();
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazyhitty/chdev/ks/firebasechat/utils/SharedPrefUtil.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * Simple util class for easing the use of shared preference.
8 | *
9 | * Created by Kartik_ch on 2/13/2016.
10 | */
11 | public class SharedPrefUtil {
12 | /**
13 | * Name of the preference file
14 | */
15 | private static final String APP_PREFS = "application_preferences";
16 |
17 | private Context mContext;
18 | private SharedPreferences mSharedPreferences;
19 | private SharedPreferences.Editor mEditor;
20 |
21 | public SharedPrefUtil(Context mContext) {
22 | this.mContext = mContext;
23 | }
24 |
25 | /**
26 | * Save a string into shared preference
27 | *
28 | * @param key The name of the preference to modify
29 | * @param value The new value for the preference
30 | */
31 | public void saveString(String key, String value) {
32 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
33 | mEditor = mSharedPreferences.edit();
34 | mEditor.putString(key, value);
35 | mEditor.commit();
36 | }
37 |
38 | /**
39 | * Save a int into shared preference
40 | *
41 | * @param key The name of the preference to modify
42 | * @param value The new value for the preference
43 | */
44 | public void saveInt(String key, int value) {
45 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
46 | mEditor = mSharedPreferences.edit();
47 | mEditor.putInt(key, value);
48 | mEditor.commit();
49 | }
50 |
51 | /**
52 | * Save a boolean into shared preference
53 | *
54 | * @param key The name of the preference to modify
55 | * @param value The new value for the preference
56 | */
57 | public void saveBoolean(String key, boolean value) {
58 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
59 | mEditor = mSharedPreferences.edit();
60 | mEditor.putBoolean(key, value);
61 | mEditor.commit();
62 | }
63 |
64 | /**
65 | * Retrieve a String value from the preferences.
66 | *
67 | * @param key The name of the preference to retrieve.
68 | * @return Returns the preference value if it exists, or null.
69 | * Throws ClassCastException if there is a preference with this name that is not a String.
70 | */
71 | public String getString(String key) {
72 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
73 | return mSharedPreferences.getString(key, null);
74 | }
75 |
76 | /**
77 | * Retrieve a String value from the preferences.
78 | *
79 | * @param key The name of the preference to retrieve.
80 | * @param defaultValue Value to return if this preference does not exist.
81 | * @return Returns the preference value if it exists, or defaultValue.
82 | * Throws ClassCastException if there is a preference with this name that is not a String.
83 | */
84 | public String getString(String key, String defaultValue) {
85 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
86 | return mSharedPreferences.getString(key, defaultValue);
87 | }
88 |
89 | /**
90 | * Retrieve a int value from the preferences.
91 | *
92 | * @param key The name of the preference to retrieve.
93 | * @return Returns the preference value if it exists, or 0.
94 | * Throws ClassCastException if there is a preference with this name that is not a int.
95 | */
96 | public int getInt(String key) {
97 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
98 | return mSharedPreferences.getInt(key, 0);
99 | }
100 |
101 | /**
102 | * Retrieve a int value from the preferences.
103 | *
104 | * @param key The name of the preference to retrieve.
105 | * @param defaultValue Value to return if this preference does not exist.
106 | * @return Returns the preference value if it exists, or defaultValue.
107 | * Throws ClassCastException if there is a preference with this name that is not a int.
108 | */
109 | public int getInt(String key, int defaultValue) {
110 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
111 | return mSharedPreferences.getInt(key, defaultValue);
112 | }
113 |
114 | /**
115 | * Retrieve a boolean value from the preferences.
116 | *
117 | * @param key The name of the preference to retrieve.
118 | * @return Returns the preference value if it exists, or false.
119 | * Throws ClassCastException if there is a preference with this name that is not a boolean.
120 | */
121 | public boolean getBoolean(String key) {
122 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
123 | return mSharedPreferences.getBoolean(key, false);
124 | }
125 |
126 | /**
127 | * Retrieve a boolean value from the preferences.
128 | *
129 | * @param key The name of the preference to retrieve.
130 | * @param defaultValue Value to return if this preference does not exist.
131 | * @return Returns the preference value if it exists, or defaultValue.
132 | * Throws ClassCastException if there is a preference with this name that is not a boolean.
133 | */
134 | public boolean getBoolean(String key, boolean defaultValue) {
135 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
136 | return mSharedPreferences.getBoolean(key, defaultValue);
137 | }
138 |
139 | /**
140 | * Clears the shared preference file
141 | */
142 | public void clear() {
143 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
144 | mSharedPreferences.edit().clear().apply();
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi-v11/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-hdpi-v11/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-hdpi/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi-v11/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-mdpi-v11/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-mdpi/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/firebase_chat_splash.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-nodpi/firebase_chat_splash.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi-v11/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-xhdpi-v11/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-xhdpi/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi-v11/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-xxhdpi-v11/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-xxhdpi/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi-v11/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-xxxhdpi-v11/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/drawable-xxxhdpi/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/chat_rounded_rect_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_accent.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_error_24dp.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_rect_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_chat.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_user_listing.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
24 |
25 |
26 |
27 |
32 |
33 |
44 |
45 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_chat.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
25 |
26 |
29 |
30 |
37 |
38 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
25 |
26 |
29 |
30 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_users.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_all_user_listing.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
27 |
28 |
31 |
32 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_chat_mine.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
26 |
27 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_chat_other.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
26 |
27 |
30 |
31 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_user_listing.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
15 |
22 |
23 |
28 |
29 |
30 |
31 |
34 |
35 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_user_listing.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/mipmap-hdpi/ic_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/mipmap-mdpi/ic_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/mipmap-xhdpi/ic_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/mipmap-xxhdpi/ic_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/app/src/main/res/mipmap-xxxhdpi/ic_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @color/blue_grey_500
4 | @color/blue_grey_700
5 | @color/cyan_700
6 |
7 | #FFEBEE
8 | #FFCDD2
9 | #EF9A9A
10 | #E57373
11 | #EF5350
12 | #F44336
13 | #E53935
14 | #D32F2F
15 | #C62828
16 | #B71C1C
17 | #FF8A80
18 | #FF5252
19 | #FF1744
20 | #D50000
21 |
22 | #EDE7F6
23 | #D1C4E9
24 | #B39DDB
25 | #9575CD
26 | #7E57C2
27 | #673AB7
28 | #5E35B1
29 | #512DA8
30 | #4527A0
31 | #311B92
32 | #B388FF
33 | #7C4DFF
34 | #651FFF
35 | #6200EA
36 |
37 | #E1F5FE
38 | #B3E5FC
39 | #81D4FA
40 | #4FC3F7
41 | #29B6F6
42 | #03A9F4
43 | #039BE5
44 | #0288D1
45 | #0277BD
46 | #01579B
47 | #80D8FF
48 | #40C4FF
49 | #00B0FF
50 | #0091EA
51 |
52 | #E8F5E9
53 | #C8E6C9
54 | #A5D6A7
55 | #81C784
56 | #66BB6A
57 | #4CAF50
58 | #43A047
59 | #388E3C
60 | #2E7D32
61 | #1B5E20
62 | #B9F6CA
63 | #69F0AE
64 | #00E676
65 | #00C853
66 |
67 | #FFFDE7
68 | #FFF9C4
69 | #FFF59D
70 | #FFF176
71 | #FFEE58
72 | #FFEB3B
73 | #FDD835
74 | #FBC02D
75 | #F9A825
76 | #F57F17
77 | #FFFF8D
78 | #FFFF00
79 | #FFEA00
80 | #FFD600
81 |
82 | #FBE9E7
83 | #FFCCBC
84 | #FFAB91
85 | #FF8A65
86 | #FF7043
87 | #FF5722
88 | #F4511E
89 | #E64A19
90 | #D84315
91 | #BF360C
92 | #FF9E80
93 | #FF6E40
94 | #FF3D00
95 | #DD2C00
96 |
97 | #ECEFF1
98 | #CFD8DC
99 | #B0BEC5
100 | #90A4AE
101 | #78909C
102 | #607D8B
103 | #546E7A
104 | #455A64
105 | #37474F
106 | #263238
107 |
108 | #FCE4EC
109 | #F8BBD0
110 | #F48FB1
111 | #F06292
112 | #EC407A
113 | #E91E63
114 | #D81B60
115 | #C2185B
116 | #AD1457
117 | #880E4F
118 | #FF80AB
119 | #FF4081
120 | #F50057
121 | #C51162
122 |
123 | #E8EAF6
124 | #C5CAE9
125 | #9FA8DA
126 | #7986CB
127 | #5C6BC0
128 | #3F51B5
129 | #3949AB
130 | #303F9F
131 | #283593
132 | #1A237E
133 | #8C9EFF
134 | #536DFE
135 | #3D5AFE
136 | #304FFE
137 |
138 | #E0F7FA
139 | #B2EBF2
140 | #80DEEA
141 | #4DD0E1
142 | #26C6DA
143 | #00BCD4
144 | #00ACC1
145 | #0097A7
146 | #00838F
147 | #006064
148 | #84FFFF
149 | #18FFFF
150 | #00E5FF
151 | #00B8D4
152 |
153 | #F1F8E9
154 | #DCEDC8
155 | #C5E1A5
156 | #AED581
157 | #9CCC65
158 | #8BC34A
159 | #7CB342
160 | #689F38
161 | #558B2F
162 | #33691E
163 | #CCFF90
164 | #B2FF59
165 | #76FF03
166 | #64DD17
167 |
168 | #FFF8E1
169 | #FFECB3
170 | #FFE082
171 | #FFD54F
172 | #FFCA28
173 | #FFC107
174 | #FFB300
175 | #FFA000
176 | #FF8F00
177 | #FF6F00
178 | #FFE57F
179 | #FFD740
180 | #FFC400
181 | #FFAB00
182 |
183 | #EFEBE9
184 | #D7CCC8
185 | #BCAAA4
186 | #A1887F
187 | #8D6E63
188 | #795548
189 | #6D4C41
190 | #5D4037
191 | #4E342E
192 | #3E2723
193 |
194 | #F3E5F5
195 | #E1BEE7
196 | #CE93D8
197 | #BA68C8
198 | #AB47BC
199 | #9C27B0
200 | #8E24AA
201 | #7B1FA2
202 | #6A1B9A
203 | #4A148C
204 | #EA80FC
205 | #E040FB
206 | #D500F9
207 | #AA00FF
208 |
209 | #E3F2FD
210 | #BBDEFB
211 | #90CAF9
212 | #64B5F6
213 | #42A5F5
214 | #2196F3
215 | #1E88E5
216 | #1976D2
217 | #1565C0
218 | #0D47A1
219 | #82B1FF
220 | #448AFF
221 | #2979FF
222 | #2962FF
223 |
224 | #E0F2F1
225 | #B2DFDB
226 | #80CBC4
227 | #4DB6AC
228 | #26A69A
229 | #009688
230 | #00897B
231 | #00796B
232 | #00695C
233 | #004D40
234 | #A7FFEB
235 | #64FFDA
236 | #1DE9B6
237 | #00BFA5
238 |
239 | #F9FBE7
240 | #F0F4C3
241 | #E6EE9C
242 | #DCE775
243 | #D4E157
244 | #CDDC39
245 | #C0CA33
246 | #AFB42B
247 | #9E9D24
248 | #827717
249 | #F4FF81
250 | #EEFF41
251 | #C6FF00
252 | #AEEA00
253 |
254 | #FFF3E0
255 | #FFE0B2
256 | #FFCC80
257 | #FFB74D
258 | #FFA726
259 | #FF9800
260 | #FB8C00
261 | #F57C00
262 | #EF6C00
263 | #E65100
264 | #FFD180
265 | #FFAB40
266 | #FF9100
267 | #FF6D00
268 |
269 | #FAFAFA
270 | #F5F5F5
271 | #EEEEEE
272 | #E0E0E0
273 | #BDBDBD
274 | #9E9E9E
275 | #757575
276 | #616161
277 | #424242
278 | #212121
279 |
280 | #000000
281 | #FFFFFF
282 |
283 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 | 4dp
8 | 8dp
9 | 16dp
10 | 32dp
11 |
12 | 4dp
13 | 8dp
14 | 16dp
15 | 32dp
16 |
17 | 4dp
18 | 8dp
19 | 16dp
20 | 32dp
21 | 64dp
22 |
23 | 36dp
24 | 36dp
25 |
26 | 4dp
27 | 4dp
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FirebaseChat
3 | Settings
4 | Email Id
5 | Password
6 | Login
7 | New user, tap here to register !
8 | Register
9 |
10 | User successfully added!
11 | Unable to add user!
12 | Adding user to database.
13 | Loading
14 | Please wait...
15 |
16 | sans-serif-thin
17 | Type a message...
18 | Logout
19 | SplashActivity
20 | Logout
21 | Are you sure ?
22 | Cancel
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/test/java/com/crazyhitty/chdev/ks/firebasechat/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.crazyhitty.chdev.ks.firebasechat;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 | classpath 'com.google.gms:google-services:3.0.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshots/chat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/screenshots/chat.png
--------------------------------------------------------------------------------
/screenshots/login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/screenshots/login.png
--------------------------------------------------------------------------------
/screenshots/push_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/screenshots/push_notification.png
--------------------------------------------------------------------------------
/screenshots/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/screenshots/splash.png
--------------------------------------------------------------------------------
/screenshots/users.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazyhitty/firebase-chat/1ac7bf79bba308c49f8dbffac0eee2e65d97fec1/screenshots/users.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------