diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml new file mode 100644 index 000000000..979432bb9 --- /dev/null +++ b/.github/workflows/android_build.yml @@ -0,0 +1,23 @@ +name: Android build + +on: pull_request + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v1 + + - name: setup jdk + uses: actions/setup-jdk@v1 + with: + java-version: 1.8 + + - name: Run Tests + run: ./gradlew test + + - name: Build project + run: ./gradlew assemble \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 113f182b5..56c91cbcc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'com.google.gms.google-services' repositories { mavenLocal() @@ -8,13 +9,13 @@ repositories { } android { - compileSdkVersion 24 - buildToolsVersion "24.0.1" + compileSdkVersion 28 + buildToolsVersion "28.0.3" defaultConfig { applicationId "com.google.firebase.udacity.friendlychat" minSdkVersion 16 - targetSdkVersion 24 + targetSdkVersion 28 versionCode 1 versionName "1.0" } @@ -32,12 +33,19 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.google.firebase:firebase-database:19.2.1' + implementation 'com.google.firebase:firebase-messaging:20.2.0' + testImplementation 'junit:junit:4.12' - compile 'com.android.support:design:24.2.0' - compile 'com.android.support:appcompat-v7:24.2.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'com.google.firebase:firebase-analytics:17.2.2' + + implementation 'com.google.firebase:firebase-auth:19.3.1' + implementation 'com.firebaseui:firebase-ui-auth:6.2.0' + implementation 'com.google.firebase:firebase-storage:19.1.1' // Displaying images - compile 'com.github.bumptech.glide:glide:3.6.1' -} \ No newline at end of file + implementation 'com.github.bumptech.glide:glide:3.6.1' +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bcd0e213c..925821ed0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + providers = Arrays.asList( + new AuthUI.IdpConfig.EmailBuilder().build(), + new AuthUI.IdpConfig.GoogleBuilder().build()); + + startActivityForResult( + AuthUI.getInstance() + .createSignInIntentBuilder() + .setAvailableProviders(providers) + .setIsSmartLockEnabled(false) + .build(), + RC_SIGN_IN); + + } + } + }; + mPhotoPickerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); +// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); + startActivityForResult(intent, RC_PHOTO_PICKER); + } + }); } @Override @@ -119,8 +194,110 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } + @Override public boolean onOptionsItemSelected(MenuItem item) { - return super.onOptionsItemSelected(item); + switch (item.getItemId()) { + case R.id.sign_out_menu: + AuthUI.getInstance().signOut(this); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + protected void onPause() { + super.onPause(); + if(mauthStateListener!=null) + mfirebaseAuth.removeAuthStateListener(mauthStateListener); + detachDatabaselistener(); + mMessageAdapter.clear(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(requestCode==RC_SIGN_IN) { + if (resultCode == RESULT_OK) { + Toast.makeText(getApplicationContext(), "Signed IN", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getApplicationContext(), "signed out", Toast.LENGTH_SHORT).show(); + finish(); + } + } + if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) { + Uri selectedImageUri = data.getData(); + final StorageReference photoRef = mPhotosstorageReference.child("image"+selectedImageUri.getLastPathSegment()); + photoRef.putFile(selectedImageUri).addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + Toast.makeText(getApplicationContext(),"uploaded",Toast.LENGTH_SHORT).show(); + photoRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) { + FriendlyMessage friendlyMessage=new FriendlyMessage(null,mUsername, uri.toString()); + mMessagedatabaseReference.push().setValue(friendlyMessage); + } + }); + } + }); + } + } + + + @Override + protected void onResume() { + super.onResume(); + mfirebaseAuth.addAuthStateListener(mauthStateListener); + } + private void onSignedInInitialized(String username){ + mUsername=username; + attachdatabaselistener(); + } + private void onSignedOutCleanUp(){ + mUsername=ANONYMOUS; + mMessageAdapter.clear(); + detachDatabaselistener(); + } + private void attachdatabaselistener(){ + if(mchildEventListener==null) { + mchildEventListener = new ChildEventListener() { + @Override + public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) { + FriendlyMessage friendlyMessage = dataSnapshot.getValue(FriendlyMessage.class); + mMessageAdapter.add(friendlyMessage); + + } + + @Override + public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) { + + } + + @Override + public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) { + + } + + @Override + public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) { + + } + + @Override + public void onCancelled(@NonNull DatabaseError databaseError) { + + } + }; + mMessagedatabaseReference.addChildEventListener(mchildEventListener); + } + } + private void detachDatabaselistener(){ + if(mchildEventListener!=null) { + mMessagedatabaseReference.removeEventListener(mchildEventListener); + mchildEventListener = null; + } + } } diff --git a/build.gradle b/build.gradle index 67fa30cbc..176856177 100644 --- a/build.gradle +++ b/build.gradle @@ -4,9 +4,15 @@ buildscript { repositories { jcenter() mavenLocal() + maven { + url 'https://maven.google.com/' + name 'Google' + } + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.google.gms:google-services:4.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -17,6 +23,10 @@ allprojects { repositories { jcenter() mavenLocal() + maven { + url 'https://maven.google.com/' + name 'Google' + } } } diff --git a/gradle.properties b/gradle.properties index 1d3591c8a..915f0e66f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,6 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +android.enableJetifier=true +android.useAndroidX=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ce88022b7..7a43eb447 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Aug 16 17:43:49 PDT 2016 +#Sat Jun 13 23:33:06 IST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip