users) {
30 | mView.onGetAllUsersSuccess(users);
31 | }
32 |
33 | @Override
34 | public void onGetAllUsersFailure(String message) {
35 | mView.onGetAllUsersFailure(message);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/events/PushNotificationEvent.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.events;
2 |
3 | /**
4 | * Created by delaroy on 4/13/17.
5 | */
6 | public class PushNotificationEvent {
7 | private String title;
8 | private String message;
9 | private String username;
10 | private String uid;
11 | private String fcmToken;
12 | public PushNotificationEvent() {
13 | }
14 |
15 | public PushNotificationEvent(String title, String message, String username, String uid, String fcmToken) {
16 | this.title = title;
17 | this.message = message;
18 | this.username = username;
19 | this.uid = uid;
20 | this.fcmToken = fcmToken;
21 | }
22 |
23 | public String getTitle() {
24 | return title;
25 | }
26 |
27 | public void setTitle(String title) {
28 | this.title = title;
29 | }
30 |
31 | public String getMessage() {
32 | return message;
33 | }
34 |
35 | public void setMessage(String message) {
36 | this.message = message;
37 | }
38 |
39 | public String getUsername() {
40 | return username;
41 | }
42 |
43 | public void setUsername(String username) {
44 | this.username = username;
45 | }
46 |
47 | public String getUid() {
48 | return uid;
49 | }
50 |
51 | public void setUid(String uid) {
52 | this.uid = uid;
53 | }
54 |
55 | public String getFcmToken() {
56 | return fcmToken;
57 | }
58 |
59 | public void setFcmToken(String fcmToken) {
60 | this.fcmToken = fcmToken;
61 | }
62 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/fcm/FcmNotificationBuilder.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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 |
20 | public class FcmNotificationBuilder {
21 | public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
22 | private static final String TAG = "FcmNotificationBuilder";
23 | private static final String SERVER_API_KEY = "YOUR_SERVER_API_KEY";
24 | private static final String CONTENT_TYPE = "Content-Type";
25 | private static final String APPLICATION_JSON = "application/json";
26 | private static final String AUTHORIZATION = "Authorization";
27 | private static final String AUTH_KEY = "key=" + SERVER_API_KEY;
28 | private static final String FCM_URL = "https://fcm.googleapis.com/fcm/send";
29 | // json related keys
30 | private static final String KEY_TO = "to";
31 | private static final String KEY_NOTIFICATION = "notification";
32 | private static final String KEY_TITLE = "title";
33 | private static final String KEY_TEXT = "text";
34 | private static final String KEY_DATA = "data";
35 | private static final String KEY_USERNAME = "username";
36 | private static final String KEY_UID = "uid";
37 | private static final String KEY_FCM_TOKEN = "fcm_token";
38 |
39 | private String mTitle;
40 | private String mMessage;
41 | private String mUsername;
42 | private String mUid;
43 | private String mFirebaseToken;
44 | private String mReceiverFirebaseToken;
45 |
46 | private FcmNotificationBuilder() {
47 |
48 | }
49 |
50 | public static FcmNotificationBuilder initialize() {
51 | return new FcmNotificationBuilder();
52 | }
53 |
54 | public FcmNotificationBuilder title(String title) {
55 | mTitle = title;
56 | return this;
57 | }
58 |
59 | public FcmNotificationBuilder message(String message) {
60 | mMessage = message;
61 | return this;
62 | }
63 |
64 | public FcmNotificationBuilder username(String username) {
65 | mUsername = username;
66 | return this;
67 | }
68 |
69 | public FcmNotificationBuilder uid(String uid) {
70 | mUid = uid;
71 | return this;
72 | }
73 |
74 | public FcmNotificationBuilder firebaseToken(String firebaseToken) {
75 | mFirebaseToken = firebaseToken;
76 | return this;
77 | }
78 |
79 | public FcmNotificationBuilder receiverFirebaseToken(String receiverFirebaseToken) {
80 | mReceiverFirebaseToken = receiverFirebaseToken;
81 | return this;
82 | }
83 |
84 | public void send() {
85 | RequestBody requestBody = null;
86 | try {
87 | requestBody = RequestBody.create(MEDIA_TYPE_JSON, getValidJsonBody().toString());
88 | } catch (JSONException e) {
89 | e.printStackTrace();
90 | }
91 |
92 | Request request = new Request.Builder()
93 | .addHeader(CONTENT_TYPE, APPLICATION_JSON)
94 | .addHeader(AUTHORIZATION, AUTH_KEY)
95 | .url(FCM_URL)
96 | .post(requestBody)
97 | .build();
98 |
99 | Call call = new OkHttpClient().newCall(request);
100 | call.enqueue(new Callback() {
101 | @Override
102 | public void onFailure(Call call, IOException e) {
103 | Log.e(TAG, "onGetAllUsersFailure: " + e.getMessage());
104 | }
105 |
106 | @Override
107 | public void onResponse(Call call, Response response) throws IOException {
108 | Log.e(TAG, "onResponse: " + response.body().string());
109 | }
110 | });
111 | }
112 |
113 | private JSONObject getValidJsonBody() throws JSONException {
114 | JSONObject jsonObjectBody = new JSONObject();
115 | jsonObjectBody.put(KEY_TO, mReceiverFirebaseToken);
116 |
117 | JSONObject jsonObjectData = new JSONObject();
118 | jsonObjectData.put(KEY_TITLE, mTitle);
119 | jsonObjectData.put(KEY_TEXT, mMessage);
120 | jsonObjectData.put(KEY_USERNAME, mUsername);
121 | jsonObjectData.put(KEY_UID, mUid);
122 | jsonObjectData.put(KEY_FCM_TOKEN, mFirebaseToken);
123 | jsonObjectBody.put(KEY_DATA, jsonObjectData);
124 |
125 | return jsonObjectBody;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/fcm/MyFirebaseInstanceIDService.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.fcm;
2 |
3 | import android.util.Log;
4 |
5 | import com.delaroystudios.firebasechat.utils.Constants;
6 | import com.delaroystudios.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/delaroystudios/firebasechat/fcm/MyFirebaseMessagingService.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.FirebaseChatMainApp;
13 | import com.delaroystudios.firebasechat.R;
14 | import com.delaroystudios.firebasechat.events.PushNotificationEvent;
15 | import com.delaroystudios.firebasechat.ui.activities.ChatActivity;
16 | import com.delaroystudios.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/delaroystudios/firebasechat/models/Chat.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.models;
2 |
3 | /**
4 | * Created by delaroy on 4/13/17.
5 | */
6 | public class Chat {
7 | public String sender;
8 | public String receiver;
9 | public String senderUid;
10 | public String receiverUid;
11 | public String message;
12 | public long timestamp;
13 |
14 | public Chat(){
15 |
16 | }
17 |
18 | public Chat(String sender, String receiver, String senderUid, String receiverUid, String message, long timestamp){
19 | this.sender = sender;
20 | this.receiver = receiver;
21 | this.senderUid = senderUid;
22 | this.receiverUid = receiverUid;
23 | this.message = message;
24 | this.timestamp = timestamp;
25 |
26 | }
27 |
28 |
29 |
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/models/User.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.models;
2 |
3 | /**
4 | * Created by delaroy on 4/13/17.
5 | */
6 | public class User {
7 | public String uid;
8 | public String email;
9 | public String firebaseToken;
10 |
11 | public User(){
12 |
13 | }
14 |
15 | public User(String uid, String email, String firebaseToken){
16 | this.uid = uid;
17 | this.email = email;
18 | this.firebaseToken = firebaseToken;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/models/Users.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.models;
2 |
3 | /**
4 | * Created by delaroy on 4/13/17.
5 | */
6 | public class Users {
7 |
8 | private String emailId;
9 | private String lastMessage;
10 | private int notifCount;
11 |
12 | public String getEmailId(){ return emailId; }
13 |
14 | public void setEmailId(){ this.emailId = emailId; }
15 |
16 | public String getLastMessage(){ return lastMessage; }
17 |
18 | public void setLastMessage(){ this.lastMessage = lastMessage; }
19 |
20 | public int getNotifCount(){ return notifCount; }
21 |
22 | public void setNotifCount(int notifCount){ this.notifCount = notifCount; }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/activities/ChatActivity.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.FirebaseChatMainApp;
11 | import com.delaroystudios.firebasechat.R;
12 | import com.delaroystudios.firebasechat.ui.fragments.ChatFragment;
13 | import com.delaroystudios.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/delaroystudios/firebasechat/ui/activities/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
11 | import com.delaroystudios.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/delaroystudios/firebasechat/ui/activities/RegisterActivity.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
11 | import com.delaroystudios.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/delaroystudios/firebasechat/ui/activities/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.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/delaroystudios/firebasechat/ui/activities/UserListingActivity.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
17 | import com.delaroystudios.firebasechat.core.logout.LogoutContract;
18 | import com.delaroystudios.firebasechat.core.logout.LogoutPresenter;
19 | import com.delaroystudios.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/delaroystudios/firebasechat/ui/adapters/ChatRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
11 | import com.delaroystudios.firebasechat.models.Chat;
12 | import com.google.firebase.auth.FirebaseAuth;
13 |
14 | import java.util.List;
15 |
16 |
17 |
18 | public class ChatRecyclerAdapter extends RecyclerView.Adapter {
19 | private static final int VIEW_TYPE_ME = 1;
20 | private static final int VIEW_TYPE_OTHER = 2;
21 |
22 | private List mChats;
23 |
24 | public ChatRecyclerAdapter(List chats) {
25 | mChats = chats;
26 | }
27 |
28 | public void add(Chat chat) {
29 | mChats.add(chat);
30 | notifyItemInserted(mChats.size() - 1);
31 | }
32 |
33 | @Override
34 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
35 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
36 | RecyclerView.ViewHolder viewHolder = null;
37 | switch (viewType) {
38 | case VIEW_TYPE_ME:
39 | View viewChatMine = layoutInflater.inflate(R.layout.item_chat_mine, parent, false);
40 | viewHolder = new MyChatViewHolder(viewChatMine);
41 | break;
42 | case VIEW_TYPE_OTHER:
43 | View viewChatOther = layoutInflater.inflate(R.layout.item_chat_other, parent, false);
44 | viewHolder = new OtherChatViewHolder(viewChatOther);
45 | break;
46 | }
47 | return viewHolder;
48 | }
49 |
50 | @Override
51 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
52 | if (TextUtils.equals(mChats.get(position).senderUid,
53 | FirebaseAuth.getInstance().getCurrentUser().getUid())) {
54 | configureMyChatViewHolder((MyChatViewHolder) holder, position);
55 | } else {
56 | configureOtherChatViewHolder((OtherChatViewHolder) holder, position);
57 | }
58 | }
59 |
60 | private void configureMyChatViewHolder(MyChatViewHolder myChatViewHolder, int position) {
61 | Chat chat = mChats.get(position);
62 |
63 | String alphabet = chat.sender.substring(0, 1);
64 |
65 | myChatViewHolder.txtChatMessage.setText(chat.message);
66 | myChatViewHolder.txtUserAlphabet.setText(alphabet);
67 | }
68 |
69 | private void configureOtherChatViewHolder(OtherChatViewHolder otherChatViewHolder, int position) {
70 | Chat chat = mChats.get(position);
71 |
72 | String alphabet = chat.sender.substring(0, 1);
73 |
74 | otherChatViewHolder.txtChatMessage.setText(chat.message);
75 | otherChatViewHolder.txtUserAlphabet.setText(alphabet);
76 | }
77 |
78 | @Override
79 | public int getItemCount() {
80 | if (mChats != null) {
81 | return mChats.size();
82 | }
83 | return 0;
84 | }
85 |
86 | @Override
87 | public int getItemViewType(int position) {
88 | if (TextUtils.equals(mChats.get(position).senderUid,
89 | FirebaseAuth.getInstance().getCurrentUser().getUid())) {
90 | return VIEW_TYPE_ME;
91 | } else {
92 | return VIEW_TYPE_OTHER;
93 | }
94 | }
95 |
96 | private static class MyChatViewHolder extends RecyclerView.ViewHolder {
97 | private TextView txtChatMessage, txtUserAlphabet;
98 |
99 | public MyChatViewHolder(View itemView) {
100 | super(itemView);
101 | txtChatMessage = (TextView) itemView.findViewById(R.id.text_view_chat_message);
102 | txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
103 | }
104 | }
105 |
106 | private static class OtherChatViewHolder extends RecyclerView.ViewHolder {
107 | private TextView txtChatMessage, txtUserAlphabet;
108 |
109 | public OtherChatViewHolder(View itemView) {
110 | super(itemView);
111 | txtChatMessage = (TextView) itemView.findViewById(R.id.text_view_chat_message);
112 | txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/adapters/UserListingPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.ui.fragments.UsersFragment;
8 |
9 |
10 | public class UserListingPagerAdapter extends FragmentPagerAdapter {
11 | private static final Fragment[] sFragments = new Fragment[]{/*UsersFragment.newInstance(UsersFragment.TYPE_CHATS),*/
12 | UsersFragment.newInstance(UsersFragment.TYPE_ALL)};
13 | private static final String[] sTitles = new String[]{/*"Chats",*/
14 | "All Users"};
15 |
16 | public UserListingPagerAdapter(FragmentManager fm) {
17 | super(fm);
18 | }
19 |
20 | @Override
21 | public Fragment getItem(int position) {
22 | return sFragments[position];
23 | }
24 |
25 | @Override
26 | public int getCount() {
27 | return sFragments.length;
28 | }
29 |
30 | @Override
31 | public CharSequence getPageTitle(int position) {
32 | return sTitles[position];
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/adapters/UserListingRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
10 | import com.delaroystudios.firebasechat.models.User;
11 |
12 | import java.util.List;
13 |
14 |
15 |
16 | public class UserListingRecyclerAdapter extends RecyclerView.Adapter {
17 | private List mUsers;
18 |
19 | public UserListingRecyclerAdapter(List users) {
20 | this.mUsers = users;
21 | }
22 |
23 | public void add(User user) {
24 | mUsers.add(user);
25 | notifyItemInserted(mUsers.size() - 1);
26 | }
27 |
28 | @Override
29 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
30 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_all_user_listing, parent, false);
31 | return new ViewHolder(view);
32 | }
33 |
34 | @Override
35 | public void onBindViewHolder(ViewHolder holder, int position) {
36 | User user = mUsers.get(position);
37 |
38 | if (user.email != null){
39 | String alphabet = user.email.substring(0, 1);
40 |
41 | holder.txtUsername.setText(user.email);
42 | holder.txtUserAlphabet.setText(alphabet);
43 | }
44 | }
45 |
46 | @Override
47 | public int getItemCount() {
48 | if (mUsers != null) {
49 | return mUsers.size();
50 | }
51 | return 0;
52 | }
53 |
54 | public User getUser(int position) {
55 | return mUsers.get(position);
56 | }
57 |
58 | static class ViewHolder extends RecyclerView.ViewHolder {
59 | private TextView txtUserAlphabet, txtUsername;
60 |
61 | ViewHolder(View itemView) {
62 | super(itemView);
63 | txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
64 | txtUsername = (TextView) itemView.findViewById(R.id.text_view_username);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/fragments/ChatFragment.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
18 | import com.delaroystudios.firebasechat.core.chat.ChatContract;
19 | import com.delaroystudios.firebasechat.core.chat.ChatPresenter;
20 | import com.delaroystudios.firebasechat.events.PushNotificationEvent;
21 | import com.delaroystudios.firebasechat.models.Chat;
22 | import com.delaroystudios.firebasechat.ui.adapters.ChatRecyclerAdapter;
23 | import com.delaroystudios.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 |
33 | public class ChatFragment extends Fragment implements ChatContract.View, TextView.OnEditorActionListener {
34 | private RecyclerView mRecyclerViewChat;
35 | private EditText mETxtMessage;
36 |
37 | private ProgressDialog mProgressDialog;
38 |
39 | private ChatRecyclerAdapter mChatRecyclerAdapter;
40 |
41 | private ChatPresenter mChatPresenter;
42 |
43 | public static ChatFragment newInstance(String receiver,
44 | String receiverUid,
45 | String firebaseToken) {
46 | Bundle args = new Bundle();
47 | args.putString(Constants.ARG_RECEIVER, receiver);
48 | args.putString(Constants.ARG_RECEIVER_UID, receiverUid);
49 | args.putString(Constants.ARG_FIREBASE_TOKEN, firebaseToken);
50 | ChatFragment fragment = new ChatFragment();
51 | fragment.setArguments(args);
52 | return fragment;
53 | }
54 |
55 | @Override
56 | public void onStart() {
57 | super.onStart();
58 | EventBus.getDefault().register(this);
59 | }
60 |
61 | @Override
62 | public void onStop() {
63 | super.onStop();
64 | EventBus.getDefault().unregister(this);
65 | }
66 |
67 | @Nullable
68 | @Override
69 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
70 | View fragmentView = inflater.inflate(R.layout.fragment_chat, container, false);
71 | bindViews(fragmentView);
72 | return fragmentView;
73 | }
74 |
75 | private void bindViews(View view) {
76 | mRecyclerViewChat = (RecyclerView) view.findViewById(R.id.recycler_view_chat);
77 | mETxtMessage = (EditText) view.findViewById(R.id.edit_text_message);
78 | }
79 |
80 | @Override
81 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
82 | super.onActivityCreated(savedInstanceState);
83 | init();
84 | }
85 |
86 | private void init() {
87 | mProgressDialog = new ProgressDialog(getActivity());
88 | mProgressDialog.setTitle(getString(R.string.loading));
89 | mProgressDialog.setMessage(getString(R.string.please_wait));
90 | mProgressDialog.setIndeterminate(true);
91 |
92 | mETxtMessage.setOnEditorActionListener(this);
93 |
94 | mChatPresenter = new ChatPresenter(this);
95 | mChatPresenter.getMessage(FirebaseAuth.getInstance().getCurrentUser().getUid(),
96 | getArguments().getString(Constants.ARG_RECEIVER_UID));
97 | }
98 |
99 | @Override
100 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
101 | if (actionId == EditorInfo.IME_ACTION_SEND) {
102 | sendMessage();
103 | return true;
104 | }
105 | return false;
106 | }
107 |
108 | private void sendMessage() {
109 | String message = mETxtMessage.getText().toString();
110 | String receiver = getArguments().getString(Constants.ARG_RECEIVER);
111 | String receiverUid = getArguments().getString(Constants.ARG_RECEIVER_UID);
112 | String sender = FirebaseAuth.getInstance().getCurrentUser().getEmail();
113 | String senderUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
114 | String receiverFirebaseToken = getArguments().getString(Constants.ARG_FIREBASE_TOKEN);
115 | Chat chat = new Chat(sender,
116 | receiver,
117 | senderUid,
118 | receiverUid,
119 | message,
120 | System.currentTimeMillis());
121 | mChatPresenter.sendMessage(getActivity().getApplicationContext(),
122 | chat,
123 | receiverFirebaseToken);
124 | }
125 |
126 | @Override
127 | public void onSendMessageSuccess() {
128 | mETxtMessage.setText("");
129 | Toast.makeText(getActivity(), "Message sent", Toast.LENGTH_SHORT).show();
130 | }
131 |
132 | @Override
133 | public void onSendMessageFailure(String message) {
134 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
135 | }
136 |
137 | @Override
138 | public void onGetMessagesSuccess(Chat chat) {
139 | if (mChatRecyclerAdapter == null) {
140 | mChatRecyclerAdapter = new ChatRecyclerAdapter(new ArrayList());
141 | mRecyclerViewChat.setAdapter(mChatRecyclerAdapter);
142 | }
143 | mChatRecyclerAdapter.add(chat);
144 | mRecyclerViewChat.smoothScrollToPosition(mChatRecyclerAdapter.getItemCount() - 1);
145 | }
146 |
147 | @Override
148 | public void onGetMessagesFailure(String message) {
149 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
150 | }
151 |
152 | @Subscribe
153 | public void onPushNotificationEvent(PushNotificationEvent pushNotificationEvent) {
154 | if (mChatRecyclerAdapter == null || mChatRecyclerAdapter.getItemCount() == 0) {
155 | mChatPresenter.getMessage(FirebaseAuth.getInstance().getCurrentUser().getUid(),
156 | pushNotificationEvent.getUid());
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/fragments/LoginFragment.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
16 | import com.delaroystudios.firebasechat.core.login.LoginContract;
17 | import com.delaroystudios.firebasechat.core.login.LoginPresenter;
18 | import com.delaroystudios.firebasechat.ui.activities.RegisterActivity;
19 | import com.delaroystudios.firebasechat.ui.activities.UserListingActivity;
20 |
21 |
22 |
23 | public class LoginFragment extends Fragment implements View.OnClickListener, LoginContract.View {
24 | private LoginPresenter mLoginPresenter;
25 |
26 | private EditText mETxtEmail, mETxtPassword;
27 | private Button mBtnLogin, mBtnRegister;
28 |
29 | private ProgressDialog mProgressDialog;
30 |
31 | public static LoginFragment newInstance() {
32 | Bundle args = new Bundle();
33 | LoginFragment fragment = new LoginFragment();
34 | fragment.setArguments(args);
35 | return fragment;
36 | }
37 |
38 | @Nullable
39 | @Override
40 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
41 | View fragmentView = inflater.inflate(R.layout.fragment_login, container, false);
42 | bindViews(fragmentView);
43 | return fragmentView;
44 | }
45 |
46 | private void bindViews(View view) {
47 | mETxtEmail = (EditText) view.findViewById(R.id.edit_text_email_id);
48 | mETxtPassword = (EditText) view.findViewById(R.id.edit_text_password);
49 | mBtnLogin = (Button) view.findViewById(R.id.button_login);
50 | mBtnRegister = (Button) view.findViewById(R.id.button_register);
51 | }
52 |
53 | @Override
54 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
55 | super.onActivityCreated(savedInstanceState);
56 | init();
57 | }
58 |
59 | private void init() {
60 | mLoginPresenter = new LoginPresenter(this);
61 |
62 | mProgressDialog = new ProgressDialog(getActivity());
63 | mProgressDialog.setTitle(getString(R.string.loading));
64 | mProgressDialog.setMessage(getString(R.string.please_wait));
65 | mProgressDialog.setIndeterminate(true);
66 |
67 | mBtnLogin.setOnClickListener(this);
68 | mBtnRegister.setOnClickListener(this);
69 |
70 | setDummyCredentials();
71 | }
72 |
73 | private void setDummyCredentials() {
74 | mETxtEmail.setText("test@test.com");
75 | mETxtPassword.setText("123456");
76 | }
77 |
78 | @Override
79 | public void onClick(View view) {
80 | int viewId = view.getId();
81 |
82 | switch (viewId) {
83 | case R.id.button_login:
84 | onLogin(view);
85 | break;
86 | case R.id.button_register:
87 | onRegister(view);
88 | break;
89 | }
90 | }
91 |
92 | private void onLogin(View view) {
93 | String emailId = mETxtEmail.getText().toString();
94 | String password = mETxtPassword.getText().toString();
95 |
96 | mLoginPresenter.login(getActivity(), emailId, password);
97 | mProgressDialog.show();
98 | }
99 |
100 | private void onRegister(View view) {
101 | RegisterActivity.startActivity(getActivity());
102 | }
103 |
104 | @Override
105 | public void onLoginSuccess(String message) {
106 | mProgressDialog.dismiss();
107 | Toast.makeText(getActivity(), "Logged in successfully", Toast.LENGTH_SHORT).show();
108 | UserListingActivity.startActivity(getActivity(),
109 | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
110 | }
111 |
112 | @Override
113 | public void onLoginFailure(String message) {
114 | mProgressDialog.dismiss();
115 | Toast.makeText(getActivity(), "Error: " + message, Toast.LENGTH_SHORT).show();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/fragments/RegisterFragment.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
17 | import com.delaroystudios.firebasechat.core.registration.RegisterContract;
18 | import com.delaroystudios.firebasechat.core.registration.RegisterPresenter;
19 | import com.delaroystudios.firebasechat.core.users.add.AddUserContract;
20 | import com.delaroystudios.firebasechat.core.users.add.AddUserPresenter;
21 | import com.delaroystudios.firebasechat.ui.activities.UserListingActivity;
22 | import com.google.firebase.auth.FirebaseUser;
23 |
24 |
25 |
26 | public class RegisterFragment extends Fragment implements View.OnClickListener, RegisterContract.View, AddUserContract.View {
27 | private static final String TAG = RegisterFragment.class.getSimpleName();
28 |
29 | private RegisterPresenter mRegisterPresenter;
30 | private AddUserPresenter mAddUserPresenter;
31 |
32 | private EditText mETxtEmail, mETxtPassword;
33 | private Button mBtnRegister;
34 |
35 | private ProgressDialog mProgressDialog;
36 |
37 | public static RegisterFragment newInstance() {
38 | Bundle args = new Bundle();
39 | RegisterFragment fragment = new RegisterFragment();
40 | fragment.setArguments(args);
41 | return fragment;
42 | }
43 |
44 | @Nullable
45 | @Override
46 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
47 | View fragmentView = inflater.inflate(R.layout.fragment_register, container, false);
48 | bindViews(fragmentView);
49 | return fragmentView;
50 | }
51 |
52 | private void bindViews(View view) {
53 | mETxtEmail = (EditText) view.findViewById(R.id.edit_text_email_id);
54 | mETxtPassword = (EditText) view.findViewById(R.id.edit_text_password);
55 | mBtnRegister = (Button) view.findViewById(R.id.button_register);
56 | }
57 |
58 | @Override
59 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
60 | super.onActivityCreated(savedInstanceState);
61 | init();
62 | }
63 |
64 | private void init() {
65 | mRegisterPresenter = new RegisterPresenter(this);
66 | mAddUserPresenter = new AddUserPresenter(this);
67 |
68 | mProgressDialog = new ProgressDialog(getActivity());
69 | mProgressDialog.setTitle(getString(R.string.loading));
70 | mProgressDialog.setMessage(getString(R.string.please_wait));
71 | mProgressDialog.setIndeterminate(true);
72 |
73 | mBtnRegister.setOnClickListener(this);
74 | }
75 |
76 | @Override
77 | public void onClick(View view) {
78 | int viewId = view.getId();
79 |
80 | switch (viewId) {
81 | case R.id.button_register:
82 | onRegister(view);
83 | break;
84 | }
85 | }
86 |
87 | private void onRegister(View view) {
88 | String emailId = mETxtEmail.getText().toString();
89 | String password = mETxtPassword.getText().toString();
90 |
91 | mRegisterPresenter.register(getActivity(), emailId, password);
92 | mProgressDialog.show();
93 | }
94 |
95 | @Override
96 | public void onRegistrationSuccess(FirebaseUser firebaseUser) {
97 | mProgressDialog.setMessage(getString(R.string.adding_user_to_db));
98 | Toast.makeText(getActivity(), "Registration Successful!", Toast.LENGTH_SHORT).show();
99 | mAddUserPresenter.addUser(getActivity().getApplicationContext(), firebaseUser);
100 | }
101 |
102 | @Override
103 | public void onRegistrationFailure(String message) {
104 | mProgressDialog.dismiss();
105 | mProgressDialog.setMessage(getString(R.string.please_wait));
106 | Log.e(TAG, "onRegistrationFailure: " + message);
107 | Toast.makeText(getActivity(), "Registration failed!+\n" + message, Toast.LENGTH_LONG).show();
108 | }
109 |
110 | @Override
111 | public void onAddUserSuccess(String message) {
112 | mProgressDialog.dismiss();
113 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
114 | UserListingActivity.startActivity(getActivity(),
115 | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
116 | }
117 |
118 | @Override
119 | public void onAddUserFailure(String message) {
120 | mProgressDialog.dismiss();
121 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/ui/fragments/UsersFragment.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
15 | import com.delaroystudios.firebasechat.core.users.getall.GetUsersContract;
16 | import com.delaroystudios.firebasechat.core.users.getall.GetUsersPresenter;
17 | import com.delaroystudios.firebasechat.models.User;
18 | import com.delaroystudios.firebasechat.ui.activities.ChatActivity;
19 | import com.delaroystudios.firebasechat.ui.adapters.UserListingRecyclerAdapter;
20 | import com.delaroystudios.firebasechat.utils.ItemClickSupport;
21 |
22 | import java.util.List;
23 |
24 |
25 |
26 | public class UsersFragment extends Fragment implements GetUsersContract.View, ItemClickSupport.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
27 | public static final String ARG_TYPE = "type";
28 | public static final String TYPE_CHATS = "type_chats";
29 | public static final String TYPE_ALL = "type_all";
30 |
31 | private SwipeRefreshLayout mSwipeRefreshLayout;
32 | private RecyclerView mRecyclerViewAllUserListing;
33 |
34 | private UserListingRecyclerAdapter mUserListingRecyclerAdapter;
35 |
36 | private GetUsersPresenter mGetUsersPresenter;
37 |
38 | public static UsersFragment newInstance(String type) {
39 | Bundle args = new Bundle();
40 | args.putString(ARG_TYPE, type);
41 | UsersFragment fragment = new UsersFragment();
42 | fragment.setArguments(args);
43 | return fragment;
44 | }
45 |
46 | @Nullable
47 | @Override
48 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
49 | View fragmentView = inflater.inflate(R.layout.fragment_users, container, false);
50 | bindViews(fragmentView);
51 | return fragmentView;
52 | }
53 |
54 | private void bindViews(View view) {
55 | mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
56 | mRecyclerViewAllUserListing = (RecyclerView) view.findViewById(R.id.recycler_view_all_user_listing);
57 | }
58 |
59 | @Override
60 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
61 | super.onActivityCreated(savedInstanceState);
62 | init();
63 | }
64 |
65 | private void init() {
66 | mGetUsersPresenter = new GetUsersPresenter(this);
67 | getUsers();
68 | mSwipeRefreshLayout.post(new Runnable() {
69 | @Override
70 | public void run() {
71 | mSwipeRefreshLayout.setRefreshing(true);
72 | }
73 | });
74 |
75 | ItemClickSupport.addTo(mRecyclerViewAllUserListing)
76 | .setOnItemClickListener(this);
77 |
78 | mSwipeRefreshLayout.setOnRefreshListener(this);
79 | }
80 |
81 | @Override
82 | public void onRefresh() {
83 | getUsers();
84 | }
85 |
86 | private void getUsers() {
87 | if (TextUtils.equals(getArguments().getString(ARG_TYPE), TYPE_CHATS)) {
88 |
89 | } else if (TextUtils.equals(getArguments().getString(ARG_TYPE), TYPE_ALL)) {
90 | mGetUsersPresenter.getAllUsers();
91 | }
92 | }
93 |
94 | @Override
95 | public void onItemClicked(RecyclerView recyclerView, int position, View v) {
96 | ChatActivity.startActivity(getActivity(),
97 | mUserListingRecyclerAdapter.getUser(position).email,
98 | mUserListingRecyclerAdapter.getUser(position).uid,
99 | mUserListingRecyclerAdapter.getUser(position).firebaseToken);
100 | }
101 |
102 | @Override
103 | public void onGetAllUsersSuccess(List users) {
104 | mSwipeRefreshLayout.post(new Runnable() {
105 | @Override
106 | public void run() {
107 | mSwipeRefreshLayout.setRefreshing(false);
108 | }
109 | });
110 | mUserListingRecyclerAdapter = new UserListingRecyclerAdapter(users);
111 | mRecyclerViewAllUserListing.setAdapter(mUserListingRecyclerAdapter);
112 | mUserListingRecyclerAdapter.notifyDataSetChanged();
113 | }
114 |
115 | @Override
116 | public void onGetAllUsersFailure(String message) {
117 | mSwipeRefreshLayout.post(new Runnable() {
118 | @Override
119 | public void run() {
120 | mSwipeRefreshLayout.setRefreshing(false);
121 | }
122 | });
123 | Toast.makeText(getActivity(), "Error: " + message, Toast.LENGTH_SHORT).show();
124 | }
125 |
126 | @Override
127 | public void onGetChatUsersSuccess(List users) {
128 |
129 | }
130 |
131 | @Override
132 | public void onGetChatUsersFailure(String message) {
133 |
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/utils/Constants.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.utils;
2 |
3 |
4 |
5 | public class Constants {
6 | public static final String ARG_USERS = "users";
7 | public static final String ARG_RECEIVER = "receiver";
8 | public static final String ARG_RECEIVER_UID = "receiver_uid";
9 | public static final String ARG_CHAT_ROOMS = "chat_rooms";
10 | public static final String ARG_FIREBASE_TOKEN = "firebaseToken";
11 | public static final String ARG_FRIENDS = "friends";
12 | public static final String ARG_UID = "uid";
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/utils/ItemClickSupport.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.utils;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | import com.delaroystudios.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/delaroystudios/firebasechat/utils/NetworkConnectionUtil.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.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.delaroystudios.firebasechat.R;
12 |
13 |
14 | public class NetworkConnectionUtil {
15 | public static final String ERR_DIALOG_TITLE = "No internet connection detected !";
16 | private static final String ERR_DIALOG_MSG = "Looks like our application is not able to detect an active internet connection, " +
17 | "please check your device's network settings.";
18 | private static final String ERR_DIALOG_POSITIVE_BTN = "Settings";
19 | private static final String ERR_DIALOG_NEGATIVE_BTN = "Dismiss";
20 |
21 | /**
22 | * Check if the device is connected to internet or not.
23 | *
24 | * @param context Current context of the application
25 | * @return true if device is connected to internet, otherwise false
26 | */
27 | public static boolean isConnectedToInternet(Context context) {
28 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
29 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
30 | return networkInfo != null && networkInfo.isConnectedOrConnecting();
31 | }
32 |
33 | /**
34 | * Check if the device is connected to internet via wifi or not.
35 | *
36 | * @param context Current context of the application
37 | * @return true if device is connected to internet via wifi, otherwise false
38 | */
39 | public static boolean isConnectedToWifi(Context context) {
40 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
41 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
42 | return networkInfo != null &&
43 | networkInfo.isConnectedOrConnecting() &&
44 | networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
45 | }
46 |
47 | /**
48 | * Check if the device is connected to internet via mobile network or not.
49 | *
50 | * @param context Current context of the application
51 | * @return true if device is connected to internet via mobile network, otherwise false
52 | */
53 | public static boolean isConnectedToMobileNetwork(Context context) {
54 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
55 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
56 | return networkInfo != null &&
57 | networkInfo.isConnectedOrConnecting() &&
58 | networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
59 | }
60 |
61 | /**
62 | * Show a error dialog representing that no internet connection is available currently.
63 | *
64 | * @param context Current context of the application
65 | */
66 | public static void showNoInternetAvailableErrorDialog(final Context context) {
67 | new AlertDialog.Builder(context)
68 | .setTitle(ERR_DIALOG_TITLE)
69 | .setMessage(ERR_DIALOG_MSG)
70 | .setIcon(R.drawable.ic_error_24dp)
71 | .setPositiveButton(ERR_DIALOG_POSITIVE_BTN, new DialogInterface.OnClickListener() {
72 | @Override
73 | public void onClick(DialogInterface dialogInterface, int i) {
74 | dialogInterface.dismiss();
75 | Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
76 | context.startActivity(intent);
77 | }
78 | })
79 | .setNegativeButton(ERR_DIALOG_NEGATIVE_BTN, new DialogInterface.OnClickListener() {
80 | @Override
81 | public void onClick(DialogInterface dialogInterface, int i) {
82 | dialogInterface.dismiss();
83 | }
84 | })
85 | .show();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/delaroystudios/firebasechat/utils/SharedPrefUtil.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 |
7 | public class SharedPrefUtil {
8 | /**
9 | * Name of the preference file
10 | */
11 | private static final String APP_PREFS = "application_preferences";
12 |
13 | private Context mContext;
14 | private SharedPreferences mSharedPreferences;
15 | private SharedPreferences.Editor mEditor;
16 |
17 | public SharedPrefUtil(Context mContext) {
18 | this.mContext = mContext;
19 | }
20 |
21 | /**
22 | * Save a string into shared preference
23 | *
24 | * @param key The name of the preference to modify
25 | * @param value The new value for the preference
26 | */
27 | public void saveString(String key, String value) {
28 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
29 | mEditor = mSharedPreferences.edit();
30 | mEditor.putString(key, value);
31 | mEditor.commit();
32 | }
33 |
34 | /**
35 | * Save a int into shared preference
36 | *
37 | * @param key The name of the preference to modify
38 | * @param value The new value for the preference
39 | */
40 | public void saveInt(String key, int value) {
41 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
42 | mEditor = mSharedPreferences.edit();
43 | mEditor.putInt(key, value);
44 | mEditor.commit();
45 | }
46 |
47 | /**
48 | * Save a boolean into shared preference
49 | *
50 | * @param key The name of the preference to modify
51 | * @param value The new value for the preference
52 | */
53 | public void saveBoolean(String key, boolean value) {
54 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
55 | mEditor = mSharedPreferences.edit();
56 | mEditor.putBoolean(key, value);
57 | mEditor.commit();
58 | }
59 |
60 | /**
61 | * Retrieve a String value from the preferences.
62 | *
63 | * @param key The name of the preference to retrieve.
64 | * @return Returns the preference value if it exists, or null.
65 | * Throws ClassCastException if there is a preference with this name that is not a String.
66 | */
67 | public String getString(String key) {
68 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
69 | return mSharedPreferences.getString(key, null);
70 | }
71 |
72 | /**
73 | * Retrieve a String value from the preferences.
74 | *
75 | * @param key The name of the preference to retrieve.
76 | * @param defaultValue Value to return if this preference does not exist.
77 | * @return Returns the preference value if it exists, or defaultValue.
78 | * Throws ClassCastException if there is a preference with this name that is not a String.
79 | */
80 | public String getString(String key, String defaultValue) {
81 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
82 | return mSharedPreferences.getString(key, defaultValue);
83 | }
84 |
85 | /**
86 | * Retrieve a int value from the preferences.
87 | *
88 | * @param key The name of the preference to retrieve.
89 | * @return Returns the preference value if it exists, or 0.
90 | * Throws ClassCastException if there is a preference with this name that is not a int.
91 | */
92 | public int getInt(String key) {
93 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
94 | return mSharedPreferences.getInt(key, 0);
95 | }
96 |
97 | /**
98 | * Retrieve a int value from the preferences.
99 | *
100 | * @param key The name of the preference to retrieve.
101 | * @param defaultValue Value to return if this preference does not exist.
102 | * @return Returns the preference value if it exists, or defaultValue.
103 | * Throws ClassCastException if there is a preference with this name that is not a int.
104 | */
105 | public int getInt(String key, int defaultValue) {
106 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
107 | return mSharedPreferences.getInt(key, defaultValue);
108 | }
109 |
110 | /**
111 | * Retrieve a boolean value from the preferences.
112 | *
113 | * @param key The name of the preference to retrieve.
114 | * @return Returns the preference value if it exists, or false.
115 | * Throws ClassCastException if there is a preference with this name that is not a boolean.
116 | */
117 | public boolean getBoolean(String key) {
118 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
119 | return mSharedPreferences.getBoolean(key, false);
120 | }
121 |
122 | /**
123 | * Retrieve a boolean value from the preferences.
124 | *
125 | * @param key The name of the preference to retrieve.
126 | * @param defaultValue Value to return if this preference does not exist.
127 | * @return Returns the preference value if it exists, or defaultValue.
128 | * Throws ClassCastException if there is a preference with this name that is not a boolean.
129 | */
130 | public boolean getBoolean(String key, boolean defaultValue) {
131 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
132 | return mSharedPreferences.getBoolean(key, defaultValue);
133 | }
134 |
135 | /**
136 | * Clears the shared preference file
137 | */
138 | public void clear() {
139 | mSharedPreferences = mContext.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
140 | mSharedPreferences.edit().clear().apply();
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/drawable/bg.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/chat_rounded_rect_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/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 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_messaging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/drawable/ic_messaging.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_rect_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/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 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
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 | 4dp
7 | 8dp
8 | 16dp
9 | 32dp
10 |
11 | 4dp
12 | 8dp
13 | 16dp
14 | 32dp
15 |
16 | 4dp
17 | 8dp
18 | 16dp
19 | 32dp
20 | 64dp
21 |
22 | 36dp
23 | 36dp
24 |
25 | 4dp
26 | 4dp
27 |
28 |
--------------------------------------------------------------------------------
/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/delaroystudios/firebasechat/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.delaroystudios.firebasechat;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/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.3'
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 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delaroy/AndroidFirbaseChat/f6d09457b536c40d7e26c032191f3084f54c32fb/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 12 09:43:58 WAT 2017
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.14.1-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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------