Commit 906939d6 by Krishna Vemulawada

get incidents validation

parents 35ad6637 aa91bb6f
...@@ -36,7 +36,7 @@ android { ...@@ -36,7 +36,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.vsoft.vera" applicationId "com.vsoft.vera"
minSdkVersion 21 minSdkVersion 23
targetSdkVersion 28 targetSdkVersion 28
versionCode 1 versionCode 1
versionName "0.0.1" versionName "0.0.1"
...@@ -72,24 +72,20 @@ android { ...@@ -72,24 +72,20 @@ android {
vportal { vportal {
applicationId "com.vsoft.vera.vportal" applicationId "com.vsoft.vera.vportal"
versionCode 1 versionCode 1
versionName "1.1.0" versionName "0.2.4"
} }
} }
} }
dependencies { dependencies {
def appCenterSdkVersion = '2.3.0' def appCenterSdkVersion = '2.3.0'
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.volley:volley:1.1.+' implementation 'com.android.volley:volley:1.1.+'
implementation('com.microsoft.aad:adal:1.14.+') { implementation('com.microsoft.aad:adal:1.14.+') {
exclude group: 'com.android.support' exclude group: 'com.android.support'
} }
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}" implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}" implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0' implementation 'com.android.support:support-annotations:28.0.0'
implementation 'android.arch.lifecycle:extensions:1.1.1' implementation 'android.arch.lifecycle:extensions:1.1.1'
...@@ -101,7 +97,6 @@ dependencies { ...@@ -101,7 +97,6 @@ dependencies {
implementation('com.google.android.gms:play-services-analytics:16.0.8') { implementation('com.google.android.gms:play-services-analytics:16.0.8') {
exclude group: 'com.google.firebase', module: 'firebase-iid' exclude group: 'com.google.firebase', module: 'firebase-iid'
} }
implementation 'com.googlecode.android-query:android-query:0.25.9' implementation 'com.googlecode.android-query:android-query:0.25.9'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') { implementation('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') {
...@@ -124,14 +119,14 @@ dependencies { ...@@ -124,14 +119,14 @@ dependencies {
implementation 'de.hdodenhof:circleimageview:3.0.0' implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.github.bumptech.glide:glide:4.8.0' implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.quickbirdstudios:opencv:4.1.0' // implementation 'com.quickbirdstudios:opencv:4.1.0'
implementation 'org.jsoup:jsoup:1.11.3' implementation 'org.jsoup:jsoup:1.11.3'
//static Reports Screen //static Reports Screen
implementation 'com.numetriclabz.numandroidcharts:numandroidcharts:1.0.9' implementation 'com.numetriclabz.numandroidcharts:numandroidcharts:1.0.9'
implementation 'info.hoang8f:android-segmented:1.0.6' implementation 'info.hoang8f:android-segmented:1.0.6'
implementation 'com.github.PhilJay:MPAndroidChart:v2.1.6' implementation 'com.github.PhilJay:MPAndroidChart:v2.1.6'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation files('libs/opencsv-4.6.jar')
} }
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
No preview for this file type
...@@ -88,7 +88,8 @@ ...@@ -88,7 +88,8 @@
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".ui.InAppWebViewActivity" /> <activity android:name=".ui.InAppWebViewActivity" />
<service android:name=".service.SyncService" /> <service android:name=".service.SyncService"
android:permission="android.permission.BIND_JOB_SERVICE" />
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"
......
package com.vsoft.vera; package com.vsoft.vera;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
...@@ -45,10 +48,11 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -45,10 +48,11 @@ public class CatalogueApplication extends MultiDexApplication {
String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION); String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION);
Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: " + action); Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: " + action);
if (Constants.ACTION_SYNC.equals(action)) { if (Constants.ACTION_SYNC.equals(action)) {
Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class); //Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class);
if (Constants.DEBUG) if (Constants.DEBUG)
Log.d(Constants.TAG, "CatalogueApplication: Start SyncService"); Log.d(Constants.TAG, "CatalogueApplication: Start SyncService");
context.startService(syncMatchSummaryIntentIntent); //context.startService(syncMatchSummaryIntentIntent);
scheduleJob(context);
} }
} }
}; };
...@@ -75,6 +79,20 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -75,6 +79,20 @@ public class CatalogueApplication extends MultiDexApplication {
} }
}; };
// schedule the start of the service every 10 - 30 seconds
public static void scheduleJob(Context context) {
ComponentName serviceComponent = new ComponentName(context, SyncService.class);
JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
builder.setMinimumLatency(1 * 1000); // wait at least
builder.setOverrideDeadline(3 * 1000); // maximum delay
//builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); // require unmetered network
//builder.setRequiresDeviceIdle(true); // device should be idle
//builder.setRequiresCharging(false); // we don't care if the device is charging or not
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
jobScheduler.schedule(builder.build());
}
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
...@@ -156,11 +174,8 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -156,11 +174,8 @@ public class CatalogueApplication extends MultiDexApplication {
options.upgrade = true; options.upgrade = true;
mSocket = IO.socket(Constants.CHAT_SERVER_URL,options); mSocket = IO.socket(Constants.CHAT_SERVER_URL,options);
// mSocket = IO.socket("http://10.1.8.229:12811",options);
mSocket.io().timeout(-1);
mSocket.io().reconnection(true);
mSocket.io().reconnectionDelay(0);
mSocket.io().reconnectionAttempts(2000);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
package com.vsoft.vera.adapters; package com.vsoft.vera.adapters;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
...@@ -10,6 +11,7 @@ import android.text.method.LinkMovementMethod; ...@@ -10,6 +11,7 @@ import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.Button; import android.widget.Button;
...@@ -37,6 +39,7 @@ import org.jsoup.select.Elements; ...@@ -37,6 +39,7 @@ import org.jsoup.select.Elements;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.ViewHolder> { public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.ViewHolder> {
...@@ -135,6 +138,8 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter. ...@@ -135,6 +138,8 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.
viewAllBT.setOnClickListener(new View.OnClickListener() { viewAllBT.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
Intent intent = new Intent(mContext, MyIncidentScreen.class); Intent intent = new Intent(mContext, MyIncidentScreen.class);
mContext.startActivity(intent); mContext.startActivity(intent);
...@@ -466,19 +471,28 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter. ...@@ -466,19 +471,28 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(mContext),"android"); webView.addJavascriptInterface(new WebAppInterface(mContext),"android");
webView.loadData(message, "text/html", "utf-8"); webView.loadData(message, "text/html", "utf-8");
}else if( message.contains("I could find following 1") && message.contains("I could find following 2") && message.contains("I could find following 3")&&message.contains("I could find following 4")&&message.contains("I could find following 5") ){ }else if( message.contains("I could find following ")){
String[] stringArray = message.split("I could find following ");
String textMessage = stringArray[1];
String splitMessage = textMessage;
String[] stringArray1 = splitMessage.split(" ");
int incidentNumber = Integer.parseInt(stringArray1[0]);
if(incidentNumber <= 6 ){
hr_text_layt.setVisibility(View.VISIBLE); hr_text_layt.setVisibility(View.VISIBLE);
mHRMessageView.setVisibility(View.VISIBLE); mHRMessageView.setVisibility(View.VISIBLE);
viewAllBT.setVisibility(View.GONE); viewAllBT.setVisibility(View.GONE);
mHRMessageView.setMovementMethod(LinkMovementMethod.getInstance()); mHRMessageView.setMovementMethod(LinkMovementMethod.getInstance());
mHRMessageView.setText(Util.fromHtml(message)); mHRMessageView.setText(Util.fromHtml(message));
}else if(message.contains("I could find following ")) { }else {
hr_text_layt.setVisibility(View.VISIBLE); hr_text_layt.setVisibility(View.VISIBLE);
mHRMessageView.setVisibility(View.VISIBLE); mHRMessageView.setVisibility(View.VISIBLE);
viewAllBT.setVisibility(View.VISIBLE); viewAllBT.setVisibility(View.VISIBLE);
mHRMessageView.setMovementMethod(LinkMovementMethod.getInstance()); mHRMessageView.setMovementMethod(LinkMovementMethod.getInstance());
mHRMessageView.setText(Util.fromHtml(message)); mHRMessageView.setText(Util.fromHtml(message));
}
}else if(message.contains("Ok, here's the link to the live agent:")) { }else if(message.contains("Ok, here's the link to the live agent:")) {
......
...@@ -40,12 +40,14 @@ import retrofit2.Retrofit; ...@@ -40,12 +40,14 @@ import retrofit2.Retrofit;
public class IncidentApiManager { public class IncidentApiManager {
public static void getIncident(Context context, GetIncidentApiListener listener) { public static void getIncident(Context context, GetIncidentApiListener listener) {
String sysId = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_DYNAMIC_USER_SYS_ID);
CatalogueLog.d("IncidentApiManager: getIncident: "); CatalogueLog.d("IncidentApiManager: getIncident: ");
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("caller_id=javascript:gs.getUserID()"); stringBuilder.append("caller_id="+sysId);
CatalogueLog.d("IncidentApiManager: getIncident: request parameter: "+stringBuilder.toString()); CatalogueLog.d("IncidentApiManager: getIncident: request parameter: "+stringBuilder.toString());
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN); String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) { if(accessToken.isEmpty()) {
listener.onFailApiCall(); listener.onFailApiCall();
return; return;
......
...@@ -2,6 +2,7 @@ package com.vsoft.vera.db; ...@@ -2,6 +2,7 @@ package com.vsoft.vera.db;
public interface DBConstants { public interface DBConstants {
//Tables //Tables
String TABLE_CHAT_LOG = "chat_log";
String TABLE_CATALOGUE = "catalogue_category"; String TABLE_CATALOGUE = "catalogue_category";
String TABLE_CATALOGUE_ITEM = "catalogue_category_item"; String TABLE_CATALOGUE_ITEM = "catalogue_category_item";
String TABLE_CATALOGUE_VARIABLES = "catalogue_variable"; String TABLE_CATALOGUE_VARIABLES = "catalogue_variable";
...@@ -41,6 +42,16 @@ public interface DBConstants { ...@@ -41,6 +42,16 @@ public interface DBConstants {
int SYNC_FLAG_DELETE = 3; int SYNC_FLAG_DELETE = 3;
/** /**
* Chat log table
*/
String CHAT_ID = "chat_id";
String CHAT_CLIENT_MESSAGE = "client_message";
String CHAT_SERVER__RESPONSE = "server_response";
String CHAT_TIMESTAMP = "timestamp";
String CHAT_CONN_STATUS= "conn_status";
String CHAT_SOCKET_ID= "socket_id";
/**
* Catalogue table * Catalogue table
*/ */
String CATALOGUE_ID = ID; String CATALOGUE_ID = ID;
...@@ -405,6 +416,8 @@ public interface DBConstants { ...@@ -405,6 +416,8 @@ public interface DBConstants {
*/ */
int CHAT_BOT_HISTORY_COLUMN_COUNT = 5; int CHAT_BOT_HISTORY_COLUMN_COUNT = 5;
int CHAT_LOG__COLUMN_COUNT = 5;
/** /**
* ChatBot User table * ChatBot User table
*/ */
......
...@@ -40,6 +40,7 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -40,6 +40,7 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createCatalogueItemInputTable(db); createCatalogueItemInputTable(db);
createAttachmentTable(db); createAttachmentTable(db);
createIncidentInputTable(db); createIncidentInputTable(db);
createChatLogTable(db);
// if(Util.isNotificationsItemEnabled()) { // if(Util.isNotificationsItemEnabled()) {
// createNotificationsTable(db); // createNotificationsTable(db);
...@@ -76,6 +77,17 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -76,6 +77,17 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
onCreate(db); onCreate(db);
} }
private void createChatLogTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_CHAT_LOG + "("
+ CHAT_ID + " integer primary key autoincrement, "
+ CHAT_CLIENT_MESSAGE + " text, "
+ CHAT_SERVER__RESPONSE + " text, "
+ CHAT_TIMESTAMP + " text, "
+ CHAT_CONN_STATUS + " text, "
+ CHAT_SOCKET_ID + " text"
+ ");");
}
private void createCatalogueTable(SQLiteDatabase db) { private void createCatalogueTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_CATALOGUE + "(" db.execSQL("create table " + TABLE_CATALOGUE + "("
+ CATALOGUE_ID + " integer primary key autoincrement, " + CATALOGUE_ID + " integer primary key autoincrement, "
......
package com.vsoft.vera.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.db.DBConstants;
import com.vsoft.vera.db.models.ChatBotHistory;
import com.vsoft.vera.utils.ChatLog;
import com.vsoft.vera.utils.Util;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
*
* @author Kunj on 05-04-2018.
*/
public class ChatLogManager implements DBConstants {
public static long save(ChatLog chatLog) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
long id = db.insert(TABLE_CHAT_LOG, null, getChatLogContentValues(chatLog));
chatLog.setChatId(id);
return id;
} else {
return -1;
}
}
public static List<ChatLog> getAllChatLogHistory() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
String queryString = "select * from " + TABLE_CHAT_LOG +";";
Cursor c = db.rawQuery(queryString, null);
ArrayList<ChatLog> chatLogList;
if (c.getCount() > 0) {
chatLogList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
ChatLog chatLog = new ChatLog();
chatLog.setChatId(c.getLong(0));
chatLog.setClientMessage(c.getString(1));
chatLog.setServerResponse(c.getString(2));
chatLog.setTimestamp(c.getString(3));
chatLog.setConnStatus(c.getString(4));
chatLog.setSocketConnId(c.getString(5));
chatLogList.add(chatLog);
}
} else {
chatLogList = new ArrayList<>(0);
}
c.close();
return chatLogList;
} else {
return new ArrayList<>(0);
}
}
public static int deleteAllRows() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_CHAT_LOG, null, null);
}
return -1;
}
public static void saveLogEvent(String clientMsg, String serverMsg, String connStatus, String connId, Date timestamp){
ChatLog chatLog = new ChatLog();
chatLog.setTimestamp(Util.getDateTime(timestamp.getTime()));
chatLog.setServerResponse(serverMsg);
chatLog.setClientMessage(clientMsg);
chatLog.setConnStatus(connStatus);
chatLog.setSocketConnId(connId);
ChatLogManager.save(chatLog);
}
private static ContentValues getChatLogContentValues(ChatLog chatLog) {
ContentValues cv = new ContentValues(CHAT_LOG__COLUMN_COUNT - 1);
cv.put(CHAT_CLIENT_MESSAGE, chatLog.getClientMessage());
cv.put(CHAT_SERVER__RESPONSE, chatLog.getServerResponse());
cv.put(CHAT_TIMESTAMP, chatLog.getTimestamp());
cv.put(CHAT_CONN_STATUS, chatLog.getConnStatus());
cv.put(CHAT_SOCKET_ID, chatLog.getSocketConnId());
return cv;
}
}
\ No newline at end of file
package com.vsoft.vera.service; package com.vsoft.vera.service;
import android.app.IntentService; import android.app.IntentService;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask;
import com.vsoft.vera.CatalogueApplication; import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.api.listeners.get.GetChatServerApiListener; import com.vsoft.vera.api.listeners.get.GetChatServerApiListener;
...@@ -62,21 +65,32 @@ import static com.vsoft.vera.db.managers.CatalogueItemInputManager.getDirtyItemI ...@@ -62,21 +65,32 @@ import static com.vsoft.vera.db.managers.CatalogueItemInputManager.getDirtyItemI
*/ */
public class SyncService extends IntentService { public class SyncService extends JobService {
private SyncStatus syncStatus = SyncStatus.FAIL; private SyncStatus syncStatus = SyncStatus.FAIL;
public SyncService() { @Override
super(SyncService.class.getSimpleName()); public boolean onStartJob(JobParameters params) {
BackgroundQueueAsync backgroundQueueAsync = new BackgroundQueueAsync();
backgroundQueueAsync.execute();
return false;
}
@Override
public boolean onStopJob(JobParameters params) {
return false;
}
public class BackgroundQueueAsync extends AsyncTask<Void, Void, Void> {
public BackgroundQueueAsync() {
} }
@Override @Override
protected void onHandleIntent(Intent intent) { protected Void doInBackground(Void... voids) {
CatalogueApplication application = (CatalogueApplication) getApplication(); CatalogueApplication application = (CatalogueApplication) getApplication();
if (!application.isNetConnected()) { if (!application.isNetConnected()) {
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit."); CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit.");
return; }else{
}
if(Util.isChatItemEnabled()) { if(Util.isChatItemEnabled()) {
if (application.getSocket() == null) { if (application.getSocket() == null) {
...@@ -87,6 +101,11 @@ public class SyncService extends IntentService { ...@@ -87,6 +101,11 @@ public class SyncService extends IntentService {
startSync(); startSync();
} }
return null;
}
}
/** /**
* Get Chatserver Url. * Get Chatserver Url.
**/ **/
......
...@@ -15,10 +15,8 @@ import android.os.Handler; ...@@ -15,10 +15,8 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
...@@ -74,7 +72,6 @@ import org.json.JSONObject; ...@@ -74,7 +72,6 @@ import org.json.JSONObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
...@@ -172,8 +169,6 @@ public class ADALActivity extends AppCompatActivity { ...@@ -172,8 +169,6 @@ public class ADALActivity extends AppCompatActivity {
} }
}); });
getCountryCode();
// CheckLoginValues(); // CheckLoginValues();
callGraphButton = (Button) findViewById(R.id.callGraph); callGraphButton = (Button) findViewById(R.id.callGraph);
signOutButton = (Button) findViewById(R.id.clearCache); signOutButton = (Button) findViewById(R.id.clearCache);
...@@ -194,6 +189,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -194,6 +189,7 @@ public class ADALActivity extends AppCompatActivity {
}); });
login_with_otp.setOnClickListener(new View.OnClickListener() { login_with_otp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
// onSignOutClicked(); // onSignOutClicked();
...@@ -334,10 +330,10 @@ public class ADALActivity extends AppCompatActivity { ...@@ -334,10 +330,10 @@ public class ADALActivity extends AppCompatActivity {
try { try {
root = new JSONObject(response.toString()); root = new JSONObject(response.toString());
String userLoginName = root.getString("givenName"); String userLoginName = root.getString("givenName");
/*Send broadcast to start SyncService*/
String mail = root.getString("mail"); String mail = root.getString("mail");
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FULL_NAME, userLoginName); PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FULL_NAME, userLoginName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_EMAIL_ID, mail); PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_EMAIL_ID, mail);
/*Send broadcast to start SyncService*/
if(!isLogin){ if(!isLogin){
new LoginDetailsSendToServer().execute(); new LoginDetailsSendToServer().execute();
...@@ -664,32 +660,49 @@ public class ADALActivity extends AppCompatActivity { ...@@ -664,32 +660,49 @@ public class ADALActivity extends AppCompatActivity {
DialogUtils.showNoConnectionDialog(ADALActivity.this); DialogUtils.showNoConnectionDialog(ADALActivity.this);
} }
String generateRandoStrPharma = GenerateRandomString.randomString(30); String generateRandoStrPharma = GenerateRandomString.randomString(30);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.SESSION_ID, generateRandoStrPharma); PrefManager.setSharedPref(ADALActivity.this, PrefManager.SESSION_ID, generateRandoStrPharma);
String firstName = mUserDetails.get(0).getFirstName(); String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName(); String lastName = mUserDetails.get(0).getLastName();
// String sysid = mUserDetails.get(0).getSysId(); String sysid = mUserDetails.get(0).getSysId();
String userFullName = mUserDetails.get(0).getFullName(); String userFullName = mUserDetails.get(0).getFullName();
String userId = mUserDetails.get(0).getUserId(); String userId = mUserDetails.get(0).getUserId();
String userEmailId = mUserDetails.get(0).getUserEmailId(); String userEmailId = mUserDetails.get(0).getUserEmailId();
if(Util.isChatItemEnabled()) {
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(sysid);
if (localChatBotUser == null) {
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager.deleteAllRows();
ChatBotUserManager.deleteAllRows();
/*Save Logged in user in local db for chat screen*/
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setUserSysId(sysid)
.setName(firstName)
.build();
ChatBotUserManager.save(chatBotUser);
} else {//Update the name of user
localChatBotUser.setName(firstName);
ChatBotUserManager.update(localChatBotUser);
}
}
/*End Chat Local DB Part*/ /*End Chat Local DB Part*/
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FIRST_NAME, firstName); PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FIRST_NAME, firstName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_LAST_NAME, lastName); PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_LAST_NAME, lastName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_SYS_ID, sysid);
/*For pre fill value in variable form*/ /*For pre fill value in variable form*/
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_ID, userId); PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_ID, userId);
new GetyUserSysIDAsync().execute(); new GetyUserSysIDAsync().execute();
// //
//
} else { } else {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.user_detail_not_available)); Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.user_detail_not_available));
} }
...@@ -701,7 +714,6 @@ public class ADALActivity extends AppCompatActivity { ...@@ -701,7 +714,6 @@ public class ADALActivity extends AppCompatActivity {
} }
} }
private class GetyUserSysIDAsync extends AsyncTask<Void, Void, SyncStatus> { private class GetyUserSysIDAsync extends AsyncTask<Void, Void, SyncStatus> {
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL; private SyncStatus syncStatus = SyncStatus.FAIL;
...@@ -732,6 +744,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -732,6 +744,7 @@ public class ADALActivity extends AppCompatActivity {
public void onDoneApiCall(String url) { public void onDoneApiCall(String url) {
userSysId = url; userSysId = url;
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_DYNAMIC_USER_SYS_ID, userSysId);
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
} }
...@@ -754,28 +767,8 @@ public class ADALActivity extends AppCompatActivity { ...@@ -754,28 +767,8 @@ public class ADALActivity extends AppCompatActivity {
if (syncStatus == SyncStatus.SUCCESS) { if (syncStatus == SyncStatus.SUCCESS) {
if(userSysId != null){ if(userSysId != null){
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_SYS_ID, userSysId);
if(Util.isChatItemEnabled()) {
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(userSysId);
if (localChatBotUser == null) {
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager.deleteAllRows();
ChatBotUserManager.deleteAllRows();
/*Save Logged in user in local db for chat screen*/
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setUserSysId(userSysId)
.setName(userFullName)
.build();
ChatBotUserManager.save(chatBotUser);
} else {//Update the name of user
localChatBotUser.setName(userFullName);
ChatBotUserManager.update(localChatBotUser);
}
}
/*Send broadcast to start SyncService*/ /*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT); Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC); intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
...@@ -809,27 +802,4 @@ public class ADALActivity extends AppCompatActivity { ...@@ -809,27 +802,4 @@ public class ADALActivity extends AppCompatActivity {
} }
} }
/*
* getCountryCode - To get the Country mobile code dynamically.
*
* @return void
* */
public void getCountryCode() {
try {
TelephonyManager telephonyManager =
(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
String countryName = telephonyManager.getNetworkCountryIso();
if(countryName.equalsIgnoreCase("us")) {
Constants.TWILIO_COUNTRY_CODE = "+1";
}
if(countryName.equalsIgnoreCase("in")) {
Constants.TWILIO_COUNTRY_CODE = "+91";
}
}
} catch (Exception e) {
Constants.TWILIO_COUNTRY_CODE = "+1";
}
}
} }
...@@ -55,6 +55,7 @@ import com.bumptech.glide.request.target.SimpleTarget; ...@@ -55,6 +55,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.github.nkzawa.emitter.Emitter; import com.github.nkzawa.emitter.Emitter;
import com.github.nkzawa.socketio.client.Socket; import com.github.nkzawa.socketio.client.Socket;
import com.opencsv.CSVWriter;
import com.vsoft.vera.CatalogueApplication; import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.R; import com.vsoft.vera.R;
import com.vsoft.vera.api.listeners.get.GetLiveAgentApiListener; import com.vsoft.vera.api.listeners.get.GetLiveAgentApiListener;
...@@ -70,6 +71,7 @@ import com.vsoft.vera.chat.Speaker; ...@@ -70,6 +71,7 @@ import com.vsoft.vera.chat.Speaker;
import com.vsoft.vera.db.DBConstants; import com.vsoft.vera.db.DBConstants;
import com.vsoft.vera.db.managers.ChatBotHistoryManager; import com.vsoft.vera.db.managers.ChatBotHistoryManager;
import com.vsoft.vera.db.managers.ChatBotUserManager; import com.vsoft.vera.db.managers.ChatBotUserManager;
import com.vsoft.vera.db.managers.ChatLogManager;
import com.vsoft.vera.db.models.ChatBotHistory; import com.vsoft.vera.db.models.ChatBotHistory;
import com.vsoft.vera.db.models.ChatBotUser; import com.vsoft.vera.db.models.ChatBotUser;
import com.vsoft.vera.db.models.UserApiValues; import com.vsoft.vera.db.models.UserApiValues;
...@@ -78,6 +80,7 @@ import com.vsoft.vera.speechRecognizer.DroidSpeech; ...@@ -78,6 +80,7 @@ import com.vsoft.vera.speechRecognizer.DroidSpeech;
import com.vsoft.vera.speechRecognizer.OnDSListener; import com.vsoft.vera.speechRecognizer.OnDSListener;
import com.vsoft.vera.speechRecognizer.OnDSPermissionsListener; import com.vsoft.vera.speechRecognizer.OnDSPermissionsListener;
import com.vsoft.vera.utils.CatalogueLog; import com.vsoft.vera.utils.CatalogueLog;
import com.vsoft.vera.utils.ChatLog;
import com.vsoft.vera.utils.Constants; import com.vsoft.vera.utils.Constants;
import com.vsoft.vera.utils.DialogUtils; import com.vsoft.vera.utils.DialogUtils;
import com.vsoft.vera.utils.GenerateRandomString; import com.vsoft.vera.utils.GenerateRandomString;
...@@ -91,16 +94,10 @@ import com.wang.avi.AVLoadingIndicatorView; ...@@ -91,16 +94,10 @@ import com.wang.avi.AVLoadingIndicatorView;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -167,7 +164,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -167,7 +164,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private static final long LISTENING_DIALOG_DISMISS_DELAY_TIME = 10000; private static final long LISTENING_DIALOG_DISMISS_DELAY_TIME = 10000;
private Boolean opencvEnd = false; private Boolean opencvEnd = false;
private boolean isBlur = false; private boolean isBlur = false;
private Mat imageMat; // private Mat imageMat;
private ImageButton sendButton; private ImageButton sendButton;
private final static String INIT_MSG = "hi"; private final static String INIT_MSG = "hi";
private String chatHistroy= ""; private String chatHistroy= "";
...@@ -210,7 +207,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -210,7 +207,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mLoggedInUserSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_SYS_ID); mLoggedInUserSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_SYS_ID);
mLoggedInUsername = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_FIRST_NAME); mLoggedInUsername = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_FIRST_NAME);
userSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_SYS_ID); userSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_DYNAMIC_USER_SYS_ID);
if(TextUtils.isEmpty(mLoggedInUserSysId) || TextUtils.isEmpty(mLoggedInUsername)) { if(TextUtils.isEmpty(mLoggedInUserSysId) || TextUtils.isEmpty(mLoggedInUsername)) {
CatalogueLog.e("User Sys id or Name is Null"); CatalogueLog.e("User Sys id or Name is Null");
...@@ -402,6 +399,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -402,6 +399,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}); });
mMessagesView.addOnItemTouchListener(mOnItemTouchListener); mMessagesView.addOnItemTouchListener(mOnItemTouchListener);
} }
private void readAndWriteCallsData() { private void readAndWriteCallsData() {
...@@ -595,16 +594,65 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -595,16 +594,65 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
finish(); finish();
return true; return true;
/*case R.id.voice_menu_icon: case R.id.export_log:
//get all logs
List<ChatLog> chatLogList = ChatLogManager.getAllChatLogHistory();
Log.i(TAG, "chat log list count = "+ chatLogList.size());
exportAndSaveLogs(chatLogList);
//delete all logs
ChatLogManager.deleteAllRows();
Toast.makeText(getApplicationContext(),
"Export Completed. Check in your external storage.", Toast.LENGTH_LONG).show();
return true; return true;
case R.id.text_menu_icon: /* case R.id.text_menu_icon:
return true;*/ return true;*/
default: default:
return super.onOptionsItemSelected(menuItem); return super.onOptionsItemSelected(menuItem);
} }
} }
private void exportAndSaveLogs(List<ChatLog> chatLogList) {
String baseDir = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
String dateString = Util.getDateTime(new Date().getTime());
String fileName = "ChatLogs_" + dateString + ".csv";
String filePath = baseDir + File.separator + fileName;
File f = new File(filePath);
CSVWriter writer;
// File exist
if (f.exists() && !f.isDirectory()) {
FileWriter mFileWriter = null;
try {
mFileWriter = new FileWriter(filePath, true);
writer = new CSVWriter(mFileWriter);
for (ChatLog chat: chatLogList) {
String[] line = {""+chat.getChatId(),chat.getClientMessage(), chat.getServerResponse(), chat.getConnStatus(), chat.getTimestamp() } ;
writer.writeNext(line);
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
writer = new CSVWriter(new FileWriter(filePath));
String[] headerLine = {"Chat Id", "Time Stamp", "Conn Status" ,"Socket Id" , "Client Msg","Server Msg"} ;
writer.writeNext(headerLine);
for (ChatLog chat: chatLogList) {
String[] line = {""+chat.getChatId(),chat.getTimestamp() , chat.getConnStatus(), chat.getSocketConnId(), chat.getClientMessage(), chat.getServerResponse() } ;
writer.writeNext(line);
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/** /**
* this message calls when we will add send and receive message in chat screen. * this message calls when we will add send and receive message in chat screen.
*/ */
...@@ -673,26 +721,27 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -673,26 +721,27 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
*/ */
private void attemptSend() { private void attemptSend() {
if (NetworkConnectivity.haveNetworkConnection(ChatActivity.this)) { if (NetworkConnectivity.haveNetworkConnection(ChatActivity.this)) {
String message = mInputMessageView.getText().toString().trim(); String message = mInputMessageView.getText().toString().trim();
if (!TextUtils.isEmpty(message)){ if (!TextUtils.isEmpty(message)){
if (null == mLoggedInUsername) return; if (null == mLoggedInUsername) return;
if (!mSocket.connected())
return;
//Whenever we'll click on send button, running TTS speak should stop //Whenever we'll click on send button, running TTS speak should stop
if(speaker != null && speaker.isSpeaking()) { if(speaker != null && speaker.isSpeaking()) {
speaker.stop(); speaker.stop();
} }
textDotLoader.show();
if (TextUtils.isEmpty(message)) { /**
mInputMessageView.requestFocus(); * checking socket connection, if it is false,
* then we are reconnecting and send the message again
*/
if (!mSocket.connected()){
showSocketConnectError();
mSocket.connect();
return; return;
} }
textDotLoader.show();
mInputMessageView.setText(""); mInputMessageView.setText("");
addMessage(mLoggedInUsername, message,""); addMessage(mLoggedInUsername, message,"");
...@@ -708,9 +757,15 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -708,9 +757,15 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
Log.i("Print", jsonObject.toString());
mSocket.emit(NEW_MESSAGE, jsonObject); mSocket.emit(NEW_MESSAGE, jsonObject);
ChatLogManager.saveLogEvent(message,"",String.valueOf(mSocket.connected()), mSocket.id(),new Date());
} else { } else {
mInputMessageView.requestFocus();
Toast toast = Toast.makeText(getApplicationContext(), "Please enter the message", Toast.LENGTH_LONG); Toast toast = Toast.makeText(getApplicationContext(), "Please enter the message", Toast.LENGTH_LONG);
View toastView = toast.getView(); // This'll return the default View of the Toast. View toastView = toast.getView(); // This'll return the default View of the Toast.
...@@ -748,7 +803,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -748,7 +803,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void run() { public void run() {
// userAuthenticateTask(); // userAuthenticateTask();
Log.e(TAG, "socket got connected" + mSocket.id());
// Toast.makeText(getApplicationContext(),
// R.string.connect, Toast.LENGTH_LONG).show();
initChatMessage(INIT_MSG); initChatMessage(INIT_MSG);
ChatLogManager.saveLogEvent("New Connection Created","","true", mSocket.id(), new Date());
} }
}); });
} }
...@@ -780,7 +839,35 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -780,7 +839,35 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} }
} }
private void showSocketConnectError(){
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e(TAG,"failed to connect");
Snackbar snackbar = Snackbar
.make(mMessagesView, R.string.error_connect, Snackbar.LENGTH_LONG)
.setAction("Dismiss", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
snackbar.show();
// Changing message text color
snackbar.setActionTextColor(Color.RED);
// Changing action button text color
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.show();
}
});
}
/** /**
* Chat server calls this if we will disconnect from server. * Chat server calls this if we will disconnect from server.
...@@ -788,6 +875,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -788,6 +875,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onDisconnect = new Emitter.Listener() { private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
ChatLogManager.saveLogEvent("Connection Disconnected","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -818,8 +907,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -818,8 +907,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onConnectTimeOut = new Emitter.Listener() { private Emitter.Listener onConnectTimeOut = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Toast.makeText(getApplicationContext(), Log.e(TAG, "onConnectTimeOut Called");
"onConnectTimeOut Called", Toast.LENGTH_LONG).show(); ChatLogManager.saveLogEvent("Connection Timed Out","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
// Toast.makeText(getApplicationContext(),
// "onConnectTimeOut Called", Toast.LENGTH_LONG).show();
//reconnect(); //reconnect();
} }
}; };
...@@ -830,8 +922,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -830,8 +922,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onReconnect = new Emitter.Listener() { private Emitter.Listener onReconnect = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
/*Toast.makeText(getApplicationContext(), Log.e(TAG, "Reconnection Called");
"Reconnection Called", Toast.LENGTH_LONG).show();*/ ChatLogManager.saveLogEvent("Reconnection Called","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
// Toast.makeText(getApplicationContext(),
// "Reconnection Called", Toast.LENGTH_LONG).show();
//reconnect(); //reconnect();
} }
...@@ -843,10 +938,13 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -843,10 +938,13 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onConnectError = new Emitter.Listener() { private Emitter.Listener onConnectError = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
ChatLogManager.saveLogEvent("Failed create a socket connection","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if(!isConnectError) { if(!isConnectError) {
Log.e(TAG,"failed to connect");
Snackbar snackbar = Snackbar Snackbar snackbar = Snackbar
.make(mMessagesView, R.string.error_connect, Snackbar.LENGTH_LONG) .make(mMessagesView, R.string.error_connect, Snackbar.LENGTH_LONG)
.setAction("Dismiss", new View.OnClickListener() { .setAction("Dismiss", new View.OnClickListener() {
...@@ -937,6 +1035,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -937,6 +1035,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} }
if(!message.isEmpty()) { if(!message.isEmpty()) {
ChatLogManager.saveLogEvent("",message,String.valueOf(mSocket.connected()), mSocket.id(),new Date());
if(message.contains(Constants.RESET_PASSWORD_NAVIGATION_SCREEN)){ if(message.contains(Constants.RESET_PASSWORD_NAVIGATION_SCREEN)){
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
...@@ -1133,7 +1232,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -1133,7 +1232,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
if(data != null ){ if(data != null ){
if (takePictureFilePath != null && !takePictureFilePath.isEmpty()) { if (takePictureFilePath != null && !takePictureFilePath.isEmpty()) {
processImageAsBitmap(takePictureFilePath); // processImageAsBitmap(takePictureFilePath);
} }
}else { }else {
initChatMessage("stop"); initChatMessage("stop");
...@@ -1159,109 +1258,109 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -1159,109 +1258,109 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private void processImageAsBitmap(String imageFilePath) { // private void processImageAsBitmap(String imageFilePath) {
try { // try {
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); // BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
takePhotobitmap = BitmapFactory.decodeFile(imageFilePath, bitmapOptions); // takePhotobitmap = BitmapFactory.decodeFile(imageFilePath, bitmapOptions);
// setImageOrientation(imageFilePath, bitmap); //// setImageOrientation(imageFilePath, bitmap);
//
if (takePhotobitmap != null) { // if (takePhotobitmap != null) {
//
opencvProcess(takePhotobitmap); // opencvProcess(takePhotobitmap);
if (isBlur) { // if (isBlur) {
reTakePhoto(); // reTakePhoto();
} else { // } else {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
takePhotobitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArrayOutputStream); // takePhotobitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray(); // byte[] byteArray = byteArrayOutputStream.toByteArray();
String base64Image = Base64.encodeToString(byteArray, Base64.DEFAULT); // String base64Image = Base64.encodeToString(byteArray, Base64.DEFAULT);
addMessage(mLoggedInUsername, "", takePictureFilePath); // addMessage(mLoggedInUsername, "", takePictureFilePath);
//
if (null == mLoggedInUsername) return; // if (null == mLoggedInUsername) return;
if (!mSocket.connected()) return; // if (!mSocket.connected()) return;
textDotLoader.show(); // textDotLoader.show();
//
// perform the sending message attempt. // // perform the sending message attempt.
JSONObject jsonObject = new JSONObject(); // JSONObject jsonObject = new JSONObject();
try { // try {
jsonObject.put(CLIENT_MESSAGE_KEY, ""); // jsonObject.put(CLIENT_MESSAGE_KEY, "");
jsonObject.put(CLIENT_MAIL_KEY, PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_EMAIL_ID)); // jsonObject.put(CLIENT_MAIL_KEY, PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_EMAIL_ID));
jsonObject.put(SESSION_ID_UNIQ, PrefManager.getSharedPref(ChatActivity.this, PrefManager.SESSION_ID)); // jsonObject.put(SESSION_ID_UNIQ, PrefManager.getSharedPref(ChatActivity.this, PrefManager.SESSION_ID));
jsonObject.put(LOCATION, "location"); // jsonObject.put(LOCATION, "location");
jsonObject.put(USER_SYSID, userSysId); // jsonObject.put(USER_SYSID, userSysId);
jsonObject.put(SCANNED_IMAGE, base64Image); // jsonObject.put(SCANNED_IMAGE, base64Image);
} catch (JSONException e) { // } catch (JSONException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
mSocket.emit(NEW_MESSAGE, jsonObject); // mSocket.emit(NEW_MESSAGE, jsonObject);
} // }
//
} else { // } else {
} // }
//
//
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i("OpenCV", "OpenCV loaded successfully");
imageMat=new Mat();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
private void opencvProcess(Bitmap image) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = true;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
int l = CvType.CV_8UC1; //8-bit grey scale image
Utils.bitmapToMat(image, imageMat);
Mat matImageGrey = new Mat();
Imgproc.cvtColor(imageMat, matImageGrey, Imgproc.COLOR_BGR2GRAY);
Bitmap destImage;
destImage = Bitmap.createBitmap(image);
Mat dst2 = new Mat();
Utils.bitmapToMat(destImage, dst2);
Mat laplacianImage = new Mat();
dst2.convertTo(laplacianImage, l);
Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
Mat laplacianImage8bit = new Mat();
laplacianImage.convertTo(laplacianImage8bit, l);
Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(), laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(laplacianImage8bit, bmp);
int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
int maxLap = -16777216; // 16m
for (int pixel : pixels) {
if (pixel > maxLap)
maxLap = pixel;
}
int soglia = -6118750; // private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
if (maxLap <= soglia) { // @Override
System.out.println("is blur image"); // public void onManagerConnected(int status) {
} // switch (status) {
soglia += 6118750; // case LoaderCallbackInterface.SUCCESS:
maxLap += 6118750; // {
opencvEnd = true; // Log.i("OpenCV", "OpenCV loaded successfully");
isBlur = maxLap <= soglia; // imageMat=new Mat();
} // } break;
// default:
// {
// super.onManagerConnected(status);
// } break;
// }
// }
// };
// private void opencvProcess(Bitmap image) {
// BitmapFactory.Options options = new BitmapFactory.Options();
// options.inDither = true;
// options.inPreferredConfig = Bitmap.Config.ARGB_8888;
// int l = CvType.CV_8UC1; //8-bit grey scale image
//
// Utils.bitmapToMat(image, imageMat);
// Mat matImageGrey = new Mat();
// Imgproc.cvtColor(imageMat, matImageGrey, Imgproc.COLOR_BGR2GRAY);
//
// Bitmap destImage;
// destImage = Bitmap.createBitmap(image);
// Mat dst2 = new Mat();
// Utils.bitmapToMat(destImage, dst2);
// Mat laplacianImage = new Mat();
// dst2.convertTo(laplacianImage, l);
// Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
// Mat laplacianImage8bit = new Mat();
// laplacianImage.convertTo(laplacianImage8bit, l);
//
// Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(), laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
// Utils.matToBitmap(laplacianImage8bit, bmp);
// int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
// bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
//
// int maxLap = -16777216; // 16m
// for (int pixel : pixels) {
// if (pixel > maxLap)
// maxLap = pixel;
// }
//
// int soglia = -6118750;
// if (maxLap <= soglia) {
// System.out.println("is blur image");
// }
// soglia += 6118750;
// maxLap += 6118750;
// opencvEnd = true;
// isBlur = maxLap <= soglia;
// }
private void checkTTS() { private void checkTTS() {
Intent check = new Intent(); Intent check = new Intent();
...@@ -1273,15 +1372,17 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -1273,15 +1372,17 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
public void onResume() public void onResume()
{ {
super.onResume(); super.onResume();
if(mSocket != null && !mSocket.connected()) if(mSocket != null && !mSocket.connected()){
mSocket.connect(); mSocket.connect();
if (!OpenCVLoader.initDebug()) {
Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
} else {
Log.d("OpenCV", "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
} }
// if (!OpenCVLoader.initDebug()) {
// Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
// OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
// } else {
// Log.d("OpenCV", "OpenCV library found inside package. Using it!");
// mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
// }
} }
RecyclerView.OnItemTouchListener mOnItemTouchListener = new RecyclerView.OnItemTouchListener() { RecyclerView.OnItemTouchListener mOnItemTouchListener = new RecyclerView.OnItemTouchListener() {
...@@ -1467,7 +1568,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -1467,7 +1568,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
chatHistoryPostData.setAttachmentName("liveAgent.txt"); chatHistoryPostData.setAttachmentName("liveAgent.txt");
chatHistoryPostData.setAttachmentType("application/txt"); chatHistoryPostData.setAttachmentType("application/txt");
chatHistoryPostData.setAttachmentData(ChatHistorybase64); chatHistoryPostData.setAttachmentData(ChatHistorybase64);
userSysId = PrefManager.getSharedPref(ChatActivity.this, PrefManager.PREFERENCE_USER_SYS_ID);
accessToken = PrefManager.getSharedPref(ChatActivity.this, PrefManager.PREFERENCE_ACCESS_TOKEN); accessToken = PrefManager.getSharedPref(ChatActivity.this, PrefManager.PREFERENCE_ACCESS_TOKEN);
} }
......
...@@ -366,6 +366,27 @@ public class OtpValidationActivity extends Activity { ...@@ -366,6 +366,27 @@ public class OtpValidationActivity extends Activity {
String userId = mUserDetails.get(0).getUserId(); String userId = mUserDetails.get(0).getUserId();
String userEmailId = mUserDetails.get(0).getUserEmailId(); String userEmailId = mUserDetails.get(0).getUserEmailId();
if(Util.isChatItemEnabled()) {
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(sysid);
if (localChatBotUser == null) {
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager.deleteAllRows();
ChatBotUserManager.deleteAllRows();
/*Save Logged in user in local db for chat screen*/
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setUserSysId(sysid)
.setName(firstName)
.build();
ChatBotUserManager.save(chatBotUser);
} else {//Update the name of user
localChatBotUser.setName(firstName);
ChatBotUserManager.update(localChatBotUser);
}
}
/*End Chat Local DB Part*/ /*End Chat Local DB Part*/
...@@ -443,28 +464,8 @@ public class OtpValidationActivity extends Activity { ...@@ -443,28 +464,8 @@ public class OtpValidationActivity extends Activity {
if (syncStatus == SyncStatus.SUCCESS) { if (syncStatus == SyncStatus.SUCCESS) {
if(userSysId != null){ if(userSysId != null){
PrefManager.setSharedPref(OtpValidationActivity.this, PrefManager.PREFERENCE_USER_SYS_ID, userSysId); PrefManager.setSharedPref(OtpValidationActivity.this, PrefManager.PREFERENCE_DYNAMIC_USER_SYS_ID, userSysId);
if(Util.isChatItemEnabled()) {
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(userSysId);
if (localChatBotUser == null) {
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager.deleteAllRows();
ChatBotUserManager.deleteAllRows();
/*Save Logged in user in local db for chat screen*/
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setUserSysId(userSysId)
.setName(userFullName)
.build();
ChatBotUserManager.save(chatBotUser);
} else {//Update the name of user
localChatBotUser.setName(userFullName);
ChatBotUserManager.update(localChatBotUser);
}
}
/*Send broadcast to start SyncService*/ /*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT); Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC); intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
......
package com.vsoft.vera.utils;
public class ChatLog {
private Long chatId;
/**
* socket connection id
*/
private String socketConnId;
private String serverResponse;
private String timestamp;
/**
* socket connection status
* true or false
*/
private String connStatus;
private String clientMessage;
public String getSocketConnId() {
return socketConnId;
}
public void setSocketConnId(String socketConnId) {
this.socketConnId = socketConnId;
}
public Long getChatId() {
return chatId;
}
public void setChatId(Long chatId) {
this.chatId = chatId;
}
public String getClientMessage() {
return clientMessage;
}
public void setClientMessage(String clientMessage) {
this.clientMessage = clientMessage;
}
public String getServerResponse() {
return serverResponse;
}
public void setServerResponse(String serverResponse) {
this.serverResponse = serverResponse;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getConnStatus() {
return connStatus;
}
public void setConnStatus(String connStatus) {
this.connStatus = connStatus;
}
}
...@@ -11,7 +11,8 @@ import com.vsoft.vera.api.interfaces.PendingApprovalsApi; ...@@ -11,7 +11,8 @@ import com.vsoft.vera.api.interfaces.PendingApprovalsApi;
public class Constants { public class Constants {
public static final String TAG = AppConfig.APP_INTERNAL_NAME; public static final String TAG = AppConfig.APP_INTERNAL_NAME;
public static String TWILIO_COUNTRY_CODE;// = "+91"; //default set to us
public static String TWILIO_COUNTRY_CODE = "+1";
public static final String[] month = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; public static final String[] month = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/** /**
......
...@@ -11,6 +11,7 @@ public class PrefManager { ...@@ -11,6 +11,7 @@ public class PrefManager {
public static final String PREFERENCE_USER_FIRST_NAME = "firstName"; public static final String PREFERENCE_USER_FIRST_NAME = "firstName";
public static final String PREFERENCE_USER_LAST_NAME = "lastName"; public static final String PREFERENCE_USER_LAST_NAME = "lastName";
public static final String PREFERENCE_USER_SYS_ID = "sysId"; public static final String PREFERENCE_USER_SYS_ID = "sysId";
public static final String PREFERENCE_DYNAMIC_USER_SYS_ID = "dynamic_sysId";
public static final String PREFERENCE_USER_FULL_NAME = "full_name"; public static final String PREFERENCE_USER_FULL_NAME = "full_name";
public static final String PREFERENCE_USER_ID = "user_id"; public static final String PREFERENCE_USER_ID = "user_id";
public static final String PREFERENCE_USER_EMAIL_ID = "user_email_id"; public static final String PREFERENCE_USER_EMAIL_ID = "user_email_id";
......
...@@ -7,5 +7,9 @@ ...@@ -7,5 +7,9 @@
android:id="@+id/more_menu_clear" android:id="@+id/more_menu_clear"
android:icon="@drawable/ic_clear_black" android:icon="@drawable/ic_clear_black"
android:title="Clear Chat" /> android:title="Clear Chat" />
<item
android:id="@+id/export_log"
android:title="Export Log" />
</menu> </menu>
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"0.1.8","enabled":true,"outputFile":"app-vportal-staging.apk","fullName":"vportalStaging","baseName":"vportal-staging"},"path":"app-vportal-staging.apk","properties":{}}] [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"0.2.4","enabled":true,"outputFile":"app-vportal-staging.apk","fullName":"vportalStaging","baseName":"vportal-staging"},"path":"app-vportal-staging.apk","properties":{}}]
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment