Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci #82

Open
wants to merge 5 commits into
base: 1.00-starting-point
Choose a base branch
from
Open

Ci #82

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 17 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

repositories {
mavenLocal()
Expand All @@ -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"
}
Expand All @@ -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'
}
implementation 'com.github.bumptech.glide:glide:3.6.1'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.udacity.friendlychat">
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
*/
package com.google.firebase.udacity.friendlychat;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
Expand All @@ -29,13 +34,31 @@
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

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;
import com.google.firebase.database.DataSnapshot;
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;
import java.util.List;

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;
Expand All @@ -49,13 +72,29 @@ public class MainActivity extends AppCompatActivity {

private String mUsername;

private FirebaseDatabase mfirebaseDatabase;
private DatabaseReference mMessagedatabaseReference;
private ChildEventListener mchildEventListener;
private FirebaseAuth mfirebaseAuth;
private FirebaseAuth.AuthStateListener mauthStateListener;
private FirebaseStorage mfirebaseStorage;
private StorageReference mPhotosstorageReference;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mUsername = ANONYMOUS;

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
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mMessageListView = (ListView) findViewById(R.id.messageListView);
Expand Down Expand Up @@ -106,10 +145,46 @@ public void afterTextChanged(Editable editable) {
public void onClick(View view) {
// TODO: Send messages on click

FriendlyMessage friendlyMessage=new FriendlyMessage(mMessageEditText.getText().toString(),mUsername,null);
mMessagedatabaseReference.push().setValue(friendlyMessage);
// Clear input box
mMessageEditText.setText("");
}
});

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<AuthUI.IdpConfig> 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
Expand All @@ -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<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(),"uploaded",Toast.LENGTH_SHORT).show();
photoRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@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;
}

}
}
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +23,10 @@ allprojects {
repositories {
jcenter()
mavenLocal()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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