This repository was archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 584
Integration Firebase Functions #108
Closed
deekshithreddyr
wants to merge
27
commits into
GoogleCloudPlatform:master
from
deekshithreddyr:master
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
aa516b2
Initial commit
deekshithreddyr ad096da
Addressed review comments
deekshithreddyr 2a0b27f
Added README File
deekshithreddyr bbd9f4e
Update README.md
deekshithreddyr a4f9ba8
Update README.md
deekshithreddyr b33d644
Update README.md
deekshithreddyr 6ce8859
refactor: refactoring the code
deekshithreddyr 0f862d4
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr 2e38050
Add stopwatchagent.zip file
deekshithreddyr c3c2b78
Update README.md
deekshithreddyr bba436b
Update README.md
deekshithreddyr b168253
Changes has per Github comments
deekshithreddyr e7d5487
Combine the three requests into one. Dropdown instead of multi-selec…
deekshithreddyr 9dcf0d1
Addressed review comments
deekshithreddyr 9ddd430
Using the Audio returned from Dialogflow.
deekshithreddyr 1c2b79f
Addressed review comments
deekshithreddyr 462db73
Separated the Authentication code from AppController.java to AuthUtil…
deekshithreddyr c8371eb
Code Refinement
deekshithreddyr 20b798a
Update README.md
deekshithreddyr d31ecb6
Update README.md
deekshithreddyr cafff50
Addressed review comments
deekshithreddyr 6b8e4bd
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr 4dd38b9
function to convert the time from UTC to local TimeZone added
deekshithreddyr 73edd3f
Code readability update
deekshithreddyr 12e2d39
Update README.md
deekshithreddyr 26599e8
Speech2speech Initial commit
deekshithreddyr 32020e9
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
samples-refs_heads_mobile-auth-mobile-mobile_proxy_server-android_app/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| *.iml | ||
| .gradle | ||
| /local.properties | ||
| /.idea/workspace.xml | ||
| /.idea/libraries | ||
| .DS_Store | ||
| /build | ||
| /captures | ||
| .externalNativeBuild | ||
1 change: 1 addition & 0 deletions
1
samples-refs_heads_mobile-auth-mobile-mobile_proxy_server-android_app/app/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
61 changes: 61 additions & 0 deletions
61
samples-refs_heads_mobile-auth-mobile-mobile_proxy_server-android_app/app/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| apply plugin: 'com.android.application' | ||
|
|
||
| android { | ||
| compileSdkVersion 28 | ||
| defaultConfig { | ||
| applicationId "com.example.mlapitest" | ||
|
nnegrey marked this conversation as resolved.
Outdated
|
||
| minSdkVersion 26 | ||
| targetSdkVersion 28 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| multiDexEnabled true | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled true | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
| packagingOptions { | ||
| exclude 'META-INF/DEPENDENCIES' | ||
| exclude 'META-INF/LICENSE' | ||
| exclude 'META-INF/LICENSE.txt' | ||
| exclude 'META-INF/license.txt' | ||
| exclude 'META-INF/NOTICE' | ||
| exclude 'META-INF/NOTICE.txt' | ||
| exclude 'META-INF/notice.txt' | ||
| exclude 'META-INF/ASL2.0' | ||
| exclude 'META-INF/INDEX.LIST' | ||
| exclude 'META-INF/io.netty.versions.properties' | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
|
|
||
| configurations.all { | ||
| resolutionStrategy.force 'com.android.support:support-annotations:25.3.0' | ||
| } | ||
| implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
| implementation 'androidx.appcompat:appcompat:1.0.0' | ||
| implementation 'com.google.android.material:material:1.0.0' | ||
| implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
| testImplementation 'junit:junit:4.12' | ||
| androidTestImplementation 'androidx.test:runner:1.1.0' | ||
| androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' | ||
|
|
||
| implementation 'com.google.firebase:firebase-core:17.0.0' | ||
| implementation 'com.google.firebase:firebase-auth:18.0.0' | ||
| implementation 'com.firebaseui:firebase-ui-auth:4.1.0' | ||
| implementation 'com.google.firebase:firebase-messaging:19.0.1' | ||
| implementation 'com.google.firebase:firebase-functions:18.0.0' | ||
| implementation 'com.android.volley:volley:1.1.1' | ||
| implementation 'com.google.cloud:google-cloud-dialogflow:0.96.0-alpha' | ||
| implementation group: 'io.grpc', name: 'grpc-okhttp', version: '1.21.0' | ||
| implementation group: 'io.grpc', name: 'grpc-netty', version: '1.21.0' | ||
|
|
||
| implementation "com.google.firebase:firebase-database:18.0.0" | ||
|
nnegrey marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
|
|
||
| apply plugin: 'com.google.gms.google-services' | ||
21 changes: 21 additions & 0 deletions
21
samples-refs_heads_mobile-auth-mobile-mobile_proxy_server-android_app/app/proguard-rules.pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # You can control the set of applied configuration files using the | ||
| # proguardFiles setting in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...r-android_app/app/src/androidTest/java/com/example/mlapitest/ExampleInstrumentedTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.example.mlapitest; | ||
|
|
||
| import android.content.Context; | ||
| import androidx.test.InstrumentationRegistry; | ||
| import androidx.test.runner.AndroidJUnit4; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| /** | ||
| * Instrumented test, which will execute on an Android device. | ||
| * | ||
| * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
| */ | ||
| @RunWith(AndroidJUnit4.class) | ||
| public class ExampleInstrumentedTest { | ||
| @Test | ||
| public void useAppContext() throws Exception { | ||
| // Context of the app under test. | ||
| Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
|
||
| assertEquals("com.example.mlapitest", appContext.getPackageName()); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...heads_mobile-auth-mobile-mobile_proxy_server-android_app/app/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| package="com.example.mlapitest"> | ||
|
|
||
| <uses-permission android:name="android.permission.RECORD_AUDIO" /> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
|
|
||
| <application | ||
| android:name=".AppController" | ||
| android:allowBackup="true" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:roundIcon="@mipmap/ic_launcher_round" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/AppTheme"> | ||
| <activity android:name=".ui.ChatActivity" /> | ||
| <activity android:name=".ui.WelcomeActivity"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
|
|
||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity android:name=".ui.MainActivity" /> | ||
| <service | ||
| android:name=".service.MyFirebaseMessagingService" | ||
|
nnegrey marked this conversation as resolved.
Outdated
|
||
| android:exported="false"> | ||
| <intent-filter> | ||
| <action android:name="com.google.firebase.MESSAGING_EVENT" /> | ||
| </intent-filter> | ||
| </service> | ||
| </application> | ||
|
|
||
| </manifest> | ||
Binary file added
BIN
+30.3 KB
...ds_mobile-auth-mobile-mobile_proxy_server-android_app/app/src/main/assets/book_a_room.wav
Binary file not shown.
54 changes: 54 additions & 0 deletions
54
...obile_proxy_server-android_app/app/src/main/java/com/example/mlapitest/AppController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.example.mlapitest; | ||
|
|
||
| import android.app.Application; | ||
|
|
||
| import com.google.firebase.functions.FirebaseFunctions; | ||
|
|
||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class AppController extends Application { | ||
|
|
||
| public static final String TOKEN_RECEIVED = "TOKEN_RECEIVED"; | ||
| public static final String PROJECT_ID = "PROJECT_ID"; | ||
| public static final String SESSION_ID = "sessionId"; | ||
| public static String firebaseInstanceId = ""; | ||
|
|
||
| public static String token = ""; | ||
| public static Date exipryTime; | ||
|
|
||
| /** | ||
| * function to call the firebase function which will send the fcm message containing token and expiry time to the device | ||
| */ | ||
| public static void callFirebaseFunction() { | ||
| Map<String, Object> data = new HashMap<>(); | ||
| data.put("deviceId", AppController.firebaseInstanceId); | ||
| FirebaseFunctions firebaseFunctions; | ||
| firebaseFunctions = FirebaseFunctions.getInstance(); | ||
|
|
||
| firebaseFunctions | ||
| .getHttpsCallable("getOAuthToken") | ||
| .call(data); | ||
| } | ||
|
|
||
| /** | ||
| * function to convert string to date | ||
| * @param dt : string date | ||
| * @return : converted date object | ||
| */ | ||
| public static Date getDateFromStrinng(String dt) { | ||
| SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
| try { | ||
| Date date = format.parse(dt); | ||
| return date; | ||
| } catch (ParseException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| } |
69 changes: 69 additions & 0 deletions
69
...-android_app/app/src/main/java/com/example/mlapitest/adapter/ChatRecyclerViewAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package com.example.mlapitest.adapter; | ||
|
|
||
| import android.content.Context; | ||
| import androidx.recyclerview.widget.RecyclerView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.RelativeLayout; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.example.mlapitest.R; | ||
| import com.example.mlapitest.model.ChatMsgModel; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerViewAdapter.MyViewHolder> { | ||
|
|
||
| private ArrayList<ChatMsgModel> chatMsgModels; | ||
| private Context context; | ||
|
|
||
| public ChatRecyclerViewAdapter(Context context, ArrayList<ChatMsgModel> chatMsgModels) { | ||
| this.context = context; | ||
| this.chatMsgModels = chatMsgModels; | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
| View itemView = LayoutInflater.from(parent.getContext()) | ||
| .inflate(R.layout.custom_chat_recyclerview_item, parent, false); | ||
|
|
||
| return new MyViewHolder(itemView); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(MyViewHolder holder, final int position) { | ||
| final ChatMsgModel chatMsgModel = chatMsgModels.get(position); | ||
|
|
||
| if(chatMsgModel.getType()==1) { // Message Sent | ||
| holder.tvMsgSent.setText(chatMsgModel.getMsg()); | ||
| holder.tvMsgSent.setVisibility(View.VISIBLE); | ||
| holder.tvMsgReceived.setVisibility(View.GONE); | ||
| } else { | ||
| holder.tvMsgReceived.setText(chatMsgModel.getMsg()); | ||
| holder.tvMsgReceived.setVisibility(View.VISIBLE); | ||
| holder.tvMsgSent.setVisibility(View.GONE); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| return chatMsgModels.size(); | ||
| } | ||
|
|
||
| public class MyViewHolder extends RecyclerView.ViewHolder { | ||
| RelativeLayout rlMain; | ||
| TextView tvMsgSent; | ||
| TextView tvMsgReceived; | ||
|
|
||
| public MyViewHolder(View view) { | ||
| super(view); | ||
| rlMain = view.findViewById(R.id.rlMain); | ||
| tvMsgSent = view.findViewById(R.id.tvMsgSent); | ||
| tvMsgReceived = view.findViewById(R.id.tvMsgReceived); | ||
| } | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
..._proxy_server-android_app/app/src/main/java/com/example/mlapitest/model/ChatMsgModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.example.mlapitest.model; | ||
|
|
||
| public class ChatMsgModel { | ||
|
|
||
| private String msg; | ||
| private int type; | ||
|
|
||
| public ChatMsgModel(String msg, int type) { | ||
| this.msg = msg; | ||
| this.type = type; | ||
| } | ||
|
|
||
| public String getMsg() { | ||
| return msg; | ||
| } | ||
|
|
||
| public void setMsg(String msg) { | ||
| this.msg = msg; | ||
| } | ||
|
|
||
| public int getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public void setType(int type) { | ||
| this.type = type; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...roid_app/app/src/main/java/com/example/mlapitest/service/MyFirebaseInstanceIDService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.example.mlapitest.service; | ||
|
|
||
| import com.example.mlapitest.AppController; | ||
| import com.google.firebase.messaging.FirebaseMessagingService; | ||
|
|
||
| public class MyFirebaseInstanceIDService extends FirebaseMessagingService { | ||
| private static final String TAG = MyFirebaseInstanceIDService.class.getSimpleName(); | ||
|
|
||
| @Override | ||
| public void onNewToken(String s) { | ||
| super.onNewToken(s); | ||
| String refreshedToken = s; | ||
|
|
||
| AppController.firebaseInstanceId = refreshedToken; | ||
|
|
||
| } | ||
|
|
||
| } |
46 changes: 46 additions & 0 deletions
46
...droid_app/app/src/main/java/com/example/mlapitest/service/MyFirebaseMessagingService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.example.mlapitest.service; | ||
|
|
||
| import android.content.Intent; | ||
| import android.util.Log; | ||
|
|
||
| import com.example.mlapitest.AppController; | ||
| import com.google.firebase.messaging.FirebaseMessagingService; | ||
| import com.google.firebase.messaging.RemoteMessage; | ||
|
|
||
| import org.json.JSONObject; | ||
|
|
||
| public class MyFirebaseMessagingService extends FirebaseMessagingService { | ||
|
|
||
| private static final String TAG = MyFirebaseMessagingService.class.getSimpleName(); | ||
|
|
||
| @Override | ||
| public void onMessageReceived(RemoteMessage remoteMessage) { | ||
| Log.e("FirebaseMessage", "From: " + remoteMessage.getFrom()); | ||
|
|
||
| if (remoteMessage == null) | ||
| return; | ||
|
|
||
| // Check if message contains a notification payload. | ||
| if (remoteMessage.getNotification() != null) { | ||
| Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody()); | ||
| handleNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * function to save the token data in the AppController | ||
| * @param title : expiry time received from FCM | ||
| * @param message : token received from FCM | ||
| */ | ||
| private void handleNotification(String title, String message) { | ||
| AppController.exipryTime = AppController.getDateFromStrinng(title); | ||
| AppController.token = message; | ||
|
|
||
| Intent intent = new Intent(AppController.TOKEN_RECEIVED); | ||
| sendBroadcast(intent); | ||
| } | ||
|
|
||
| private void handleDataMessage(JSONObject json) { | ||
| Log.e(TAG, "push json: " + json.toString()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.