Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aa516b2
Initial commit
deekshithreddyr Jul 10, 2019
ad096da
Addressed review comments
deekshithreddyr Jul 16, 2019
2a0b27f
Added README File
deekshithreddyr Jul 16, 2019
bbd9f4e
Update README.md
deekshithreddyr Jul 17, 2019
a4f9ba8
Update README.md
deekshithreddyr Jul 17, 2019
b33d644
Update README.md
deekshithreddyr Jul 17, 2019
6ce8859
refactor: refactoring the code
deekshithreddyr Jul 21, 2019
0f862d4
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr Jul 21, 2019
2e38050
Add stopwatchagent.zip file
deekshithreddyr Jul 21, 2019
c3c2b78
Update README.md
deekshithreddyr Jul 22, 2019
bba436b
Update README.md
deekshithreddyr Jul 22, 2019
b168253
Changes has per Github comments
deekshithreddyr Jul 23, 2019
e7d5487
Combine the three requests into one. Dropdown instead of multi-selec…
deekshithreddyr Aug 6, 2019
9dcf0d1
Addressed review comments
deekshithreddyr Aug 8, 2019
9ddd430
Using the Audio returned from Dialogflow.
deekshithreddyr Aug 11, 2019
1c2b79f
Addressed review comments
deekshithreddyr Aug 13, 2019
462db73
Separated the Authentication code from AppController.java to AuthUtil…
deekshithreddyr Aug 14, 2019
c8371eb
Code Refinement
deekshithreddyr Aug 18, 2019
20b798a
Update README.md
deekshithreddyr Aug 18, 2019
d31ecb6
Update README.md
deekshithreddyr Aug 19, 2019
cafff50
Addressed review comments
deekshithreddyr Aug 26, 2019
6b8e4bd
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr Aug 26, 2019
4dd38b9
function to convert the time from UTC to local TimeZone added
deekshithreddyr Aug 26, 2019
73edd3f
Code readability update
deekshithreddyr Aug 30, 2019
12e2d39
Update README.md
deekshithreddyr Aug 30, 2019
26599e8
Speech2speech Initial commit
deekshithreddyr Aug 30, 2019
32020e9
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr Aug 30, 2019
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
8 changes: 4 additions & 4 deletions dialogflow/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-auth:18.1.0'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-auth:19.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.1.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation 'com.google.firebase:firebase-functions:19.0.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.cloud:google-cloud-dialogflow:0.98.0-alpha'
implementation group: 'io.grpc', name: 'grpc-okhttp', version: '1.21.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow;

import android.app.Application;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.adapter;

import android.view.LayoutInflater;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.model;

public class ChatMsgModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@

/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.service;

