├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml └── misc.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── mychatapptutorial │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── mychatapptutorial │ │ │ ├── MainActivity.java │ │ │ ├── Messages.java │ │ │ ├── MessagesAdapter.java │ │ │ ├── PagerAdapter.java │ │ │ ├── ProfileActivity.java │ │ │ ├── UpdateProfile.java │ │ │ ├── callFragment.java │ │ │ ├── chatActivity.java │ │ │ ├── chatFragment.java │ │ │ ├── firebasemodel.java │ │ │ ├── otpAuthentication.java │ │ │ ├── setProfile.java │ │ │ ├── specificchat.java │ │ │ ├── splashscreen.java │ │ │ ├── statusFragment.java │ │ │ └── userprofile.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── defaultprofile.png │ │ ├── ic_baseline_arrow_back_24.xml │ │ ├── ic_baseline_arrow_forward_24.xml │ │ ├── ic_baseline_more_vert_24.xml │ │ ├── ic_baseline_person_24.xml │ │ ├── ic_launcher_background.xml │ │ ├── messagebackgroun.xml │ │ ├── mychatapplogo.png │ │ ├── recieverchatdrawble.xml │ │ └── senderchatdrawable.xml │ │ ├── font │ │ ├── playlist.ttf │ │ └── raleway.ttf │ │ ├── layout │ │ ├── activity_chat.xml │ │ ├── activity_main.xml │ │ ├── activity_otp_authentication.xml │ │ ├── activity_profile.xml │ │ ├── activity_set_profile.xml │ │ ├── activity_specificchat.xml │ │ ├── activity_splashscreen.xml │ │ ├── activity_update_profile.xml │ │ ├── callfragment.xml │ │ ├── chatfragment.xml │ │ ├── chatviewlayout.xml │ │ ├── recieverchatlayout.xml │ │ ├── senderchatlayout.xml │ │ └── statusfragment.xml │ │ ├── menu │ │ └── menu.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── example │ └── mychatapptutorial │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chatAppInAndroidStudio 2 | This chat app is created in android studio using java and firebase 3 | Some of the Output screens 4 | ![image](https://user-images.githubusercontent.com/64765400/119440006-5a5e0100-bcd8-11eb-88fb-0712bb223f78.png) 5 | 6 | ![image](https://user-images.githubusercontent.com/64765400/119440053-706bc180-bcd8-11eb-8bb7-2f0b6c5c43df.png) 7 | 8 | ![image](https://user-images.githubusercontent.com/64765400/119440063-75307580-bcd8-11eb-8da2-f3629f67c145.png) 9 | 10 | ![image](https://user-images.githubusercontent.com/64765400/119440078-7f527400-bcd8-11eb-97bc-287362d5d764.png) 11 | 12 | ![image](https://user-images.githubusercontent.com/64765400/119440082-82e5fb00-bcd8-11eb-9c99-3dfeae3e17ee.png) 13 | 14 | ![image](https://user-images.githubusercontent.com/64765400/119440112-91ccad80-bcd8-11eb-9bba-8e7c24034da4.png) 15 | 16 | ![image](https://user-images.githubusercontent.com/64765400/119440138-9b561580-bcd8-11eb-8cdf-76c3a6a4d902.png) 17 | 18 | ![image](https://user-images.githubusercontent.com/64765400/119440156-a14bf680-bcd8-11eb-9818-2533a8f1dfa4.png) 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'com.google.gms.google-services' 4 | } 5 | 6 | android { 7 | compileSdkVersion 30 8 | buildToolsVersion "30.0.3" 9 | 10 | defaultConfig { 11 | applicationId "com.example.mychatapptutorial" 12 | minSdkVersion 21 13 | targetSdkVersion 30 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | } 31 | 32 | dependencies { 33 | 34 | implementation 'androidx.appcompat:appcompat:1.2.0' 35 | implementation 'com.google.android.material:material:1.3.0' 36 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 37 | implementation 'com.google.firebase:firebase-auth:20.0.4' 38 | implementation 'com.google.firebase:firebase-database:19.7.0' 39 | implementation 'com.google.firebase:firebase-firestore:22.1.2' 40 | implementation 'com.google.firebase:firebase-storage:19.2.2' 41 | testImplementation 'junit:junit:4.+' 42 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 43 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 44 | implementation 'com.hbb20:ccp:2.5.1' 45 | 46 | implementation 'com.squareup.picasso:picasso:2.71828' 47 | 48 | 49 | implementation 'com.firebaseui:firebase-ui-firestore:4.1.0' 50 | 51 | 52 | 53 | 54 | 55 | } -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "944214901903", 4 | "project_id": "mychatapptutorial-754ba", 5 | "storage_bucket": "mychatapptutorial-754ba.appspot.com" 6 | }, 7 | "client": [ 8 | { 9 | "client_info": { 10 | "mobilesdk_app_id": "1:944214901903:android:d1316af7e9de06e2891cfa", 11 | "android_client_info": { 12 | "package_name": "com.example.mychatapptutorial" 13 | } 14 | }, 15 | "oauth_client": [ 16 | { 17 | "client_id": "944214901903-vvuuqoj6gl7d1m55ijna0khao074v2e6.apps.googleusercontent.com", 18 | "client_type": 1, 19 | "android_info": { 20 | "package_name": "com.example.mychatapptutorial", 21 | "certificate_hash": "150941ba8656894c715789791f187679ab1d0171" 22 | } 23 | }, 24 | { 25 | "client_id": "944214901903-1pg1avsiht7dr9rnkl41om485i8qsgvh.apps.googleusercontent.com", 26 | "client_type": 3 27 | } 28 | ], 29 | "api_key": [ 30 | { 31 | "current_key": "AIzaSyBnmRtf1GhHDseyn1rFbeF28bB-F83-T-U" 32 | } 33 | ], 34 | "services": { 35 | "appinvite_service": { 36 | "other_platform_oauth_client": [ 37 | { 38 | "client_id": "944214901903-1pg1avsiht7dr9rnkl41om485i8qsgvh.apps.googleusercontent.com", 39 | "client_type": 3 40 | } 41 | ] 42 | } 43 | } 44 | } 45 | ], 46 | "configuration_version": "1" 47 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/mychatapptutorial/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.example.mychatapptutorial", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.EditText; 10 | import android.widget.ProgressBar; 11 | import android.widget.Toast; 12 | 13 | import com.google.firebase.FirebaseException; 14 | import com.google.firebase.auth.FirebaseAuth; 15 | import com.google.firebase.auth.PhoneAuthCredential; 16 | import com.google.firebase.auth.PhoneAuthOptions; 17 | import com.google.firebase.auth.PhoneAuthProvider; 18 | import com.google.firestore.v1.TargetOrBuilder; 19 | import com.hbb20.CountryCodePicker; 20 | 21 | import java.util.concurrent.TimeUnit; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | 25 | 26 | 27 | EditText mgetphonenumber; 28 | android.widget.Button msendotp; 29 | CountryCodePicker mcountrycodepicker; 30 | String countrycode; 31 | String phonenumber; 32 | 33 | FirebaseAuth firebaseAuth; 34 | ProgressBar mprogressbarofmain; 35 | 36 | 37 | 38 | PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks; 39 | String codesent; 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_main); 45 | mcountrycodepicker=findViewById(R.id.countrycodepicker); 46 | msendotp=findViewById(R.id.sendotpbutton); 47 | mgetphonenumber=findViewById(R.id.getphonenumber); 48 | mprogressbarofmain=findViewById(R.id.progressbarofmain); 49 | 50 | firebaseAuth=FirebaseAuth.getInstance(); 51 | 52 | countrycode=mcountrycodepicker.getSelectedCountryCodeWithPlus(); 53 | 54 | mcountrycodepicker.setOnCountryChangeListener(new CountryCodePicker.OnCountryChangeListener() { 55 | @Override 56 | public void onCountrySelected() { 57 | countrycode=mcountrycodepicker.getSelectedCountryCodeWithPlus(); 58 | } 59 | }); 60 | 61 | msendotp.setOnClickListener(new View.OnClickListener() { 62 | @Override 63 | public void onClick(View view) { 64 | String number; 65 | number=mgetphonenumber.getText().toString(); 66 | if(number.isEmpty()) 67 | { 68 | Toast.makeText(getApplicationContext(),"Please Enter YOur number",Toast.LENGTH_SHORT).show(); 69 | } 70 | else if(number.length()<10) 71 | { 72 | Toast.makeText(getApplicationContext(),"Please Enter correct number",Toast.LENGTH_SHORT).show(); 73 | } 74 | else 75 | { 76 | 77 | mprogressbarofmain.setVisibility(View.VISIBLE); 78 | phonenumber=countrycode+number; 79 | 80 | PhoneAuthOptions options=PhoneAuthOptions.newBuilder(firebaseAuth) 81 | .setPhoneNumber(phonenumber) 82 | .setTimeout(60L, TimeUnit.SECONDS) 83 | .setActivity(MainActivity.this) 84 | .setCallbacks(mCallbacks) 85 | .build(); 86 | 87 | 88 | PhoneAuthProvider.verifyPhoneNumber(options); 89 | 90 | 91 | 92 | } 93 | 94 | 95 | } 96 | }); 97 | 98 | 99 | 100 | mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { 101 | @Override 102 | public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) { 103 | //how to automatically fetch code here 104 | } 105 | 106 | @Override 107 | public void onVerificationFailed(@NonNull FirebaseException e) { 108 | 109 | } 110 | 111 | 112 | @Override 113 | public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) { 114 | super.onCodeSent(s, forceResendingToken); 115 | Toast.makeText(getApplicationContext(),"OTP is Sent",Toast.LENGTH_SHORT).show(); 116 | mprogressbarofmain.setVisibility(View.INVISIBLE); 117 | codesent=s; 118 | Intent intent=new Intent(MainActivity.this,otpAuthentication.class); 119 | intent.putExtra("otp",codesent); 120 | startActivity(intent); 121 | } 122 | }; 123 | 124 | 125 | 126 | } 127 | 128 | 129 | @Override 130 | protected void onStart() { 131 | super.onStart(); 132 | if(FirebaseAuth.getInstance().getCurrentUser()!=null) 133 | { 134 | Intent intent=new Intent(MainActivity.this,chatActivity.class); 135 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK); 136 | startActivity(intent); 137 | } 138 | 139 | 140 | 141 | 142 | 143 | 144 | } 145 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/Messages.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | public class Messages { 4 | 5 | String message; 6 | String senderId; 7 | long timestamp; 8 | String currenttime; 9 | 10 | 11 | public Messages() { 12 | } 13 | 14 | 15 | public Messages(String message, String senderId, long timestamp, String currenttime) { 16 | this.message = message; 17 | this.senderId = senderId; 18 | this.timestamp = timestamp; 19 | this.currenttime = currenttime; 20 | } 21 | 22 | public String getMessage() { 23 | return message; 24 | } 25 | 26 | public void setMessage(String message) { 27 | this.message = message; 28 | } 29 | 30 | public String getSenderId() { 31 | return senderId; 32 | } 33 | 34 | public void setSenderId(String senderId) { 35 | this.senderId = senderId; 36 | } 37 | 38 | public long getTimestamp() { 39 | return timestamp; 40 | } 41 | 42 | public void setTimestamp(long timestamp) { 43 | this.timestamp = timestamp; 44 | } 45 | 46 | public String getCurrenttime() { 47 | return currenttime; 48 | } 49 | 50 | public void setCurrenttime(String currenttime) { 51 | this.currenttime = currenttime; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/MessagesAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.core.content.ContextCompat; 11 | import androidx.recyclerview.widget.RecyclerView; 12 | 13 | import com.google.firebase.auth.FirebaseAuth; 14 | 15 | import java.util.ArrayList; 16 | 17 | public class MessagesAdapter extends RecyclerView.Adapter { 18 | 19 | Context context; 20 | ArrayList messagesArrayList; 21 | 22 | int ITEM_SEND=1; 23 | int ITEM_RECIEVE=2; 24 | 25 | public MessagesAdapter(Context context, ArrayList messagesArrayList) { 26 | this.context = context; 27 | this.messagesArrayList = messagesArrayList; 28 | } 29 | 30 | @NonNull 31 | @Override 32 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 33 | if(viewType==ITEM_SEND) 34 | { 35 | View view= LayoutInflater.from(context).inflate(R.layout.senderchatlayout,parent,false); 36 | return new SenderViewHolder(view); 37 | } 38 | else 39 | { 40 | View view= LayoutInflater.from(context).inflate(R.layout.recieverchatlayout,parent,false); 41 | return new RecieverViewHolder(view); 42 | } 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { 47 | 48 | Messages messages=messagesArrayList.get(position); 49 | if(holder.getClass()==SenderViewHolder.class) 50 | { 51 | SenderViewHolder viewHolder=(SenderViewHolder)holder; 52 | viewHolder.textViewmessaage.setText(messages.getMessage()); 53 | viewHolder.timeofmessage.setText(messages.getCurrenttime()); 54 | } 55 | else 56 | { 57 | RecieverViewHolder viewHolder=(RecieverViewHolder)holder; 58 | viewHolder.textViewmessaage.setText(messages.getMessage()); 59 | viewHolder.timeofmessage.setText(messages.getCurrenttime()); 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | } 70 | 71 | 72 | @Override 73 | public int getItemViewType(int position) { 74 | Messages messages=messagesArrayList.get(position); 75 | if(FirebaseAuth.getInstance().getCurrentUser().getUid().equals(messages.getSenderId())) 76 | 77 | { 78 | return ITEM_SEND; 79 | } 80 | else 81 | { 82 | return ITEM_RECIEVE; 83 | } 84 | } 85 | 86 | @Override 87 | public int getItemCount() { 88 | return messagesArrayList.size(); 89 | } 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | class SenderViewHolder extends RecyclerView.ViewHolder 99 | { 100 | 101 | TextView textViewmessaage; 102 | TextView timeofmessage; 103 | 104 | 105 | public SenderViewHolder(@NonNull View itemView) { 106 | super(itemView); 107 | textViewmessaage=itemView.findViewById(R.id.sendermessage); 108 | timeofmessage=itemView.findViewById(R.id.timeofmessage); 109 | } 110 | } 111 | 112 | class RecieverViewHolder extends RecyclerView.ViewHolder 113 | { 114 | 115 | TextView textViewmessaage; 116 | TextView timeofmessage; 117 | 118 | 119 | public RecieverViewHolder(@NonNull View itemView) { 120 | super(itemView); 121 | textViewmessaage=itemView.findViewById(R.id.sendermessage); 122 | timeofmessage=itemView.findViewById(R.id.timeofmessage); 123 | } 124 | } 125 | 126 | 127 | 128 | 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/PagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.fragment.app.Fragment; 5 | import androidx.fragment.app.FragmentManager; 6 | import androidx.fragment.app.FragmentPagerAdapter; 7 | 8 | public class PagerAdapter extends FragmentPagerAdapter { 9 | 10 | int tabcount; 11 | 12 | 13 | 14 | 15 | public PagerAdapter(@NonNull FragmentManager fm, int behavior) { 16 | super(fm, behavior); 17 | tabcount=behavior; 18 | 19 | 20 | 21 | 22 | } 23 | 24 | @NonNull 25 | @Override 26 | public Fragment getItem(int position) { 27 | switch (position) 28 | { 29 | case 0: 30 | return new chatFragment(); 31 | 32 | 33 | case 1: 34 | return new statusFragment(); 35 | 36 | case 2: 37 | 38 | return new callFragment(); 39 | 40 | 41 | default: 42 | return null; 43 | } 44 | 45 | 46 | 47 | } 48 | 49 | @Override 50 | public int getCount() { 51 | return tabcount; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/ProfileActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Bundle; 9 | import android.view.View; 10 | import android.widget.EditText; 11 | import android.widget.ImageButton; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | import android.widget.Toolbar; 16 | 17 | import com.google.android.gms.tasks.OnSuccessListener; 18 | import com.google.firebase.auth.FirebaseAuth; 19 | import com.google.firebase.database.DataSnapshot; 20 | import com.google.firebase.database.DatabaseError; 21 | import com.google.firebase.database.DatabaseReference; 22 | import com.google.firebase.database.FirebaseDatabase; 23 | import com.google.firebase.database.ValueEventListener; 24 | import com.google.firebase.firestore.DocumentReference; 25 | import com.google.firebase.firestore.FirebaseFirestore; 26 | import com.google.firebase.storage.FirebaseStorage; 27 | import com.google.firebase.storage.StorageReference; 28 | import com.squareup.picasso.Picasso; 29 | 30 | public class ProfileActivity extends AppCompatActivity { 31 | 32 | 33 | EditText mviewusername; 34 | FirebaseAuth firebaseAuth; 35 | FirebaseDatabase firebaseDatabase; 36 | TextView mmovetoupdateprofile; 37 | 38 | FirebaseFirestore firebaseFirestore; 39 | 40 | ImageView mviewuserimageinimageview; 41 | 42 | StorageReference storageReference; 43 | 44 | private String ImageURIacessToken; 45 | 46 | androidx.appcompat.widget.Toolbar mtoolbarofviewprofile; 47 | ImageButton mbackbuttonofviewprofile; 48 | 49 | 50 | FirebaseStorage firebaseStorage; 51 | 52 | 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_profile); 58 | 59 | mviewuserimageinimageview=findViewById(R.id.viewuserimageinimageview); 60 | mviewusername=findViewById(R.id.viewusername); 61 | mmovetoupdateprofile=findViewById(R.id.movetoupdateprofile); 62 | firebaseFirestore=FirebaseFirestore.getInstance(); 63 | mtoolbarofviewprofile=findViewById(R.id.toolbarofviewprofile); 64 | mbackbuttonofviewprofile=findViewById(R.id.backbuttonofviewprofile); 65 | firebaseDatabase=FirebaseDatabase.getInstance(); 66 | firebaseAuth=FirebaseAuth.getInstance(); 67 | firebaseStorage=FirebaseStorage.getInstance(); 68 | 69 | 70 | setSupportActionBar(mtoolbarofviewprofile); 71 | 72 | mbackbuttonofviewprofile.setOnClickListener(new View.OnClickListener() { 73 | @Override 74 | public void onClick(View view) { 75 | finish(); 76 | } 77 | }); 78 | 79 | 80 | storageReference=firebaseStorage.getReference(); 81 | storageReference.child("Images").child(firebaseAuth.getUid()).child("Profile Pic").getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { 82 | @Override 83 | public void onSuccess(Uri uri) { 84 | ImageURIacessToken=uri.toString(); 85 | Picasso.get().load(uri).into(mviewuserimageinimageview); 86 | 87 | } 88 | }); 89 | 90 | DatabaseReference databaseReference=firebaseDatabase.getReference(firebaseAuth.getUid()); 91 | databaseReference.addValueEventListener(new ValueEventListener() { 92 | @Override 93 | public void onDataChange(@NonNull DataSnapshot snapshot) { 94 | userprofile muserprofile=snapshot.getValue(userprofile.class); 95 | mviewusername.setText(muserprofile.getUsername()); 96 | } 97 | 98 | @Override 99 | public void onCancelled(@NonNull DatabaseError error) { 100 | 101 | Toast.makeText(getApplicationContext(),"Failed To Fetch",Toast.LENGTH_SHORT).show(); 102 | } 103 | }); 104 | 105 | 106 | mmovetoupdateprofile.setOnClickListener(new View.OnClickListener() { 107 | @Override 108 | public void onClick(View view) { 109 | Intent intent=new Intent(ProfileActivity.this,UpdateProfile.class); 110 | intent.putExtra("nameofuser",mviewusername.getText().toString()); 111 | startActivity(intent); 112 | } 113 | }); 114 | 115 | 116 | 117 | 118 | } 119 | 120 | 121 | @Override 122 | protected void onStop() { 123 | super.onStop(); 124 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 125 | documentReference.update("status","Offline").addOnSuccessListener(new OnSuccessListener() { 126 | @Override 127 | public void onSuccess(Void aVoid) { 128 | Toast.makeText(getApplicationContext(),"Now User is Offline",Toast.LENGTH_SHORT).show(); 129 | } 130 | }); 131 | 132 | 133 | 134 | } 135 | 136 | @Override 137 | protected void onStart() { 138 | super.onStart(); 139 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 140 | documentReference.update("status","Online").addOnSuccessListener(new OnSuccessListener() { 141 | @Override 142 | public void onSuccess(Void aVoid) { 143 | Toast.makeText(getApplicationContext(),"Now User is Online",Toast.LENGTH_SHORT).show(); 144 | } 145 | }); 146 | 147 | } 148 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/UpdateProfile.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.annotation.Nullable; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | 7 | import android.content.Intent; 8 | import android.graphics.Bitmap; 9 | import android.media.MediaActionSound; 10 | import android.net.Uri; 11 | import android.os.Bundle; 12 | import android.provider.MediaStore; 13 | import android.view.View; 14 | import android.widget.EditText; 15 | import android.widget.ImageButton; 16 | import android.widget.ImageView; 17 | import android.widget.ProgressBar; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.google.android.gms.tasks.OnFailureListener; 22 | import com.google.android.gms.tasks.OnSuccessListener; 23 | import com.google.firebase.auth.FirebaseAuth; 24 | import com.google.firebase.database.DatabaseReference; 25 | import com.google.firebase.database.FirebaseDatabase; 26 | import com.google.firebase.firestore.DocumentReference; 27 | import com.google.firebase.firestore.FirebaseFirestore; 28 | import com.google.firebase.storage.FirebaseStorage; 29 | import com.google.firebase.storage.StorageReference; 30 | import com.google.firebase.storage.UploadTask; 31 | import com.squareup.picasso.Picasso; 32 | 33 | import java.io.ByteArrayOutputStream; 34 | import java.io.IOException; 35 | import java.util.HashMap; 36 | import java.util.Map; 37 | 38 | public class UpdateProfile extends AppCompatActivity { 39 | 40 | private EditText mnewusername; 41 | private FirebaseAuth firebaseAuth; 42 | private FirebaseDatabase firebaseDatabase; 43 | 44 | 45 | private FirebaseFirestore firebaseFirestore; 46 | 47 | private ImageView mgetnewimageinimageview; 48 | 49 | private StorageReference storageReference; 50 | 51 | private String ImageURIacessToken; 52 | 53 | private androidx.appcompat.widget.Toolbar mtoolbarofupdateprofile; 54 | private ImageButton mbackbuttonofupdateprofile; 55 | 56 | 57 | private FirebaseStorage firebaseStorage; 58 | 59 | 60 | ProgressBar mprogressbarofupdateprofile; 61 | 62 | private Uri imagepath; 63 | 64 | Intent intent; 65 | 66 | private static int PICK_IMAGE=123; 67 | 68 | android.widget.Button mupdateprofilebutton; 69 | String newname; 70 | 71 | 72 | 73 | 74 | @Override 75 | protected void onCreate(Bundle savedInstanceState) { 76 | super.onCreate(savedInstanceState); 77 | setContentView(R.layout.activity_update_profile); 78 | 79 | mtoolbarofupdateprofile=findViewById(R.id.toolbarofupdateprofile); 80 | mbackbuttonofupdateprofile=findViewById(R.id.backbuttonofupdateprofile); 81 | mgetnewimageinimageview=findViewById(R.id.getnewuserimageinimageview); 82 | mprogressbarofupdateprofile=findViewById(R.id.progressbarofupdateprofile); 83 | mnewusername=findViewById(R.id.getnewusername); 84 | mupdateprofilebutton=findViewById(R.id.updateprofilebutton); 85 | 86 | firebaseAuth=FirebaseAuth.getInstance(); 87 | firebaseDatabase=FirebaseDatabase.getInstance(); 88 | firebaseStorage=FirebaseStorage.getInstance(); 89 | firebaseFirestore=FirebaseFirestore.getInstance(); 90 | 91 | intent=getIntent(); 92 | 93 | setSupportActionBar(mtoolbarofupdateprofile); 94 | 95 | mbackbuttonofupdateprofile.setOnClickListener(new View.OnClickListener() { 96 | @Override 97 | public void onClick(View view) { 98 | finish(); 99 | } 100 | }); 101 | 102 | 103 | 104 | mnewusername.setText(intent.getStringExtra("nameofuser")); 105 | 106 | 107 | 108 | 109 | DatabaseReference databaseReference=firebaseDatabase.getReference(firebaseAuth.getUid()); 110 | 111 | mupdateprofilebutton.setOnClickListener(new View.OnClickListener() { 112 | @Override 113 | public void onClick(View view) { 114 | 115 | newname=mnewusername.getText().toString(); 116 | if(newname.isEmpty()) 117 | { 118 | Toast.makeText(getApplicationContext(),"Name is Empty",Toast.LENGTH_SHORT).show(); 119 | } 120 | else if(imagepath!=null) 121 | { 122 | mprogressbarofupdateprofile.setVisibility(View.VISIBLE); 123 | userprofile muserprofile =new userprofile(newname,firebaseAuth.getUid()); 124 | databaseReference.setValue(muserprofile); 125 | 126 | updateimagetostorage(); 127 | 128 | Toast.makeText(getApplicationContext(),"Updated",Toast.LENGTH_SHORT).show(); 129 | mprogressbarofupdateprofile.setVisibility(View.INVISIBLE); 130 | Intent intent=new Intent(UpdateProfile.this,chatActivity.class); 131 | startActivity(intent); 132 | finish(); 133 | 134 | } 135 | else 136 | { 137 | 138 | mprogressbarofupdateprofile.setVisibility(View.VISIBLE); 139 | userprofile muserprofile =new userprofile(newname,firebaseAuth.getUid()); 140 | databaseReference.setValue(muserprofile); 141 | updatenameoncloudfirestore(); 142 | Toast.makeText(getApplicationContext(),"Updated",Toast.LENGTH_SHORT).show(); 143 | mprogressbarofupdateprofile.setVisibility(View.INVISIBLE); 144 | Intent intent=new Intent(UpdateProfile.this,chatActivity.class); 145 | startActivity(intent); 146 | finish(); 147 | 148 | 149 | 150 | 151 | } 152 | 153 | 154 | 155 | 156 | 157 | } 158 | }); 159 | 160 | 161 | mgetnewimageinimageview.setOnClickListener(new View.OnClickListener() { 162 | @Override 163 | public void onClick(View view) { 164 | Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI); 165 | startActivityForResult(intent,PICK_IMAGE); 166 | } 167 | }); 168 | 169 | storageReference=firebaseStorage.getReference(); 170 | storageReference.child("Images").child(firebaseAuth.getUid()).child("Profile Pic").getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { 171 | @Override 172 | public void onSuccess(Uri uri) { 173 | ImageURIacessToken=uri.toString(); 174 | Picasso.get().load(uri).into(mgetnewimageinimageview); 175 | } 176 | }); 177 | 178 | 179 | 180 | 181 | 182 | } 183 | 184 | 185 | 186 | 187 | 188 | private void updatenameoncloudfirestore() { 189 | 190 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 191 | Map userdata=new HashMap<>(); 192 | userdata.put("name",newname); 193 | userdata.put("image",ImageURIacessToken); 194 | userdata.put("uid",firebaseAuth.getUid()); 195 | userdata.put("status","Online"); 196 | 197 | 198 | documentReference.set(userdata).addOnSuccessListener(new OnSuccessListener() { 199 | @Override 200 | public void onSuccess(Void aVoid) { 201 | Toast.makeText(getApplicationContext(),"Profile Update Succusfully",Toast.LENGTH_SHORT).show(); 202 | 203 | } 204 | }); 205 | 206 | } 207 | 208 | private void updateimagetostorage() { 209 | 210 | 211 | StorageReference imageref=storageReference.child("Images").child(firebaseAuth.getUid()).child("Profile Pic"); 212 | 213 | //Image compresesion 214 | 215 | Bitmap bitmap=null; 216 | try { 217 | bitmap= MediaStore.Images.Media.getBitmap(getContentResolver(),imagepath); 218 | } 219 | catch (IOException e) 220 | { 221 | e.printStackTrace(); 222 | } 223 | 224 | ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(); 225 | bitmap.compress(Bitmap.CompressFormat.JPEG,25,byteArrayOutputStream); 226 | byte[] data=byteArrayOutputStream.toByteArray(); 227 | 228 | ///putting image to storage 229 | 230 | UploadTask uploadTask=imageref.putBytes(data); 231 | 232 | uploadTask.addOnSuccessListener(new OnSuccessListener() { 233 | @Override 234 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 235 | 236 | imageref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { 237 | @Override 238 | public void onSuccess(Uri uri) { 239 | ImageURIacessToken=uri.toString(); 240 | Toast.makeText(getApplicationContext(),"URI get sucess",Toast.LENGTH_SHORT).show(); 241 | updatenameoncloudfirestore(); 242 | } 243 | }).addOnFailureListener(new OnFailureListener() { 244 | @Override 245 | public void onFailure(@NonNull Exception e) { 246 | Toast.makeText(getApplicationContext(),"URI get Failed",Toast.LENGTH_SHORT).show(); 247 | } 248 | 249 | 250 | }); 251 | Toast.makeText(getApplicationContext(),"Image is Updated",Toast.LENGTH_SHORT).show(); 252 | 253 | } 254 | }).addOnFailureListener(new OnFailureListener() { 255 | @Override 256 | public void onFailure(@NonNull Exception e) { 257 | Toast.makeText(getApplicationContext(),"Image Not Updated",Toast.LENGTH_SHORT).show(); 258 | } 259 | }); 260 | 261 | 262 | 263 | 264 | } 265 | 266 | 267 | @Override 268 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 269 | 270 | if(requestCode==PICK_IMAGE && resultCode==RESULT_OK) 271 | { 272 | imagepath=data.getData(); 273 | mgetnewimageinimageview.setImageURI(imagepath); 274 | } 275 | 276 | 277 | 278 | 279 | super.onActivityResult(requestCode, resultCode, data); 280 | } 281 | 282 | 283 | @Override 284 | protected void onStop() { 285 | super.onStop(); 286 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 287 | documentReference.update("status","Offline").addOnSuccessListener(new OnSuccessListener() { 288 | @Override 289 | public void onSuccess(Void aVoid) { 290 | Toast.makeText(getApplicationContext(),"Now User is Offline",Toast.LENGTH_SHORT).show(); 291 | } 292 | }); 293 | 294 | 295 | 296 | } 297 | 298 | @Override 299 | protected void onStart() { 300 | super.onStart(); 301 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 302 | documentReference.update("status","Online").addOnSuccessListener(new OnSuccessListener() { 303 | @Override 304 | public void onSuccess(Void aVoid) { 305 | Toast.makeText(getApplicationContext(),"Now User is Online",Toast.LENGTH_SHORT).show(); 306 | } 307 | }); 308 | 309 | } 310 | 311 | 312 | 313 | 314 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/callFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.fragment.app.Fragment; 11 | 12 | public class callFragment extends Fragment { 13 | 14 | @Nullable 15 | @Override 16 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 17 | return inflater.inflate(R.layout.callfragment,null); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/chatActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.core.content.ContextCompat; 6 | import androidx.viewpager.widget.ViewPager; 7 | 8 | import android.content.Intent; 9 | import android.graphics.drawable.Drawable; 10 | import android.os.Bundle; 11 | import android.view.Menu; 12 | import android.view.MenuInflater; 13 | import android.view.MenuItem; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.google.android.gms.tasks.OnSuccessListener; 18 | import com.google.android.material.tabs.TabItem; 19 | import com.google.android.material.tabs.TabLayout; 20 | import com.google.firebase.auth.FirebaseAuth; 21 | import com.google.firebase.database.FirebaseDatabase; 22 | import com.google.firebase.firestore.DocumentReference; 23 | import com.google.firebase.firestore.FirebaseFirestore; 24 | 25 | 26 | public class chatActivity extends AppCompatActivity { 27 | 28 | TabLayout tabLayout; 29 | TabItem mchat,mcall,mstatus; 30 | ViewPager viewPager; 31 | PagerAdapter pagerAdapter; 32 | androidx.appcompat.widget.Toolbar mtoolbar; 33 | 34 | FirebaseAuth firebaseAuth; 35 | 36 | 37 | FirebaseFirestore firebaseFirestore; 38 | 39 | 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_chat); 45 | 46 | tabLayout=findViewById(R.id.include); 47 | mchat=findViewById(R.id.chat); 48 | mcall=findViewById(R.id.calls); 49 | mstatus=findViewById(R.id.status); 50 | viewPager=findViewById(R.id.fragmentcontainer); 51 | 52 | firebaseFirestore=FirebaseFirestore.getInstance(); 53 | firebaseAuth=FirebaseAuth.getInstance(); 54 | 55 | mtoolbar=findViewById(R.id.toolbar); 56 | setSupportActionBar(mtoolbar); 57 | 58 | 59 | Drawable drawable= ContextCompat.getDrawable(getApplicationContext(),R.drawable.ic_baseline_more_vert_24); 60 | mtoolbar.setOverflowIcon(drawable); 61 | 62 | 63 | pagerAdapter=new PagerAdapter(getSupportFragmentManager(),tabLayout.getTabCount()); 64 | viewPager.setAdapter(pagerAdapter); 65 | 66 | tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { 67 | @Override 68 | public void onTabSelected(TabLayout.Tab tab) { 69 | viewPager.setCurrentItem(tab.getPosition()); 70 | 71 | if(tab.getPosition()==0 || tab.getPosition()==1|| tab.getPosition()==2) 72 | { 73 | pagerAdapter.notifyDataSetChanged(); 74 | } 75 | 76 | 77 | 78 | } 79 | 80 | @Override 81 | public void onTabUnselected(TabLayout.Tab tab) { 82 | 83 | } 84 | 85 | @Override 86 | public void onTabReselected(TabLayout.Tab tab) { 87 | 88 | } 89 | }); 90 | 91 | 92 | viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); 93 | 94 | 95 | } 96 | 97 | 98 | @Override 99 | public boolean onOptionsItemSelected(@NonNull MenuItem item) { 100 | 101 | switch (item.getItemId()) 102 | { 103 | case R.id.profile: 104 | Intent intent=new Intent(chatActivity.this,ProfileActivity.class); 105 | startActivity(intent); 106 | break; 107 | 108 | case R.id.settings: 109 | Toast.makeText(getApplicationContext(),"Settign is clicked",Toast.LENGTH_SHORT).show(); 110 | break; 111 | } 112 | 113 | 114 | 115 | return true; 116 | } 117 | 118 | 119 | @Override 120 | public boolean onCreateOptionsMenu(Menu menu) { 121 | 122 | MenuInflater menuInflater=getMenuInflater(); 123 | menuInflater.inflate(R.menu.menu,menu); 124 | 125 | 126 | return true; 127 | } 128 | 129 | @Override 130 | protected void onStop() { 131 | super.onStop(); 132 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 133 | documentReference.update("status","Offline").addOnSuccessListener(new OnSuccessListener() { 134 | @Override 135 | public void onSuccess(Void aVoid) { 136 | Toast.makeText(getApplicationContext(),"Now User is Offline",Toast.LENGTH_SHORT).show(); 137 | } 138 | }); 139 | 140 | 141 | 142 | } 143 | 144 | @Override 145 | protected void onStart() { 146 | super.onStart(); 147 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 148 | documentReference.update("status","Online").addOnSuccessListener(new OnSuccessListener() { 149 | @Override 150 | public void onSuccess(Void aVoid) { 151 | Toast.makeText(getApplicationContext(),"Now User is Online",Toast.LENGTH_SHORT).show(); 152 | } 153 | }); 154 | 155 | } 156 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/chatFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import androidx.annotation.NonNull; 14 | import androidx.annotation.Nullable; 15 | import androidx.fragment.app.Fragment; 16 | import androidx.recyclerview.widget.LinearLayoutManager; 17 | import androidx.recyclerview.widget.RecyclerView; 18 | 19 | import com.firebase.ui.firestore.FirestoreRecyclerAdapter; 20 | import com.firebase.ui.firestore.FirestoreRecyclerOptions; 21 | import com.google.firebase.auth.FirebaseAuth; 22 | import com.google.firebase.firestore.FirebaseFirestore; 23 | import com.google.firebase.firestore.Query; 24 | import com.google.firebase.storage.FirebaseStorage; 25 | import com.squareup.picasso.Picasso; 26 | 27 | 28 | public class chatFragment extends Fragment { 29 | 30 | private FirebaseFirestore firebaseFirestore; 31 | LinearLayoutManager linearLayoutManager; 32 | private FirebaseAuth firebaseAuth; 33 | 34 | ImageView mimageviewofuser; 35 | 36 | FirestoreRecyclerAdapter chatAdapter; 37 | 38 | RecyclerView mrecyclerview; 39 | 40 | 41 | 42 | @Nullable 43 | @Override 44 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 45 | View v=inflater.inflate(R.layout.chatfragment,container,false); 46 | 47 | firebaseAuth=FirebaseAuth.getInstance(); 48 | firebaseFirestore= FirebaseFirestore.getInstance(); 49 | mrecyclerview=v.findViewById(R.id.recyclerview); 50 | 51 | 52 | // Query query=firebaseFirestore.collection("Users"); 53 | Query query=firebaseFirestore.collection("Users").whereNotEqualTo("uid",firebaseAuth.getUid()); 54 | FirestoreRecyclerOptions allusername=new FirestoreRecyclerOptions.Builder().setQuery(query,firebasemodel.class).build(); 55 | 56 | chatAdapter=new FirestoreRecyclerAdapter(allusername) { 57 | @Override 58 | protected void onBindViewHolder(@NonNull NoteViewHolder noteViewHolder, int i, @NonNull firebasemodel firebasemodel) { 59 | 60 | noteViewHolder.particularusername.setText(firebasemodel.getName()); 61 | String uri=firebasemodel.getImage(); 62 | 63 | Picasso.get().load(uri).into(mimageviewofuser); 64 | if(firebasemodel.getStatus().equals("Online")) 65 | { 66 | noteViewHolder.statusofuser.setText(firebasemodel.getStatus()); 67 | noteViewHolder.statusofuser.setTextColor(Color.GREEN); 68 | } 69 | else 70 | { 71 | noteViewHolder.statusofuser.setText(firebasemodel.getStatus()); 72 | } 73 | 74 | noteViewHolder.itemView.setOnClickListener(new View.OnClickListener() { 75 | @Override 76 | public void onClick(View view) { 77 | Intent intent=new Intent(getActivity(),specificchat.class); 78 | intent.putExtra("name",firebasemodel.getName()); 79 | intent.putExtra("receiveruid",firebasemodel.getUid()); 80 | intent.putExtra("imageuri",firebasemodel.getImage()); 81 | startActivity(intent); 82 | } 83 | }); 84 | 85 | 86 | 87 | } 88 | 89 | @NonNull 90 | @Override 91 | public NoteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 92 | 93 | View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.chatviewlayout,parent,false); 94 | return new NoteViewHolder(view); 95 | } 96 | }; 97 | 98 | 99 | mrecyclerview.setHasFixedSize(true); 100 | linearLayoutManager=new LinearLayoutManager(getContext()); 101 | linearLayoutManager.setOrientation(RecyclerView.VERTICAL); 102 | mrecyclerview.setLayoutManager(linearLayoutManager); 103 | mrecyclerview.setAdapter(chatAdapter); 104 | 105 | 106 | return v; 107 | 108 | 109 | 110 | 111 | } 112 | 113 | 114 | public class NoteViewHolder extends RecyclerView.ViewHolder 115 | { 116 | 117 | private TextView particularusername; 118 | private TextView statusofuser; 119 | 120 | public NoteViewHolder(@NonNull View itemView) { 121 | super(itemView); 122 | particularusername=itemView.findViewById(R.id.nameofuser); 123 | statusofuser=itemView.findViewById(R.id.statusofuser); 124 | mimageviewofuser=itemView.findViewById(R.id.imageviewofuser); 125 | 126 | 127 | 128 | 129 | } 130 | } 131 | 132 | @Override 133 | public void onStart() { 134 | super.onStart(); 135 | chatAdapter.startListening(); 136 | } 137 | 138 | @Override 139 | public void onStop() { 140 | super.onStop(); 141 | if(chatAdapter!=null) 142 | { 143 | chatAdapter.stopListening(); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/firebasemodel.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | public class firebasemodel { 4 | 5 | String name; 6 | String image; 7 | String uid; 8 | String status; 9 | 10 | 11 | public firebasemodel(String name, String image, String uid, String status) { 12 | this.name = name; 13 | this.image = image; 14 | this.uid = uid; 15 | this.status = status; 16 | } 17 | 18 | public firebasemodel() { 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getImage() { 30 | return image; 31 | } 32 | 33 | public void setImage(String image) { 34 | this.image = image; 35 | } 36 | 37 | public String getUid() { 38 | return uid; 39 | } 40 | 41 | public void setUid(String uid) { 42 | this.uid = uid; 43 | } 44 | 45 | public String getStatus() { 46 | return status; 47 | } 48 | 49 | public void setStatus(String status) { 50 | this.status = status; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/otpAuthentication.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.EditText; 10 | import android.widget.ProgressBar; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import com.google.android.gms.tasks.OnCompleteListener; 15 | import com.google.android.gms.tasks.Task; 16 | import com.google.firebase.auth.AuthResult; 17 | import com.google.firebase.auth.FirebaseAuth; 18 | import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException; 19 | import com.google.firebase.auth.PhoneAuthCredential; 20 | import com.google.firebase.auth.PhoneAuthProvider; 21 | 22 | public class otpAuthentication extends AppCompatActivity { 23 | 24 | TextView mchangenumber; 25 | EditText mgetotp; 26 | android.widget.Button mverifyotp; 27 | String enteredotp; 28 | 29 | FirebaseAuth firebaseAuth; 30 | ProgressBar mprogressbarofotpauth; 31 | 32 | 33 | 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_otp_authentication); 39 | 40 | mchangenumber=findViewById(R.id.changenumber); 41 | mverifyotp=findViewById(R.id.verifyotp); 42 | mgetotp=findViewById(R.id.getotp); 43 | mprogressbarofotpauth=findViewById(R.id.progressbarofotpauth); 44 | 45 | firebaseAuth=FirebaseAuth.getInstance(); 46 | 47 | mchangenumber.setOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View view) { 50 | Intent intent=new Intent(otpAuthentication.this,MainActivity.class); 51 | 52 | startActivity(intent); 53 | } 54 | }); 55 | 56 | mverifyotp.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | enteredotp=mgetotp.getText().toString(); 60 | if(enteredotp.isEmpty()) 61 | { 62 | Toast.makeText(getApplicationContext(),"Enter your OTP First ",Toast.LENGTH_SHORT).show(); 63 | } 64 | else 65 | 66 | { 67 | mprogressbarofotpauth.setVisibility(View.VISIBLE); 68 | String coderecieved=getIntent().getStringExtra("otp"); 69 | PhoneAuthCredential credential= PhoneAuthProvider.getCredential(coderecieved,enteredotp); 70 | signInWithPhoneAuthCredential(credential); 71 | 72 | } 73 | } 74 | }); 75 | 76 | 77 | 78 | } 79 | 80 | 81 | private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) 82 | { 83 | firebaseAuth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener() { 84 | @Override 85 | public void onComplete(@NonNull Task task) { 86 | if(task.isSuccessful()) 87 | { 88 | mprogressbarofotpauth.setVisibility(View.INVISIBLE); 89 | Toast.makeText(getApplicationContext(),"Login sucess",Toast.LENGTH_SHORT).show(); 90 | Intent intent=new Intent(otpAuthentication.this,setProfile.class); 91 | startActivity(intent); 92 | finish(); 93 | } 94 | else 95 | { 96 | if(task.getException() instanceof FirebaseAuthInvalidCredentialsException) 97 | { 98 | mprogressbarofotpauth.setVisibility(View.INVISIBLE); 99 | Toast.makeText(getApplicationContext(),"Login Failed",Toast.LENGTH_SHORT).show(); 100 | } 101 | } 102 | } 103 | }); 104 | 105 | 106 | 107 | 108 | } 109 | 110 | 111 | 112 | 113 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/setProfile.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.annotation.Nullable; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import androidx.cardview.widget.CardView; 7 | 8 | import android.content.Intent; 9 | import android.graphics.Bitmap; 10 | import android.net.Uri; 11 | import android.os.Bundle; 12 | import android.provider.MediaStore; 13 | import android.view.View; 14 | import android.widget.EditText; 15 | import android.widget.ImageView; 16 | import android.widget.ProgressBar; 17 | import android.widget.Toast; 18 | 19 | import com.google.android.gms.tasks.OnFailureListener; 20 | import com.google.android.gms.tasks.OnSuccessListener; 21 | import com.google.firebase.auth.FirebaseAuth; 22 | import com.google.firebase.database.DatabaseReference; 23 | import com.google.firebase.database.FirebaseDatabase; 24 | import com.google.firebase.firestore.DocumentReference; 25 | import com.google.firebase.firestore.FirebaseFirestore; 26 | import com.google.firebase.storage.FirebaseStorage; 27 | import com.google.firebase.storage.StorageReference; 28 | import com.google.firebase.storage.UploadTask; 29 | 30 | import java.io.ByteArrayOutputStream; 31 | import java.io.IOException; 32 | import java.util.HashMap; 33 | import java.util.Map; 34 | 35 | public class setProfile extends AppCompatActivity { 36 | 37 | private CardView mgetuserimage; 38 | private ImageView mgetuserimageinimageview; 39 | private static int PICK_IMAGE=123; 40 | private Uri imagepath; 41 | 42 | private EditText mgetusername; 43 | 44 | private android.widget.Button msaveprofile; 45 | 46 | private FirebaseAuth firebaseAuth; 47 | private String name; 48 | 49 | private FirebaseStorage firebaseStorage; 50 | private StorageReference storageReference; 51 | 52 | private String ImageUriAcessToken; 53 | 54 | private FirebaseFirestore firebaseFirestore; 55 | 56 | ProgressBar mprogressbarofsetprofile; 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | @Override 68 | protected void onCreate(Bundle savedInstanceState) { 69 | super.onCreate(savedInstanceState); 70 | setContentView(R.layout.activity_set_profile); 71 | 72 | firebaseAuth=FirebaseAuth.getInstance(); 73 | firebaseStorage=FirebaseStorage.getInstance(); 74 | storageReference=firebaseStorage.getReference(); 75 | firebaseFirestore=FirebaseFirestore.getInstance(); 76 | 77 | 78 | mgetusername=findViewById(R.id.getusername); 79 | mgetuserimage=findViewById(R.id.getuserimage); 80 | mgetuserimageinimageview=findViewById(R.id.getuserimageinimageview); 81 | msaveprofile=findViewById(R.id.saveProfile); 82 | mprogressbarofsetprofile=findViewById(R.id.progressbarofsetProfile); 83 | 84 | 85 | mgetuserimage.setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View view) { 88 | Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI); 89 | startActivityForResult(intent,PICK_IMAGE); 90 | } 91 | }); 92 | 93 | 94 | msaveprofile.setOnClickListener(new View.OnClickListener() { 95 | @Override 96 | public void onClick(View view) { 97 | name=mgetusername.getText().toString(); 98 | if(name.isEmpty()) 99 | { 100 | Toast.makeText(getApplicationContext(),"Name is Empty",Toast.LENGTH_SHORT).show(); 101 | } 102 | else if(imagepath==null) 103 | { 104 | Toast.makeText(getApplicationContext(),"Image is Empty",Toast.LENGTH_SHORT).show(); 105 | } 106 | else 107 | { 108 | 109 | mprogressbarofsetprofile.setVisibility(View.VISIBLE); 110 | sendDataForNewUser(); 111 | mprogressbarofsetprofile.setVisibility(View.INVISIBLE); 112 | Intent intent=new Intent(setProfile.this,chatActivity.class); 113 | startActivity(intent); 114 | finish(); 115 | 116 | 117 | } 118 | } 119 | }); 120 | 121 | 122 | 123 | 124 | 125 | 126 | } 127 | 128 | 129 | private void sendDataForNewUser() 130 | { 131 | 132 | sendDataToRealTimeDatabase(); 133 | 134 | } 135 | 136 | private void sendDataToRealTimeDatabase() 137 | { 138 | 139 | 140 | name=mgetusername.getText().toString().trim(); 141 | FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance(); 142 | DatabaseReference databaseReference=firebaseDatabase.getReference(firebaseAuth.getUid()); 143 | 144 | userprofile muserprofile=new userprofile(name,firebaseAuth.getUid()); 145 | databaseReference.setValue(muserprofile); 146 | Toast.makeText(getApplicationContext(),"User Profile Added Sucessfully",Toast.LENGTH_SHORT).show(); 147 | sendImagetoStorage(); 148 | 149 | 150 | 151 | 152 | } 153 | 154 | private void sendImagetoStorage() 155 | { 156 | 157 | StorageReference imageref=storageReference.child("Images").child(firebaseAuth.getUid()).child("Profile Pic"); 158 | 159 | //Image compresesion 160 | 161 | Bitmap bitmap=null; 162 | try { 163 | bitmap= MediaStore.Images.Media.getBitmap(getContentResolver(),imagepath); 164 | } 165 | catch (IOException e) 166 | { 167 | e.printStackTrace(); 168 | } 169 | 170 | ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(); 171 | bitmap.compress(Bitmap.CompressFormat.JPEG,25,byteArrayOutputStream); 172 | byte[] data=byteArrayOutputStream.toByteArray(); 173 | 174 | ///putting image to storage 175 | 176 | UploadTask uploadTask=imageref.putBytes(data); 177 | 178 | uploadTask.addOnSuccessListener(new OnSuccessListener() { 179 | @Override 180 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 181 | 182 | imageref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { 183 | @Override 184 | public void onSuccess(Uri uri) { 185 | ImageUriAcessToken=uri.toString(); 186 | Toast.makeText(getApplicationContext(),"URI get sucess",Toast.LENGTH_SHORT).show(); 187 | sendDataTocloudFirestore(); 188 | } 189 | }).addOnFailureListener(new OnFailureListener() { 190 | @Override 191 | public void onFailure(@NonNull Exception e) { 192 | Toast.makeText(getApplicationContext(),"URI get Failed",Toast.LENGTH_SHORT).show(); 193 | } 194 | 195 | 196 | }); 197 | Toast.makeText(getApplicationContext(),"Image is uploaded",Toast.LENGTH_SHORT).show(); 198 | 199 | } 200 | }).addOnFailureListener(new OnFailureListener() { 201 | @Override 202 | public void onFailure(@NonNull Exception e) { 203 | Toast.makeText(getApplicationContext(),"Image Not UPdloaded",Toast.LENGTH_SHORT).show(); 204 | } 205 | }); 206 | 207 | 208 | 209 | 210 | 211 | } 212 | 213 | private void sendDataTocloudFirestore() { 214 | 215 | 216 | DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid()); 217 | Map userdata=new HashMap<>(); 218 | userdata.put("name",name); 219 | userdata.put("image",ImageUriAcessToken); 220 | userdata.put("uid",firebaseAuth.getUid()); 221 | userdata.put("status","Online"); 222 | 223 | documentReference.set(userdata).addOnSuccessListener(new OnSuccessListener() { 224 | @Override 225 | public void onSuccess(Void aVoid) { 226 | Toast.makeText(getApplicationContext(),"Data on Cloud Firestore send success",Toast.LENGTH_SHORT).show(); 227 | 228 | } 229 | }); 230 | 231 | 232 | 233 | } 234 | 235 | 236 | @Override 237 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 238 | 239 | if(requestCode==PICK_IMAGE && resultCode==RESULT_OK) 240 | { 241 | imagepath=data.getData(); 242 | mgetuserimageinimageview.setImageURI(imagepath); 243 | } 244 | 245 | 246 | 247 | 248 | super.onActivityResult(requestCode, resultCode, data); 249 | } 250 | 251 | 252 | 253 | 254 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/specificchat.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.cardview.widget.CardView; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | 9 | import android.content.Intent; 10 | import android.content.pm.PackageInfo; 11 | import android.os.Bundle; 12 | import android.view.View; 13 | import android.widget.EditText; 14 | import android.widget.ImageButton; 15 | import android.widget.ImageView; 16 | import android.widget.TextView; 17 | import android.widget.Toast; 18 | 19 | import com.google.android.gms.tasks.OnCompleteListener; 20 | import com.google.android.gms.tasks.Task; 21 | import com.google.firebase.auth.FirebaseAuth; 22 | import com.google.firebase.database.DataSnapshot; 23 | import com.google.firebase.database.DatabaseError; 24 | import com.google.firebase.database.DatabaseReference; 25 | import com.google.firebase.database.FirebaseDatabase; 26 | import com.google.firebase.database.ValueEventListener; 27 | import com.squareup.picasso.Picasso; 28 | 29 | import java.text.SimpleDateFormat; 30 | import java.util.ArrayList; 31 | import java.util.Calendar; 32 | import java.util.Date; 33 | 34 | public class specificchat extends AppCompatActivity { 35 | 36 | EditText mgetmessage; 37 | ImageButton msendmessagebutton; 38 | 39 | CardView msendmessagecardview; 40 | androidx.appcompat.widget.Toolbar mtoolbarofspecificchat; 41 | ImageView mimageviewofspecificuser; 42 | TextView mnameofspecificuser; 43 | 44 | private String enteredmessage; 45 | Intent intent; 46 | String mrecievername,sendername,mrecieveruid,msenderuid; 47 | private FirebaseAuth firebaseAuth; 48 | FirebaseDatabase firebaseDatabase; 49 | String senderroom,recieverroom; 50 | 51 | ImageButton mbackbuttonofspecificchat; 52 | 53 | RecyclerView mmessagerecyclerview; 54 | 55 | String currenttime; 56 | Calendar calendar; 57 | SimpleDateFormat simpleDateFormat; 58 | 59 | MessagesAdapter messagesAdapter; 60 | ArrayList messagesArrayList; 61 | 62 | 63 | 64 | @Override 65 | protected void onCreate(Bundle savedInstanceState) { 66 | super.onCreate(savedInstanceState); 67 | setContentView(R.layout.activity_specificchat); 68 | 69 | mgetmessage=findViewById(R.id.getmessage); 70 | msendmessagecardview=findViewById(R.id.carviewofsendmessage); 71 | msendmessagebutton=findViewById(R.id.imageviewsendmessage); 72 | mtoolbarofspecificchat=findViewById(R.id.toolbarofspecificchat); 73 | mnameofspecificuser=findViewById(R.id.Nameofspecificuser); 74 | mimageviewofspecificuser=findViewById(R.id.specificuserimageinimageview); 75 | mbackbuttonofspecificchat=findViewById(R.id.backbuttonofspecificchat); 76 | 77 | messagesArrayList=new ArrayList<>(); 78 | mmessagerecyclerview=findViewById(R.id.recyclerviewofspecific); 79 | 80 | LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this); 81 | linearLayoutManager.setStackFromEnd(true); 82 | mmessagerecyclerview.setLayoutManager(linearLayoutManager); 83 | messagesAdapter=new MessagesAdapter(specificchat.this,messagesArrayList); 84 | mmessagerecyclerview.setAdapter(messagesAdapter); 85 | 86 | 87 | 88 | 89 | intent=getIntent(); 90 | 91 | setSupportActionBar(mtoolbarofspecificchat); 92 | mtoolbarofspecificchat.setOnClickListener(new View.OnClickListener() { 93 | @Override 94 | public void onClick(View view) { 95 | Toast.makeText(getApplicationContext(),"Toolbar is Clicked",Toast.LENGTH_SHORT).show(); 96 | 97 | 98 | } 99 | }); 100 | 101 | firebaseAuth=FirebaseAuth.getInstance(); 102 | firebaseDatabase=FirebaseDatabase.getInstance(); 103 | calendar=Calendar.getInstance(); 104 | simpleDateFormat=new SimpleDateFormat("hh:mm a"); 105 | 106 | 107 | msenderuid=firebaseAuth.getUid(); 108 | mrecieveruid=getIntent().getStringExtra("receiveruid"); 109 | mrecievername=getIntent().getStringExtra("name"); 110 | 111 | 112 | 113 | senderroom=msenderuid+mrecieveruid; 114 | recieverroom=mrecieveruid+msenderuid; 115 | 116 | 117 | 118 | DatabaseReference databaseReference=firebaseDatabase.getReference().child("chats").child(senderroom).child("messages"); 119 | messagesAdapter=new MessagesAdapter(specificchat.this,messagesArrayList); 120 | databaseReference.addValueEventListener(new ValueEventListener() { 121 | @Override 122 | public void onDataChange(@NonNull DataSnapshot snapshot) { 123 | messagesArrayList.clear(); 124 | for(DataSnapshot snapshot1:snapshot.getChildren()) 125 | { 126 | Messages messages=snapshot1.getValue(Messages.class); 127 | messagesArrayList.add(messages); 128 | } 129 | messagesAdapter.notifyDataSetChanged(); 130 | } 131 | 132 | @Override 133 | public void onCancelled(@NonNull DatabaseError error) { 134 | 135 | } 136 | }); 137 | 138 | 139 | 140 | 141 | mbackbuttonofspecificchat.setOnClickListener(new View.OnClickListener() { 142 | @Override 143 | public void onClick(View view) { 144 | finish(); 145 | } 146 | }); 147 | 148 | 149 | mnameofspecificuser.setText(mrecievername); 150 | String uri=intent.getStringExtra("imageuri"); 151 | if(uri.isEmpty()) 152 | { 153 | Toast.makeText(getApplicationContext(),"null is recieved",Toast.LENGTH_SHORT).show(); 154 | } 155 | else 156 | { 157 | Picasso.get().load(uri).into(mimageviewofspecificuser); 158 | } 159 | 160 | 161 | msendmessagebutton.setOnClickListener(new View.OnClickListener() { 162 | @Override 163 | public void onClick(View view) { 164 | 165 | enteredmessage=mgetmessage.getText().toString(); 166 | if(enteredmessage.isEmpty()) 167 | { 168 | Toast.makeText(getApplicationContext(),"Enter message first",Toast.LENGTH_SHORT).show(); 169 | } 170 | 171 | else 172 | 173 | { 174 | Date date=new Date(); 175 | currenttime=simpleDateFormat.format(calendar.getTime()); 176 | Messages messages=new Messages(enteredmessage,firebaseAuth.getUid(),date.getTime(),currenttime); 177 | firebaseDatabase=FirebaseDatabase.getInstance(); 178 | firebaseDatabase.getReference().child("chats") 179 | .child(senderroom) 180 | .child("messages") 181 | .push().setValue(messages).addOnCompleteListener(new OnCompleteListener() { 182 | @Override 183 | public void onComplete(@NonNull Task task) { 184 | firebaseDatabase.getReference() 185 | .child("chats") 186 | .child(recieverroom) 187 | .child("messages") 188 | .push() 189 | .setValue(messages).addOnCompleteListener(new OnCompleteListener() { 190 | @Override 191 | public void onComplete(@NonNull Task task) { 192 | 193 | } 194 | }); 195 | } 196 | }); 197 | 198 | mgetmessage.setText(null); 199 | 200 | 201 | 202 | 203 | } 204 | 205 | 206 | 207 | 208 | } 209 | }); 210 | 211 | 212 | 213 | 214 | } 215 | 216 | 217 | @Override 218 | public void onStart() { 219 | super.onStart(); 220 | messagesAdapter.notifyDataSetChanged(); 221 | } 222 | 223 | @Override 224 | public void onStop() { 225 | super.onStop(); 226 | if(messagesAdapter!=null) 227 | { 228 | messagesAdapter.notifyDataSetChanged(); 229 | } 230 | } 231 | 232 | 233 | 234 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/splashscreen.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.view.WindowManager; 9 | 10 | public class splashscreen extends AppCompatActivity { 11 | 12 | private static int SPLASH_TIMER=3000; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_splashscreen); 18 | 19 | 20 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 21 | 22 | new Handler().postDelayed(new Runnable() { 23 | @Override 24 | public void run() { 25 | 26 | Intent intent=new Intent(splashscreen.this,MainActivity.class); 27 | startActivity(intent); 28 | finish(); 29 | 30 | 31 | } 32 | },SPLASH_TIMER); 33 | 34 | 35 | 36 | 37 | 38 | } 39 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/statusFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.fragment.app.Fragment; 11 | 12 | public class statusFragment extends Fragment { 13 | 14 | @Nullable 15 | @Override 16 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 17 | return inflater.inflate(R.layout.statusfragment,null); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mychatapptutorial/userprofile.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | public class userprofile { 4 | 5 | 6 | public String username,userUID; 7 | 8 | public userprofile() { 9 | } 10 | 11 | public userprofile(String username, String userUID) { 12 | this.username = username; 13 | this.userUID = userUID; 14 | } 15 | 16 | public String getUsername() { 17 | return username; 18 | } 19 | 20 | public void setUsername(String username) { 21 | this.username = username; 22 | } 23 | 24 | public String getUserUID() { 25 | return userUID; 26 | } 27 | 28 | public void setUserUID(String userUID) { 29 | this.userUID = userUID; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/defaultprofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/drawable/defaultprofile.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_arrow_back_24.xml: -------------------------------------------------------------------------------- 1 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_arrow_forward_24.xml: -------------------------------------------------------------------------------- 1 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_more_vert_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_person_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/messagebackgroun.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/mychatapplogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/drawable/mychatapplogo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/recieverchatdrawble.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/senderchatdrawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/font/playlist.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/font/playlist.ttf -------------------------------------------------------------------------------- /app/src/main/res/font/raleway.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/font/raleway.ttf -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_chat.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 19 | 20 | 24 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 55 | 60 | 61 | 62 | 63 | 68 | 69 | 70 | 71 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 18 | 19 | 20 | 21 | 22 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 62 | 63 | 64 | 65 | 66 | 78 | 79 | 80 | 81 | 82 | 83 | 96 | 97 | 98 | 99 | 100 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_otp_authentication.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 18 | 19 | 20 | 21 | 22 | 34 | 35 | 36 | 37 | 38 | 39 | 51 | 52 | 53 | 54 | 55 | 65 | 66 | 67 | 68 | 80 | 81 | 82 | 83 | 84 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 24 | 25 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 70 | 71 | 72 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 96 | 97 | 98 | 111 | 112 | 113 | 114 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_set_profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 21 | 22 | 23 | 24 | 25 | 26 | 35 | 36 | 37 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 61 | 62 | 63 | 64 | 76 | 77 | 78 | 79 | 80 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_specificchat.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 18 | 19 | 23 | 24 | 32 | 33 | 34 | 35 | 36 | 44 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | 110 | 111 | 112 | 122 | 123 | 124 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_splashscreen.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 29 | 30 | 31 | 32 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_update_profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 17 | 18 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | 36 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 68 | 69 | 70 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 95 | 96 | 97 | 98 | 99 | 109 | 110 | 111 | 112 | 113 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /app/src/main/res/layout/callfragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/chatfragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/chatviewlayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 30 | 31 | 32 | 33 | 34 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 62 | 63 | 64 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recieverchatlayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 26 | 27 | 28 | 29 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/senderchatlayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 25 | 26 | 27 | 28 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/statusfragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #055047 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MyChatAppTutorial 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/mychatapptutorial/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mychatapptutorial; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath "com.android.tools.build:gradle:4.1.1" 9 | classpath 'com.google.gms:google-services:4.3.5' 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 | google() 19 | jcenter() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brijesh-kumar-sharma/chatAppInAndroidStudio/81188eb146558acefcb3a8fbf27ebdcb480e8e36/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu May 13 14:40:03 PDT 2021 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-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "MyChatAppTutorial" --------------------------------------------------------------------------------