From 689a63493941e39fbdeda5035daca72ade05d1fd Mon Sep 17 00:00:00 2001 From: debarghya472 Date: Sat, 13 Jun 2020 23:46:08 +0530 Subject: [PATCH 1/5] done --- app/build.gradle | 18 ++++++++++-------- build.gradle | 12 +++++++++++- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 113f182b5..d05312988 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,13 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' - compile 'com.android.support:design:24.2.0' - compile 'com.android.support:appcompat-v7:24.2.0' + implementation 'com.android.support:design:24.2.0' + implementation 'com.android.support:appcompat-v7:24.2.0' + implementation 'com.google.firebase:firebase-analytics:17.2.2' // Displaying images - compile 'com.github.bumptech.glide:glide:3.6.1' + implementation 'com.github.bumptech.glide:glide:3.6.1' } \ No newline at end of file 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/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 From 3fe930d29a02ea23f47cb0ca61d866ab21e0b29c Mon Sep 17 00:00:00 2001 From: debarghya472 Date: Sun, 14 Jun 2020 15:10:25 +0530 Subject: [PATCH 2/5] basic --- app/build.gradle | 10 +- app/src/main/AndroidManifest.xml | 1 + .../udacity/friendlychat/MainActivity.java | 93 ++++++++++++++++++- gradle.properties | 4 +- 4 files changed, 103 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d05312988..3e8bc0635 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,12 +34,16 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.google.firebase:firebase-database:19.2.1' testImplementation 'junit:junit:4.12' - implementation 'com.android.support:design:24.2.0' - implementation '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' + // Displaying images implementation 'com.github.bumptech.glide:glide:3.6.1' -} \ No newline at end of file +} 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); + + } + } + }; } @Override @@ -123,4 +202,16 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + + @Override + protected void onPause() { + super.onPause(); + mfirebaseAuth.removeAuthStateListener(mauthStateListener); + } + + @Override + protected void onResume() { + super.onResume(); + mfirebaseAuth.addAuthStateListener(mauthStateListener); + } } 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 From cf9255f10ea4c3e976dc96f784613f1f40366d9d Mon Sep 17 00:00:00 2001 From: debarghya472 Date: Sun, 14 Jun 2020 17:01:19 +0530 Subject: [PATCH 3/5] sdsd --- .../udacity/friendlychat/MainActivity.java | 105 +++++++++++++----- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java b/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java index aa072cff4..021144977 100644 --- a/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java +++ b/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java @@ -15,6 +15,7 @@ */ package com.google.firebase.udacity.friendlychat; +import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; @@ -35,6 +36,7 @@ import android.widget.Toast; import com.firebase.ui.auth.AuthUI; +import com.google.android.gms.auth.api.Auth; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.database.ChildEventListener; @@ -138,42 +140,16 @@ public void onClick(View view) { mMessageEditText.setText(""); } }); - 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); mauthStateListener=new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser(); if(user!=null){ Toast.makeText(getApplicationContext(),"youre signed in",Toast.LENGTH_SHORT).show(); + onSignedInInitialized(user.getDisplayName()); }else{ + onSignedOutCleanUp(); List providers = Arrays.asList( new AuthUI.IdpConfig.EmailBuilder().build(), new AuthUI.IdpConfig.GoogleBuilder().build()); @@ -198,15 +174,37 @@ 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(); + } } @Override @@ -214,4 +212,53 @@ 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; + } + + } } From e0cf21ffda21413b3c46dcf24be07d8e6b62f8e3 Mon Sep 17 00:00:00 2001 From: debarghya472 Date: Sun, 21 Jun 2020 23:42:09 +0530 Subject: [PATCH 4/5] gj --- app/build.gradle | 2 + .../udacity/friendlychat/MainActivity.java | 49 +++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3e8bc0635..56c91cbcc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,6 +35,7 @@ android { dependencies { 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' implementation 'com.google.android.material:material:1.0.0' @@ -43,6 +44,7 @@ dependencies { 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 implementation 'com.github.bumptech.glide:glide:3.6.1' diff --git a/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java b/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java index 021144977..5c1bb566a 100644 --- a/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java +++ b/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java @@ -16,6 +16,7 @@ package com.google.firebase.udacity.friendlychat; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import androidx.annotation.NonNull; @@ -37,6 +38,7 @@ import com.firebase.ui.auth.AuthUI; import com.google.android.gms.auth.api.Auth; +import com.google.android.gms.tasks.OnSuccessListener; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.database.ChildEventListener; @@ -44,6 +46,9 @@ import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; +import com.google.firebase.storage.UploadTask; import java.util.ArrayList; import java.util.Arrays; @@ -53,6 +58,7 @@ public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_SIGN_IN = 1; + private static final int RC_PHOTO_PICKER = 2; public static final String ANONYMOUS = "anonymous"; public static final int DEFAULT_MSG_LENGTH_LIMIT = 1000; @@ -71,6 +77,8 @@ public class MainActivity extends AppCompatActivity { private ChildEventListener mchildEventListener; private FirebaseAuth mfirebaseAuth; private FirebaseAuth.AuthStateListener mauthStateListener; + private FirebaseStorage mfirebaseStorage; + private StorageReference mPhotosstorageReference; @Override protected void onCreate(Bundle savedInstanceState) { @@ -81,7 +89,10 @@ protected void onCreate(Bundle savedInstanceState) { mfirebaseDatabase=FirebaseDatabase.getInstance(); mfirebaseAuth=FirebaseAuth.getInstance(); + mfirebaseStorage=FirebaseStorage.getInstance(); + mMessagedatabaseReference=mfirebaseDatabase.getReference().child("messages"); + mPhotosstorageReference=mfirebaseStorage.getReference().child("chat_photos"); // mMessagedatabaseReference.setValue("hello world"); // Initialize references to views @@ -165,6 +176,15 @@ public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { } } }; + 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 @@ -198,15 +218,34 @@ protected void onPause() { @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(); + 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(); From d8dcfcba722a7d43ccbe51a526fd796c3093d4e5 Mon Sep 17 00:00:00 2001 From: debarghya472 Date: Mon, 22 Jun 2020 17:22:53 +0530 Subject: [PATCH 5/5] setup actions workflow --- .github/workflows/android_build.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/android_build.yml 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