import android.content.Intent;
Expand All @@ -8,10 +25,6 @@
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class MyFirebaseCloudMessagingService extends FirebaseMessagingService {

private static final String TAG = MyFirebaseCloudMessagingService.class.getSimpleName();
Expand All @@ -34,11 +47,8 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
* @param token : token received from FCM
*/
private void handleNotification(String expiryTime, String token) {
try {
AuthUtils.expiryTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(expiryTime);
} catch (ParseException e) {
e.printStackTrace();
}

AuthUtils.setExpiryTime(expiryTime);
AuthUtils.token = token;

Intent intent = new Intent(AppController.TOKEN_RECEIVED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.ui;

import android.Manifest;
Expand Down Expand Up @@ -100,7 +116,7 @@ private void addMsg(String msg, int type) {
*/
private void showProgressDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Please wait...");
builder.setMessage("Fetching auth token...");
builder.setCancelable(false);

alert = builder.create();
Expand Down Expand Up @@ -195,7 +211,7 @@ public void onClick(View v) {
private void sendMsg(String msg) {
if (!TextUtils.isEmpty(msg)) {
// check if the token is received and expiry time is received and not expired
if (AuthUtils.expiryTime != null && !AuthUtils.token.equals("") && AuthUtils.expiryTime.getTime() > System.currentTimeMillis()) {
if (AuthUtils.isTokenValid()) {
addMsg(msg, 1);
etMsg.setText("");
voiceInput = "";
Expand Down Expand Up @@ -337,11 +353,6 @@ public APIRequest(String token, Date expiryTime, String msg, boolean tts, boolea
this.knowledge = knowledge;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected String doInBackground(Void... voids) {
return apiRequest.callAPI(token, expiryTime, msg, tts, sentiment, knowledge);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.utils;

import com.google.api.gax.core.FixedCredentialsProvider;
Expand Down Expand Up @@ -172,7 +188,7 @@ private DetectIntentRequest getDetectIntentRequest(SessionName sessionName, Quer
KnowledgeBasesSettings knowledgeSessionsSettings = KnowledgeBasesSettings.newBuilder()
.setCredentialsProvider(fixedCredentialsProvider).build();
ArrayList<String> knowledgeBaseNames =
KnowledgeBaseUtils.listKnowledgeBases(
KnowledgeBaseUtils123.listKnowledgeBases(
AppController.PROJECT_ID, knowledgeSessionsSettings);

if (knowledgeBaseNames.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.utils;

import android.app.Activity;
Expand All @@ -15,14 +31,21 @@
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

public class AuthUtils {

public static String firebaseInstanceId = "";
public static FirebaseAuth firebaseAuth;
private static String firebaseInstanceId = "";
private static FirebaseAuth firebaseAuth;

public static String token = "";
public static Date expiryTime;
Expand All @@ -39,6 +62,40 @@ public static void callFirebaseFunction() {
.call(data);
}

/**
* function to store the token expiry time
* @param expiryTime : expiry time in UTC timezone
*/
public static void setExpiryTime(String expiryTime) {
AuthUtils.expiryTime = getConvertedDateTime(expiryTime);
}

/**
* function to convert the time from UTC to local TimeZone
* @param expiryTime : expiry time in UTC timezone
* @return Date : converted datetime to local timezonne
*/
private static Date getConvertedDateTime(String expiryTime) {
try {
final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
DateTimeFormatter format = DateTimeFormatter.ofPattern(DATE_FORMAT);
LocalDateTime ldt = LocalDateTime.parse(expiryTime, format);
ZoneId fromZoneId = ZoneId.of(TimeZone.getTimeZone("UTC").getID());
ZonedDateTime fromZoneDateTime = ldt.atZone(fromZoneId);
ZoneId currentZoneId = TimeZone.getDefault().toZoneId();
ZonedDateTime zonedDateTime = fromZoneDateTime.withZoneSameInstant(currentZoneId);
return new SimpleDateFormat(DATE_FORMAT, Locale.US).parse(format.format(zonedDateTime));
} catch(Exception ex) {
ex.printStackTrace();
}

return null;
}

/**
* function to signin to Firebase Anonymously
* @param activity : Instance of the Activity
*/
public static void signInAnonymously(final Activity activity) {
firebaseAuth = FirebaseAuth.getInstance();
firebaseAuth.signInAnonymously()
Expand Down Expand Up @@ -68,6 +125,9 @@ public static boolean checkSignIn() {
return firebaseAuth != null && firebaseAuth.getCurrentUser() != null;
}

/**
* function to get the firebase instance id
*/
public static void getFirebaseInstanceId() {
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
Expand All @@ -79,4 +139,12 @@ public void onSuccess(InstanceIdResult instanceIdResult) {
});
}

/**
* function to check if the token is valid
* @return boolean : indicates the status of the signin
*/
public static boolean isTokenValid() {
return AuthUtils.expiryTime != null && !AuthUtils.token.equals("") && AuthUtils.expiryTime.getTime() > System.currentTimeMillis();
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.examples.dialogflow.utils;


Expand All @@ -8,7 +24,7 @@

import java.util.ArrayList;

public class KnowledgeBaseUtils {
public class KnowledgeBaseUtils123 {

/**
* List Knowledge bases
Expand Down