Commit a5ec3d51 by Kunj Gupta

Added Chatbot history in local DB.

parent b5528c19
Showing with 686 additions and 483 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'android-apt'
android {
signingConfigs {
config {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file('/home/chaukadev/.android/debug.keystore')
storePassword 'android'
}
}
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.vsoft.uoflservicenow"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "0.0.7"
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
buildConfigField "int", "BUILD_TYPE_INT", "1"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "BUILD_TYPE_INT", "2"
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'android-apt'
android {
signingConfigs {
config {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file('/home/chaukadev/.android/debug.keystore')
storePassword 'android'
}
}
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.vsoft.uoflservicenow"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "0.0.5"
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
buildConfigField "int", "BUILD_TYPE_INT", "1"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "BUILD_TYPE_INT", "2"
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'android-apt'
android {
signingConfigs {
config {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file('/home/chaukadev/.android/debug.keystore')
storePassword 'android'
}
}
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.vsoft.uoflservicenow"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "0.0.6"
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
buildConfigField "int", "BUILD_TYPE_INT", "1"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "BUILD_TYPE_INT", "2"
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'android-apt'
android {
signingConfigs {
config {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file('/home/chaukadev/.android/debug.keystore')
storePassword 'android'
}
}
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.vsoft.uoflservicenow"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "0.0.7"
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
buildConfigField "int", "BUILD_TYPE_INT", "1"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "BUILD_TYPE_INT", "2"
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
}
...@@ -39,9 +39,13 @@ public class AppConfig { ...@@ -39,9 +39,13 @@ public class AppConfig {
public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile";
/** /**
* Socket Chat server URLs * Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/
* test - http://111.93.6.218:12912/
* demo - http://111.93.6.218:12913/
* release - http://111.93.6.218:12914/
* */ * */
public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12914/";
public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12911/";
public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12913/";
} }
...@@ -39,9 +39,13 @@ public class AppConfig { ...@@ -39,9 +39,13 @@ public class AppConfig {
public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile";
/** /**
* Socket Chat server URLs * Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/
* test - http://111.93.6.218:12912/
* demo - http://111.93.6.218:12913/
* release - http://111.93.6.218:12914/
* */ * */
public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12914/";
public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12911/";
public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12913/";
} }
...@@ -39,9 +39,13 @@ public class AppConfig { ...@@ -39,9 +39,13 @@ public class AppConfig {
public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile";
/** /**
* Socket Chat server URLs * Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/
* test - http://111.93.6.218:12912/
* demo - http://111.93.6.218:12913/
* release - http://111.93.6.218:12914/
* */ * */
public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12914/";
public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12911/";
public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12913/";
} }
...@@ -59,13 +59,12 @@ public class CatalogueApplication extends Application { ...@@ -59,13 +59,12 @@ public class CatalogueApplication extends Application {
Toast.makeText(CatalogueApplication.this, R.string.prompt_relogin_login_expired, Toast.LENGTH_SHORT).show(); Toast.makeText(CatalogueApplication.this, R.string.prompt_relogin_login_expired, Toast.LENGTH_SHORT).show();
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_ACCESS_TOKEN, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_REFRESH_TOKEN, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_LAST_NAME, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_LAST_NAME, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_SYS_ID, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_SYS_ID, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_FIRST_NAME, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_FIRST_NAME, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_ID, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_ID, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_FULL_NAME, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_FULL_NAME, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_EMAIL_ID, ""); PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_EMAIL_ID, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_LOGIN_USER_NAME, "");
Intent loginIntent = new Intent(CatalogueApplication.this, LoginScreen.class); Intent loginIntent = new Intent(CatalogueApplication.this, LoginScreen.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent); startActivity(loginIntent);
......
...@@ -135,7 +135,6 @@ public class LoginApiManager { ...@@ -135,7 +135,6 @@ public class LoginApiManager {
CatalogueLog.d("---- 401, unSetting access and refresh token, prompt user to login again"); CatalogueLog.d("---- 401, unSetting access and refresh token, prompt user to login again");
PrefManager.setSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN, ""); PrefManager.setSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN, ""); PrefManager.setSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
PrefManager.setSharedPref(context, PrefManager.PREFERENCE_LOGIN_USER_NAME, "");
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_PROMPT_LOGIN); intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_PROMPT_LOGIN);
......
...@@ -9,7 +9,6 @@ public class Message { ...@@ -9,7 +9,6 @@ public class Message {
private int mType; private int mType;
private String mMessage; private String mMessage;
private String mUsername; private String mUsername;
private boolean mEnableSpeaker;
private Message() {} private Message() {}
...@@ -25,15 +24,10 @@ public class Message { ...@@ -25,15 +24,10 @@ public class Message {
return mUsername; return mUsername;
}; };
public boolean ismEnableSpeaker() {
return mEnableSpeaker;
}
public static class Builder { public static class Builder {
private final int mType; private final int mType;
private String mUsername; private String mUsername;
private String mMessage; private String mMessage;
private boolean mEnableSpeaker;
public Builder(int type) { public Builder(int type) {
mType = type; mType = type;
...@@ -49,17 +43,11 @@ public class Message { ...@@ -49,17 +43,11 @@ public class Message {
return this; return this;
} }
public Builder enableSpeaker(boolean enableSpeaker) {
mEnableSpeaker = enableSpeaker;
return this;
}
public Message build() { public Message build() {
Message message = new Message(); Message message = new Message();
message.mType = mType; message.mType = mType;
message.mUsername = mUsername; message.mUsername = mUsername;
message.mMessage = mMessage; message.mMessage = mMessage;
message.mEnableSpeaker = mEnableSpeaker;
return message; return message;
} }
} }
......
...@@ -2,21 +2,13 @@ package com.vsoft.servicenow.chat; ...@@ -2,21 +2,13 @@ package com.vsoft.servicenow.chat;
import android.content.Context; import android.content.Context;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.vsoft.servicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.ui.HomeScreen;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
...@@ -28,7 +20,6 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold ...@@ -28,7 +20,6 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
private List<Message> mMessages; private List<Message> mMessages;
private int[] mUsernameColors; private int[] mUsernameColors;
private Context mContext; private Context mContext;
private int type = -1;
public MessageAdapter(Context context, List<Message> messages) { public MessageAdapter(Context context, List<Message> messages) {
mMessages = messages; mMessages = messages;
...@@ -38,24 +29,9 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold ...@@ -38,24 +29,9 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
int layout = -1;
switch (viewType) {
case Message.TYPE_MESSAGE:
type = -1;
layout = R.layout.item_message;
break;
case Message.TYPE_LOG:
type = Message.TYPE_LOG;
layout = R.layout.item_log;
break;
case Message.TYPE_ACTION:
type = -1;
layout = R.layout.item_action;
break;
}
View v = LayoutInflater View v = LayoutInflater
.from(parent.getContext()) .from(parent.getContext())
.inflate(layout, parent, false); .inflate(R.layout.item_message, parent, false);
return new ViewHolder(v); return new ViewHolder(v);
} }
...@@ -81,8 +57,6 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold ...@@ -81,8 +57,6 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
public class ViewHolder extends RecyclerView.ViewHolder { public class ViewHolder extends RecyclerView.ViewHolder {
private TextView mUsernameView, mHrNameView; private TextView mUsernameView, mHrNameView;
private TextView mUserMessageView, mHRMessageView; private TextView mUserMessageView, mHRMessageView;
private TextView mTitleMessageTextView, mLogMessageTextView;
private TextView mNameItemActionTextView;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
...@@ -91,14 +65,11 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold ...@@ -91,14 +65,11 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
mHrNameView = (TextView) itemView.findViewById(R.id.hr_username); mHrNameView = (TextView) itemView.findViewById(R.id.hr_username);
mUserMessageView = (TextView) itemView.findViewById(R.id.user_message); mUserMessageView = (TextView) itemView.findViewById(R.id.user_message);
mHRMessageView = (TextView) itemView.findViewById(R.id.hr_message); mHRMessageView = (TextView) itemView.findViewById(R.id.hr_message);
mTitleMessageTextView = (TextView) itemView.findViewById(R.id.title_message);
mLogMessageTextView = (TextView) itemView.findViewById(R.id.log_message);
mNameItemActionTextView = (TextView) itemView.findViewById(R.id.item_action_username);
} }
public void setUsername(String username) { public void setUsername(String username) {
if(mUsernameView != null && mHrNameView != null) { if(mUsernameView != null && mHrNameView != null) {
if (username.equals(PrefManager.getSharedPref(mContext, PrefManager.PREFERENCE_FIRST_NAME))) { if (username.equals(PrefManager.getSharedPref(mContext, PrefManager.PREFERENCE_USER_FIRST_NAME))) {
mUsernameView.setVisibility(View.VISIBLE); mUsernameView.setVisibility(View.VISIBLE);
mHrNameView.setVisibility(View.GONE); mHrNameView.setVisibility(View.GONE);
mUsernameView.setText(username); mUsernameView.setText(username);
...@@ -109,16 +80,13 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold ...@@ -109,16 +80,13 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
mHrNameView.setText(username); mHrNameView.setText(username);
mHrNameView.setTextColor(getUsernameColor(username)); mHrNameView.setTextColor(getUsernameColor(username));
} }
} else if(mNameItemActionTextView != null) {
mNameItemActionTextView.setText(username);
} }
} }
public void setMessage(String userName, String message) { public void setMessage(String userName, String message) {
//if (null == mHRMessageView) return; if(userName != null) {
if(type == -1 && userName != null) {
if(mUserMessageView != null && mHRMessageView != null) { if(mUserMessageView != null && mHRMessageView != null) {
if (userName.equals(PrefManager.getSharedPref(mContext, PrefManager.PREFERENCE_FIRST_NAME))) { if (userName.equals(PrefManager.getSharedPref(mContext, PrefManager.PREFERENCE_USER_FIRST_NAME))) {
mUserMessageView.setVisibility(View.VISIBLE); mUserMessageView.setVisibility(View.VISIBLE);
mHRMessageView.setVisibility(View.GONE); mHRMessageView.setVisibility(View.GONE);
mUserMessageView.setMovementMethod(LinkMovementMethod.getInstance()); mUserMessageView.setMovementMethod(LinkMovementMethod.getInstance());
...@@ -130,16 +98,6 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold ...@@ -130,16 +98,6 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
mHRMessageView.setText(Util.fromHtml(message)); mHRMessageView.setText(Util.fromHtml(message));
} }
} }
} else if(type == Message.TYPE_LOG) {
if(message.contains(mContext.getString(R.string.message_welcome))) {
mTitleMessageTextView.setVisibility(View.VISIBLE);
mLogMessageTextView.setVisibility(View.GONE);
mTitleMessageTextView.setText(message);
} else {
mTitleMessageTextView.setVisibility(View.GONE);
mLogMessageTextView.setVisibility(View.VISIBLE);
mLogMessageTextView.setText(message);
}
} }
} }
......
package com.vsoft.servicenow.utils; package com.vsoft.servicenow.db;
public interface DBConstants { public interface DBConstants {
//Tables //Tables
...@@ -17,6 +17,8 @@ public interface DBConstants { ...@@ -17,6 +17,8 @@ public interface DBConstants {
String TABLE_CATALOGUE_ITEM_INPUT = "input_catalogue_item"; String TABLE_CATALOGUE_ITEM_INPUT = "input_catalogue_item";
String TABLE_ATTACHMENT = "attachment"; String TABLE_ATTACHMENT = "attachment";
String TABLE_NOTIFICATIONS = "notifications"; String TABLE_NOTIFICATIONS = "notifications";
String TABLE_CHAT_BOT_HISTORY = "chat_bot_history";
String TABLE_CHAT_BOT_USER = "chat_bot_user";
String ID = "_id"; String ID = "_id";
String SYS_ID = "sys_id"; String SYS_ID = "sys_id";
...@@ -366,4 +368,42 @@ public interface DBConstants { ...@@ -366,4 +368,42 @@ public interface DBConstants {
* NOTIFICATIONS_COLUMN_COUNT: Total column count for notification table. * NOTIFICATIONS_COLUMN_COUNT: Total column count for notification table.
*/ */
int NOTIFICATIONS_COLUMN_COUNT = 5; int NOTIFICATIONS_COLUMN_COUNT = 5;
/**
* ChatBot History table
*/
String CHAT_BOT_HISTORY_ID = ID;
String CHAT_BOT_HISTORY_USER_ID = "user_id";
String CHAT_BOT_HISTORY_MESSAGE = "message";
String CHAT_BOT_HISTORY_TIME_STAMP = "timestamp";
/**
* Chat table. *Use these only if you fetch all columns*
*/
int INDEX_CHAT_BOT_HISTORY_ID = 0;
int INDEX_CHAT_BOT_HISTORY_USER_ID = 1;
int INDEX_CHAT_BOT_HISTORY_MESSAGE = 2;
int INDEX_CHAT_BOT_HISTORY_TIME_STAMP = 3;
/**
* CHAT_BOT_HISTORY_COLUMN_COUNT: Total column count for chatbot table.
*/
int CHAT_BOT_HISTORY_COLUMN_COUNT = 4;
/**
* ChatBot User table
*/
String CHAT_BOT_USER_ID = ID;
String CHAT_BOT_USER_SYS_ID = "sys_id";
String CHAT_BOT_USER_NAME = "name";
/**
* Chat user table. *Use these only if you fetch all columns*
*/
int INDEX_CHAT_BOT_USER_ID = 0;
int INDEX_CHAT_BOT_USER_SYS_ID = 1;
int INDEX_CHAT_BOT_USER_NAME = 2;
/**
* CHAT_BOT_USER_COLUMN_COUNT: Total column count for chatbot user table.
*/
int CHAT_BOT_USER_COLUMN_COUNT = 3;
} }
\ No newline at end of file
...@@ -7,10 +7,8 @@ import android.database.sqlite.SQLiteOpenHelper; ...@@ -7,10 +7,8 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DBConstants;
import com.vsoft.servicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
/** /**
* *
* @author Kunj on 11-08-2016. * @author Kunj on 11-08-2016.
...@@ -46,6 +44,11 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -46,6 +44,11 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
if(Util.isNotificationsItemEnabled()) { if(Util.isNotificationsItemEnabled()) {
createNotificationsTable(db); createNotificationsTable(db);
} }
if(Util.isChatItemEnabled()) {
createChatBotTable(db);
createChatBotUserTable(db);
}
} }
@Override @Override
...@@ -215,4 +218,21 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -215,4 +218,21 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ NOTIFICATIONS_CREATED_BY + " text" + NOTIFICATIONS_CREATED_BY + " text"
+ ");"); + ");");
} }
private void createChatBotTable(SQLiteDatabase db) {
db.execSQL("create table IF NOT EXISTS " + TABLE_CHAT_BOT_HISTORY + "("
+ CHAT_BOT_HISTORY_ID + " integer primary key autoincrement, "
+ CHAT_BOT_HISTORY_USER_ID + " integer, "
+ CHAT_BOT_HISTORY_MESSAGE + " text, "
+ CHAT_BOT_HISTORY_TIME_STAMP + " real"
+ ");");
}
private void createChatBotUserTable(SQLiteDatabase db) {
db.execSQL("create table IF NOT EXISTS " + TABLE_CHAT_BOT_USER + "("
+ CHAT_BOT_USER_ID + " integer primary key autoincrement, "
+ CHAT_BOT_USER_SYS_ID + " integer, "
+ CHAT_BOT_USER_NAME + " text"
+ ");");
}
} }
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Attachment; import com.vsoft.servicenow.db.models.Attachment;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.CatalogueItemInput; import com.vsoft.servicenow.db.models.CatalogueItemInput;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -8,7 +8,7 @@ import com.vsoft.servicenow.CatalogueApplication; ...@@ -8,7 +8,7 @@ import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.enums.ViewType; import com.vsoft.servicenow.enums.ViewType;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.ChatBotHistory;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 05-04-2018.
*/
public class ChatBotHistoryManager implements DBConstants {
public static long save(ChatBotHistory chatBotHistory) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
long id = db.insert(TABLE_CHAT_BOT_HISTORY, null, getContentValues(chatBotHistory));
chatBotHistory.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(ChatBotHistory chatBotHistory) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_CHAT_BOT_HISTORY, CHAT_BOT_HISTORY_ID + "=" + chatBotHistory.getId(), null);
}
return -1;
}
public static int update(ChatBotHistory chatBotHistory) {
return update(chatBotHistory, null);
}
public static int update(ChatBotHistory chatBotHistory, List<String> column) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (column == null || column.size() == 0) {
return db.update(TABLE_CHAT_BOT_HISTORY, getContentValues(chatBotHistory), CHAT_BOT_HISTORY_ID + "=" + chatBotHistory.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (CHAT_BOT_HISTORY_USER_ID.equals(columnName)) {
contentValues.put(CHAT_BOT_HISTORY_USER_ID, chatBotHistory.getUserId());
} else if (CHAT_BOT_HISTORY_MESSAGE.equals(columnName)) {
contentValues.put(CHAT_BOT_HISTORY_MESSAGE, chatBotHistory.getMessage());
} else if (CHAT_BOT_HISTORY_TIME_STAMP.equals(columnName)) {
contentValues.put(CHAT_BOT_HISTORY_TIME_STAMP, chatBotHistory.getTimestamp());
}
}
return db.update(TABLE_CHAT_BOT_HISTORY, contentValues, CHAT_BOT_HISTORY_ID + "=" + chatBotHistory.getId(), null);
}
} else {
return -1;
}
}
public static List<ChatBotHistory> getAllChatBotHistory() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
String queryString = "select * from " + TABLE_CHAT_BOT_HISTORY
+ " left join " + TABLE_CHAT_BOT_USER
+ " on " + TABLE_CHAT_BOT_HISTORY + "." + CHAT_BOT_HISTORY_USER_ID + "=" +
TABLE_CHAT_BOT_USER + "." + CHAT_BOT_USER_ID
+ " order by " + TABLE_CHAT_BOT_HISTORY + "." + CHAT_BOT_HISTORY_TIME_STAMP + " ASC";
Cursor c = db.rawQuery(queryString, null);
ArrayList<ChatBotHistory> chatBotHistoryList;
if (c.getCount() > 0) {
chatBotHistoryList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
ChatBotHistory.ChatBotBuilder builder = ChatBotHistory.ChatBotBuilder.aChatBotHistory();
fillAllChatBotHistoryDetails(c, builder);
ChatBotHistory chatBotHistory = builder.build();
chatBotHistory.setUserName(c.getString(c.getColumnIndex(CHAT_BOT_USER_NAME)));
chatBotHistoryList.add(chatBotHistory);
}
} else {
chatBotHistoryList = new ArrayList<>(0);
}
c.close();
return chatBotHistoryList;
} else {
return new ArrayList<>(0);
}
}
public static int deleteAllRows() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_CHAT_BOT_HISTORY, null, null);
}
return -1;
}
private static void fillAllChatBotHistoryDetails(Cursor c, ChatBotHistory.ChatBotBuilder builder) {
builder.setId(c.getLong(INDEX_CHAT_BOT_HISTORY_ID));
builder.setUserId(c.getInt(INDEX_CHAT_BOT_HISTORY_USER_ID));
builder.setMessage(c.getString(INDEX_CHAT_BOT_HISTORY_MESSAGE));
builder.setTimestamp(c.getLong(INDEX_CHAT_BOT_HISTORY_TIME_STAMP));
}
private static ContentValues getContentValues(ChatBotHistory chatBotHistory) {
ContentValues cv = new ContentValues(CHAT_BOT_HISTORY_COLUMN_COUNT - 1);
cv.put(CHAT_BOT_HISTORY_USER_ID, chatBotHistory.getUserId());
cv.put(CHAT_BOT_HISTORY_MESSAGE, chatBotHistory.getMessage());
cv.put(CHAT_BOT_HISTORY_TIME_STAMP, chatBotHistory.getTimestamp());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.ChatBotUser;
import java.util.List;
/**
*
* @author Kunj on 05-04-2018.
*/
public class ChatBotUserManager implements DBConstants {
public static long save(ChatBotUser chatBotUser) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
long id = db.insert(TABLE_CHAT_BOT_USER, null, getContentValues(chatBotUser));
chatBotUser.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(ChatBotUser chatBotUser) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_CHAT_BOT_USER, CHAT_BOT_USER_ID + "=" + chatBotUser.getId(), null);
}
return -1;
}
public static int update(ChatBotUser chatBotUser) {
return update(chatBotUser, null);
}
public static int update(ChatBotUser chatBotUser, List<String> column) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (column == null || column.size() == 0) {
return db.update(TABLE_CHAT_BOT_USER, getContentValues(chatBotUser), CHAT_BOT_USER_ID + "=" + chatBotUser.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (CHAT_BOT_USER_SYS_ID.equals(columnName)) {
contentValues.put(CHAT_BOT_USER_SYS_ID, chatBotUser.getUserSysId());
} else if (CHAT_BOT_USER_NAME.equals(columnName)) {
contentValues.put(CHAT_BOT_USER_NAME, chatBotUser.getName());
}
}
return db.update(TABLE_CHAT_BOT_USER, contentValues, CHAT_BOT_USER_ID + "=" + chatBotUser.getId(), null);
}
} else {
return -1;
}
}
public static ChatBotUser getChatBotUsersByUserSysId(String userSysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
ChatBotUser chatBotUser = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CHAT_BOT_USER
+ " where " + CHAT_BOT_USER_SYS_ID + "='" + userSysId + "'" , null);
if (c.moveToFirst()) {
ChatBotUser.ChatBotUserBuilder builder = ChatBotUser.ChatBotUserBuilder.aChatBotUser();
fillAllChatBotUserDetails(c, builder);
chatBotUser = builder.build();
}
c.close();
}
return chatBotUser;
}
public static ChatBotUser getChatBotUsersByName(String userName) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
ChatBotUser chatBotUser = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CHAT_BOT_USER
+ " where " + CHAT_BOT_USER_NAME + "='" + userName + "'" , null);
if (c.moveToFirst()) {
ChatBotUser.ChatBotUserBuilder builder = ChatBotUser.ChatBotUserBuilder.aChatBotUser();
fillAllChatBotUserDetails(c, builder);
chatBotUser = builder.build();
}
c.close();
}
return chatBotUser;
}
public static long getChatBotUsersLocalId(String userSysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
long localId = -1;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CHAT_BOT_USER
+ " where " + CHAT_BOT_USER_SYS_ID + "='" + userSysId + "'" , null);
if (c.moveToFirst()) {
localId = c.getLong(INDEX_CHAT_BOT_USER_ID);
}
c.close();
}
return localId;
}
public static int deleteAllRows() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_CHAT_BOT_USER, null, null);
}
return -1;
}
private static void fillAllChatBotUserDetails(Cursor c, ChatBotUser.ChatBotUserBuilder builder) {
builder.setId(c.getLong(INDEX_CHAT_BOT_USER_ID));
builder.setUserSysId(c.getString(INDEX_CHAT_BOT_USER_SYS_ID));
builder.setName(c.getString(INDEX_CHAT_BOT_USER_NAME));
}
private static ContentValues getContentValues(ChatBotUser chatBotUser) {
ContentValues cv = new ContentValues(CHAT_BOT_USER_COLUMN_COUNT - 1);
cv.put(CHAT_BOT_USER_SYS_ID, chatBotUser.getUserSysId());
cv.put(CHAT_BOT_USER_NAME, chatBotUser.getName());
return cv;
}
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.servicenow.enums.Impact; import com.vsoft.servicenow.enums.Impact;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.MyRequestDisplayValue; import com.vsoft.servicenow.db.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.List; import java.util.List;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.MyRequestDisplayValue; import com.vsoft.servicenow.db.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.List; import java.util.List;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.MyRequestDisplayValue; import com.vsoft.servicenow.db.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.List; import java.util.List;
......
...@@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.MyRequest; import com.vsoft.servicenow.db.models.MyRequest;
import com.vsoft.servicenow.db.models.MyRequestDisplayValue; import com.vsoft.servicenow.db.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -5,10 +5,9 @@ import android.database.Cursor; ...@@ -5,10 +5,9 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.db.models.Notifications; import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.servicenow.enums.Impact; import com.vsoft.servicenow.enums.Impact;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.UiPolicyAction; import com.vsoft.servicenow.db.models.UiPolicyAction;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.UiPolicyItem; import com.vsoft.servicenow.db.models.UiPolicyItem;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.VariableChoice; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.servicenow.db.models;
/**
* Created by chaukadev on 4/5/18.
*/
public class ChatBotHistory {
private long id = -1;
private long userId;
private String message;
private long timestamp;
private String userName;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public static final class ChatBotBuilder {
private long id = -1;
private long userId;
private String message;
private long timestamp;
private ChatBotBuilder() {
}
public static ChatBotBuilder aChatBotHistory() {
return new ChatBotBuilder();
}
public ChatBotBuilder setId(long val) {
id = val;
return this;
}
public ChatBotBuilder setUserId(long val) {
userId = val;
return this;
}
public ChatBotBuilder setMessage(String val) {
message = val;
return this;
}
public ChatBotBuilder setTimestamp(long val) {
timestamp = val;
return this;
}
public ChatBotBuilder but() {
return aChatBotHistory().setId(id).setUserId(userId).setMessage(message).setTimestamp(timestamp);
}
public ChatBotHistory build() {
ChatBotHistory chatBotHistory = new ChatBotHistory();
chatBotHistory.setId(id);
chatBotHistory.setUserId(userId);
chatBotHistory.setMessage(message);
chatBotHistory.setTimestamp(timestamp);
return chatBotHistory;
}
}
@Override
public String toString() {
return "ChatBotHistory{" +
"id=" + id +
", userId=" + userId +
", message='" + message + '\'' +
", timestamp=" + timestamp +
'}';
}
}
package com.vsoft.servicenow.db.models;
/**
* Created by chaukadev on 4/5/18.
*/
public class ChatBotUser {
public static final String CHAT_BOT_SYS_ID = "0";
private long id = -1;
private String userSysId;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getUserSysId() {
return userSysId;
}
public void setUserSysId(String userSysId) {
this.userSysId = userSysId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static final class ChatBotUserBuilder {
private long id = -1;
private String userSysId;
private String name;
private ChatBotUserBuilder() {
}
public static ChatBotUserBuilder aChatBotUser() {
return new ChatBotUserBuilder();
}
public ChatBotUserBuilder setId(long val) {
id = val;
return this;
}
public ChatBotUserBuilder setUserSysId(String val) {
userSysId = val;
return this;
}
public ChatBotUserBuilder setName(String val) {
name = val;
return this;
}
public ChatBotUserBuilder but() {
return aChatBotUser().setId(id).setUserSysId(userSysId).setName(name);
}
public ChatBotUser build() {
ChatBotUser chatBotUser = new ChatBotUser();
chatBotUser.setId(id);
chatBotUser.setUserSysId(userSysId);
chatBotUser.setName(name);
return chatBotUser;
}
}
@Override
public String toString() {
return "ChatBotUser{" +
"id=" + id +
", userSysId='" + userSysId + '\'' +
", name='" + name + '\'' +
'}';
}
}
...@@ -2,12 +2,10 @@ package com.vsoft.servicenow.service; ...@@ -2,12 +2,10 @@ package com.vsoft.servicenow.service;
import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService; import com.google.firebase.iid.FirebaseInstanceIdService;
import com.google.gson.JsonObject;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.api.interfaces.UserApi; import com.vsoft.servicenow.api.interfaces.UserApi;
import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener; import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.servicenow.api.managers.UserApiManager; import com.vsoft.servicenow.api.managers.UserApiManager;
import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
...@@ -36,7 +34,7 @@ public class NotificationInstanceIdService extends FirebaseInstanceIdService { ...@@ -36,7 +34,7 @@ public class NotificationInstanceIdService extends FirebaseInstanceIdService {
} }
private void sendRegistrationToServer(String refreshedToken) { private void sendRegistrationToServer(String refreshedToken) {
String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_SYS_ID); String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_USER_SYS_ID);
if (userSysId == null || userSysId.isEmpty()) { if (userSysId == null || userSysId.isEmpty()) {
CatalogueLog.e("NotificationInstanceIdService: sendRegistrationToServer: userSysId is null."); CatalogueLog.e("NotificationInstanceIdService: sendRegistrationToServer: userSysId is null.");
return; return;
......
...@@ -46,7 +46,7 @@ public class NotificationMessagingService extends FirebaseMessagingService { ...@@ -46,7 +46,7 @@ public class NotificationMessagingService extends FirebaseMessagingService {
@Override @Override
public void onMessageReceived(RemoteMessage remoteMessage) { public void onMessageReceived(RemoteMessage remoteMessage) {
String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_SYS_ID); String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_USER_SYS_ID);
if (userSysId != null && !userSysId.isEmpty()) { if (userSysId != null && !userSysId.isEmpty()) {
Map<String, String> dataMap = remoteMessage.getData(); Map<String, String> dataMap = remoteMessage.getData();
String title = dataMap.get(FCM_KEY_TITLE); String title = dataMap.get(FCM_KEY_TITLE);
......
...@@ -20,7 +20,7 @@ import com.vsoft.servicenow.db.models.Incident; ...@@ -20,7 +20,7 @@ import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.servicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException; import org.json.JSONException;
...@@ -38,9 +38,9 @@ import okhttp3.MediaType; ...@@ -38,9 +38,9 @@ import okhttp3.MediaType;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import static com.vsoft.servicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput; import static com.vsoft.servicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput;
import static com.vsoft.servicenow.utils.DBConstants.CATALOGUE_ITEM_INPUT_SYS_ID; import static com.vsoft.servicenow.db.DBConstants.CATALOGUE_ITEM_INPUT_SYS_ID;
import static com.vsoft.servicenow.utils.DBConstants.INCIDENT_INPUT_NUMBER; import static com.vsoft.servicenow.db.DBConstants.INCIDENT_INPUT_NUMBER;
import static com.vsoft.servicenow.utils.DBConstants.SYNC_FLAG_NONE; import static com.vsoft.servicenow.db.DBConstants.SYNC_FLAG_NONE;
/** /**
...@@ -173,7 +173,7 @@ public class SyncService extends IntentService { ...@@ -173,7 +173,7 @@ public class SyncService extends IntentService {
**/ **/
private SyncStatus syncIncidentForm(final Incident incident) { private SyncStatus syncIncidentForm(final Incident incident) {
CatalogueLog.d( "syncVariableForm"); CatalogueLog.d( "syncVariableForm");
String userSysId = PrefManager.getSharedPref(SyncService.this, PrefManager.PREFERENCE_SYS_ID); String userSysId = PrefManager.getSharedPref(SyncService.this, PrefManager.PREFERENCE_USER_SYS_ID);
if(incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) { if(incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) {
JSONObject incidentJsonObject = new JSONObject(); JSONObject incidentJsonObject = new JSONObject();
try { try {
......
...@@ -26,7 +26,6 @@ import android.support.v4.content.ContextCompat; ...@@ -26,7 +26,6 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -83,7 +82,7 @@ import com.vsoft.servicenow.listeners.ReferenceListener; ...@@ -83,7 +82,7 @@ import com.vsoft.servicenow.listeners.ReferenceListener;
import com.vsoft.servicenow.ui.supportviews.DateAndTimePickerFragment; import com.vsoft.servicenow.ui.supportviews.DateAndTimePickerFragment;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.servicenow.utils.PartialCondition; import com.vsoft.servicenow.utils.PartialCondition;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
......
...@@ -28,6 +28,10 @@ import com.vsoft.servicenow.api.managers.LoginApiManager; ...@@ -28,6 +28,10 @@ import com.vsoft.servicenow.api.managers.LoginApiManager;
import com.vsoft.servicenow.chat.Message; import com.vsoft.servicenow.chat.Message;
import com.vsoft.servicenow.chat.MessageAdapter; import com.vsoft.servicenow.chat.MessageAdapter;
import com.vsoft.servicenow.chat.Speaker; import com.vsoft.servicenow.chat.Speaker;
import com.vsoft.servicenow.db.managers.ChatBotHistoryManager;
import com.vsoft.servicenow.db.managers.ChatBotUserManager;
import com.vsoft.servicenow.db.models.ChatBotHistory;
import com.vsoft.servicenow.db.models.ChatBotUser;
import com.vsoft.servicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.speechRecognizer.DroidSpeech; import com.vsoft.servicenow.speechRecognizer.DroidSpeech;
import com.vsoft.servicenow.speechRecognizer.OnDSListener; import com.vsoft.servicenow.speechRecognizer.OnDSListener;
...@@ -58,16 +62,14 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -58,16 +62,14 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private static String NEW_MESSAGE_USER_NAME = "username"; private static String NEW_MESSAGE_USER_NAME = "username";
private static String NEW_MESSAGE_MESSAGE = "message"; private static String NEW_MESSAGE_MESSAGE = "message";
private static final int REQUEST_LOGIN = 0;
private static final int TYPING_TIMER_LENGTH = 600;
private static final int CHECK_CODE = 102; private static final int CHECK_CODE = 102;
private RecyclerView mMessagesView; private RecyclerView mMessagesView;
private EditText mInputMessageView; private EditText mInputMessageView;
private List<Message> mMessages = new ArrayList<>(); private List<Message> mMessages = new ArrayList<>();
private RecyclerView.Adapter mAdapter; private RecyclerView.Adapter mAdapter;
private String mUsername; private String mLoggedInUsername;
private String mLoggedInUserSysId;
private Socket mSocket; private Socket mSocket;
private Speaker speaker; private Speaker speaker;
...@@ -95,6 +97,9 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -95,6 +97,9 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
setContentView(R.layout.chat_activity); setContentView(R.layout.chat_activity);
mLoggedInUserSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_SYS_ID);
mLoggedInUsername = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_FIRST_NAME);
Toolbar mToolbar = findViewById(R.id.tool_bar_view); Toolbar mToolbar = findViewById(R.id.tool_bar_view);
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
...@@ -106,6 +111,13 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -106,6 +111,13 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(true);
} }
List<ChatBotHistory> chatBotHistoryList = ChatBotHistoryManager.getAllChatBotHistory();
for (int i = 0; i < chatBotHistoryList.size(); i++) {
ChatBotHistory chatBotHistory = chatBotHistoryList.get(i);
mMessages.add(new Message.Builder(Message.TYPE_MESSAGE)
.username(chatBotHistory.getUserName()).message(chatBotHistory.getMessage()).build());
}
mAdapter = new MessageAdapter(this, mMessages); mAdapter = new MessageAdapter(this, mMessages);
CatalogueApplication app = (CatalogueApplication) getApplication(); CatalogueApplication app = (CatalogueApplication) getApplication();
...@@ -128,8 +140,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -128,8 +140,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
mMessagesView.setLayoutManager(new LinearLayoutManager(this)); mMessagesView.setLayoutManager(new LinearLayoutManager(this));
mMessagesView.setAdapter(mAdapter); mMessagesView.setAdapter(mAdapter);
mUsername = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_FIRST_NAME);
mInputMessageView = (EditText) findViewById(R.id.message_input); mInputMessageView = (EditText) findViewById(R.id.message_input);
mInputMessageView.setOnEditorActionListener(new TextView.OnEditorActionListener() { mInputMessageView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override @Override
...@@ -163,7 +173,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -163,7 +173,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
mVoiceButton.setOnClickListener(new View.OnClickListener() { mVoiceButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (null == mUsername) return; if (null == mLoggedInUsername) return;
if (!mSocket.connected()) return; if (!mSocket.connected()) return;
if(speaker != null && speaker.isSpeaking()) { if(speaker != null && speaker.isSpeaking()) {
...@@ -183,8 +193,22 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -183,8 +193,22 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private void addMessage(String username, String message) { private void addMessage(String username, String message) {
if(username.isEmpty() || message.isEmpty()) if(username.isEmpty() || message.isEmpty())
return; return;
if(CURRENT_STATE == VOICE_STATE && !username.equals(PrefManager.getSharedPref(this, PrefManager.PREFERENCE_FIRST_NAME))) {
long userLocalId;
if(username.equals(mLoggedInUsername)) {
userLocalId = ChatBotUserManager.getChatBotUsersLocalId(mLoggedInUserSysId);
} else {
userLocalId = ChatBotUserManager.getChatBotUsersLocalId(ChatBotUser.CHAT_BOT_SYS_ID);
}
ChatBotHistory chatBotHistory = ChatBotHistory.ChatBotBuilder.aChatBotHistory()
.setMessage(message)
.setUserId(userLocalId)
.setTimestamp(System.currentTimeMillis()).build();
ChatBotHistoryManager.save(chatBotHistory);
if(CURRENT_STATE == VOICE_STATE && !username.equals(mLoggedInUsername)) {
if(droidSpeech != null) { if(droidSpeech != null) {
CatalogueLog.i("addMessage: close droid speech");
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
speaker.allow(true); speaker.allow(true);
...@@ -201,7 +225,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -201,7 +225,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
* This method calls when we will send message to server. * This method calls when we will send message to server.
*/ */
private void attemptSend() { private void attemptSend() {
if (null == mUsername) return; if (null == mLoggedInUsername) return;
if (!mSocket.connected()) 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
...@@ -216,7 +240,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -216,7 +240,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
} }
mInputMessageView.setText(""); mInputMessageView.setText("");
addMessage(mUsername, message); addMessage(mLoggedInUsername, message);
// perform the sending message attempt. // perform the sending message attempt.
mSocket.emit(NEW_MESSAGE, message); mSocket.emit(NEW_MESSAGE, message);
...@@ -296,6 +320,15 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -296,6 +320,15 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
return; return;
} }
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByName(username);
if(localChatBotUser == null) {
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setName(username)
.setUserSysId(ChatBotUser.CHAT_BOT_SYS_ID)
.build();
ChatBotUserManager.save(chatBotUser);
}
addMessage(username, message); addMessage(username, message);
} }
}); });
...@@ -313,8 +346,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -313,8 +346,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
@Override @Override
public void run() { public void run() {
if (!isConnected) { if (!isConnected) {
if (null != mUsername) if (null != mLoggedInUsername)
mSocket.emit(ADD_USER, mUsername); mSocket.emit(ADD_USER, mLoggedInUsername);
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
R.string.connect, Toast.LENGTH_LONG).show(); R.string.connect, Toast.LENGTH_LONG).show();
isConnected = true; isConnected = true;
...@@ -364,7 +397,13 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -364,7 +397,13 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
//sending token to server //sending token to server
String accessToken = PrefManager.getSharedPref(ChatActivity.this, PrefManager.PREFERENCE_ACCESS_TOKEN); String accessToken = PrefManager.getSharedPref(ChatActivity.this, PrefManager.PREFERENCE_ACCESS_TOKEN);
CatalogueLog.e("Access Token "+accessToken); CatalogueLog.e("Access Token "+accessToken);
String loginUserName = PrefManager.getSharedPref(ChatActivity.this, PrefManager.PREFERENCE_LOGIN_USER_NAME);
String loginUserName = null;
ChatBotUser chatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(mLoggedInUserSysId);
if(chatBotUser != null) {
loginUserName = chatBotUser.getName();
}
if(!TextUtils.isEmpty(accessToken) && !TextUtils.isEmpty(loginUserName)) { if(!TextUtils.isEmpty(accessToken) && !TextUtils.isEmpty(loginUserName)) {
String userDetailURL = Constants.CHAT_USER_API_URL + "?" + Constants.URL_PARAM_SYSPRM_USERNAME + "=" + loginUserName; String userDetailURL = Constants.CHAT_USER_API_URL + "?" + Constants.URL_PARAM_SYSPRM_USERNAME + "=" + loginUserName;
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -394,6 +433,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -394,6 +433,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() { speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override @Override
public void onDone(String utteranceId) { public void onDone(String utteranceId) {
CatalogueLog.i("onActivityResult: Speaking done: isSpeaking: "+speaker.isSpeaking()+", droidSpeech: "+droidSpeech);
if (!speaker.isSpeaking() && droidSpeech != null) { if (!speaker.isSpeaking() && droidSpeech != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
...@@ -412,6 +452,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -412,6 +452,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
@Override @Override
public void onStart(String utteranceId) { public void onStart(String utteranceId) {
if (droidSpeech != null) { if (droidSpeech != null) {
CatalogueLog.i("onActivityResult: close droid speech");
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
} }
...@@ -456,6 +497,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -456,6 +497,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
speaker.stop(); speaker.stop();
} }
if(droidSpeech != null) { if(droidSpeech != null) {
CatalogueLog.i("onPause: close droid speech");
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
CURRENT_STATE = NONE; CURRENT_STATE = NONE;
......
...@@ -64,9 +64,9 @@ public class HomeScreen extends HandleNotificationActivity { ...@@ -64,9 +64,9 @@ public class HomeScreen extends HandleNotificationActivity {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_LAST_NAME, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_LAST_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_SYS_ID, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_SYS_ID, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_FIRST_NAME, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_FIRST_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_ID, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_ID, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, ""); PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, "");
......
...@@ -21,6 +21,9 @@ import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener; ...@@ -21,6 +21,9 @@ import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.servicenow.api.managers.LoginApiManager; import com.vsoft.servicenow.api.managers.LoginApiManager;
import com.vsoft.servicenow.api.managers.UserApiManager; import com.vsoft.servicenow.api.managers.UserApiManager;
import com.vsoft.servicenow.api.pojos.LoginApiResponse; import com.vsoft.servicenow.api.pojos.LoginApiResponse;
import com.vsoft.servicenow.db.managers.ChatBotHistoryManager;
import com.vsoft.servicenow.db.managers.ChatBotUserManager;
import com.vsoft.servicenow.db.models.ChatBotUser;
import com.vsoft.servicenow.db.models.UserApiValues; import com.vsoft.servicenow.db.models.UserApiValues;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.DialogUtils;
...@@ -83,7 +86,7 @@ public class LoginScreen extends Activity { ...@@ -83,7 +86,7 @@ public class LoginScreen extends Activity {
} }
private void CheckLoginValues() { private void CheckLoginValues() {
String sysId = PrefManager.getSharedPref(LoginScreen.this, PrefManager.PREFERENCE_SYS_ID); String sysId = PrefManager.getSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_SYS_ID);
if (!TextUtils.isEmpty(sysId)) { if (!TextUtils.isEmpty(sysId)) {
/*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);
...@@ -142,13 +145,13 @@ public class LoginScreen extends Activity { ...@@ -142,13 +145,13 @@ public class LoginScreen extends Activity {
.LOGIN_CLIENT_SECRET, userName, password, new GetUserLoginApiListener() { .LOGIN_CLIENT_SECRET, userName, password, new GetUserLoginApiListener() {
@Override @Override
public void onDoneApiCall(LoginApiResponse loginApiResponse) { public void onDoneApiCall(LoginApiResponse loginApiResponse) {
apiStatus = API_SUCCESS_USER_LOGIN;
publishProgress(USER_DETAIL);
/*Save access token in Preference*/ /*Save access token in Preference*/
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, loginApiResponse.getAccessToken()); PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, loginApiResponse.getAccessToken());
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, loginApiResponse.getRefreshToken()); PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, loginApiResponse.getRefreshToken());
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_LOGIN_USER_NAME, userName);
apiStatus = API_SUCCESS_USER_LOGIN;
publishProgress(USER_DETAIL);
UserApiManager.getUserDetailResponse(LoginScreen.this, userName, new GetUserDetailApiListener() { UserApiManager.getUserDetailResponse(LoginScreen.this, userName, new GetUserDetailApiListener() {
@Override @Override
public void onDoneApiCall(List<UserApiValues> userValues) { public void onDoneApiCall(List<UserApiValues> userValues) {
...@@ -208,10 +211,30 @@ public class LoginScreen extends Activity { ...@@ -208,10 +211,30 @@ public class LoginScreen 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();
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_FIRST_NAME, firstName); /*Start Chat Local DB Part*/
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_LAST_NAME, lastName); //Here we'll save logged in user detail in local DB for chat history.
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_SYS_ID, sysid); ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(sysid);
/*For prefill value in variable form*/ 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*/
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_FIRST_NAME, firstName);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_LAST_NAME, lastName);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_SYS_ID, sysid);
/*For pre fill value in variable form*/
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, userFullName); PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, userFullName);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_ID, userId); PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_ID, userId);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, userEmailId); PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, userEmailId);
......
...@@ -6,7 +6,6 @@ import android.os.Bundle; ...@@ -6,7 +6,6 @@ import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Editable; import android.text.Editable;
import android.text.Html; import android.text.Html;
...@@ -26,7 +25,7 @@ import com.vsoft.servicenow.db.managers.ReportIncidentValueManager; ...@@ -26,7 +25,7 @@ import com.vsoft.servicenow.db.managers.ReportIncidentValueManager;
import com.vsoft.servicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.servicenow.enums.Impact; import com.vsoft.servicenow.enums.Impact;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
...@@ -129,7 +128,7 @@ public class ReportIncidentScreen extends HandleNotificationActivity { ...@@ -129,7 +128,7 @@ public class ReportIncidentScreen extends HandleNotificationActivity {
void submitOnClicked(View view) { void submitOnClicked(View view) {
Util.hideSoftKeyboard(ReportIncidentScreen.this, view); Util.hideSoftKeyboard(ReportIncidentScreen.this, view);
if (!hasValidateForm()) { if (!hasValidateForm()) {
String userSysId = PrefManager.getSharedPref(ReportIncidentScreen.this, PrefManager.PREFERENCE_SYS_ID); String userSysId = PrefManager.getSharedPref(ReportIncidentScreen.this, PrefManager.PREFERENCE_USER_SYS_ID);
if(userSysId != null && !userSysId.isEmpty()) { if(userSysId != null && !userSysId.isEmpty()) {
Util.createDynamicTableForIncidentFormValues(); Util.createDynamicTableForIncidentFormValues();
Incident incident = Incident.IncidentBuilder.anIncident() Incident incident = Incident.IncidentBuilder.anIncident()
......
...@@ -9,6 +9,12 @@ import android.util.Log; ...@@ -9,6 +9,12 @@ import android.util.Log;
*/ */
public class CatalogueLog { public class CatalogueLog {
public static void i(String msg) {
if (CatalogueBuildConfig.DEBUG) {
Log.i(Constants.TAG, msg);
}
}
public static void d(String msg) { public static void d(String msg) {
if (CatalogueBuildConfig.DEBUG) { if (CatalogueBuildConfig.DEBUG) {
Log.d(Constants.TAG, msg); Log.d(Constants.TAG, msg);
......
...@@ -7,21 +7,17 @@ import android.content.SharedPreferences; ...@@ -7,21 +7,17 @@ import android.content.SharedPreferences;
* Created by krishna on 08-31-2016. * Created by krishna on 08-31-2016.
*/ */
public class PrefManager { public class PrefManager {
//Login Preferences //Login Preferences
public static final String PREFERENCE_USER_VALUES_KEY = "UserPrefs"; public static final String PREFERENCE_USER_FIRST_NAME = "firstName";
public static final String PREFERENCE_FIRST_NAME = "firstName"; public static final String PREFERENCE_USER_LAST_NAME = "lastName";
public static final String PREFERENCE_LAST_NAME = "lastName"; public static final String PREFERENCE_USER_SYS_ID = "sysId";
public static final String PREFERENCE_SYS_ID = "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";
/*Access Token */ /*Access Token */
public static final String PREFERENCE_LOGIN_VALUES_KEY = "LoginPrefs";
public static final String PREFERENCE_ACCESS_TOKEN = "access_token"; public static final String PREFERENCE_ACCESS_TOKEN = "access_token";
public static final String PREFERENCE_REFRESH_TOKEN = "refresh_token"; public static final String PREFERENCE_REFRESH_TOKEN = "refresh_token";
public static final String PREFERENCE_LOGIN_USER_NAME = "login_user_name";
private static final String SHARED_PREFERENCE_NAME = PrefManager.class.getSimpleName(); private static final String SHARED_PREFERENCE_NAME = PrefManager.class.getSimpleName();
......
...@@ -32,6 +32,7 @@ import com.google.android.gms.analytics.Tracker; ...@@ -32,6 +32,7 @@ import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.MenuProvider; import com.vsoft.servicenow.MenuProvider;
import com.vsoft.servicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.db.models.Reference; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.servicenow.db.models.VariableChoice; import com.vsoft.servicenow.db.models.VariableChoice;
......
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="@dimen/spacing">
<TextView
android:id="@+id/item_action_username"
style="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"/>
<TextView
android:id="@+id/action"
style="?android:textAppearanceMedium"
android:textColor="?android:textColorSecondary"
android:text="@string/user_action_typing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spacing"
android:paddingRight="@dimen/spacing"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/log_message"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:visibility="gone"
android:paddingTop="@dimen/spacing"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/title_message"
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:paddingTop="@dimen/spacing"
android:paddingBottom="@dimen/spacing"
android:background="@color/colorPrimaryDark"
android:textColor="@android:color/white" />
</LinearLayout>
...@@ -39,9 +39,13 @@ public class AppConfig { ...@@ -39,9 +39,13 @@ public class AppConfig {
public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile";
/** /**
* Socket Chat server URLs * Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/
* test - http://111.93.6.218:12912/
* demo - http://111.93.6.218:12913/
* release - http://111.93.6.218:12914/
* */ * */
public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12914/";
public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12911/";
public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12913/";
} }
...@@ -41,9 +41,13 @@ public class AppConfig { ...@@ -41,9 +41,13 @@ public class AppConfig {
public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/uofl_mobile";
/** /**
* Socket Chat server URLs * Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/
* test - http://111.93.6.218:12912/
* demo - http://111.93.6.218:12913/
* release - http://111.93.6.218:12914/
* */ * */
public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_RELEASE = "http://111.93.6.218:12914/";
public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_DEBUG = "http://111.93.6.218:12911/";
public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12910/"; public static final String CHAT_SERVER_URL_STAGING = "http://111.93.6.218:12913/";
} }
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