Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
84d408af
authored
Oct 01, 2019
by
Chayaa852
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Socket related changes
parent
cb7cc48d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
52 deletions
app/build.gradle
app/src/main/java/com/vsoft/vera/CatalogueApplication.java
app/src/main/java/com/vsoft/vera/ui/ChatActivity.java
build.gradle
app/build.gradle
View file @
84d408af
...
...
@@ -56,7 +56,7 @@ android {
}
staging
{
//staging is the UAT environment
//applicationIdSuffix ".staging"
debuggable
fals
e
debuggable
tru
e
buildConfigField
"int"
,
"BUILD_TYPE_INT"
,
"3"
signingConfig
signingConfigs
.
debug
}
...
...
@@ -72,7 +72,7 @@ android {
vportal
{
applicationId
"com.vsoft.vera.vportal"
versionCode
1
versionName
"0.1.
5
"
versionName
"0.1.
6
"
}
}
}
...
...
@@ -108,7 +108,7 @@ dependencies {
transitive
=
true
;
}
implementation
'com.squareup.picasso:picasso:2.5.2'
implementation
'com.github.nkzawa:socket.io-client:0.
3
.0'
implementation
'com.github.nkzawa:socket.io-client:0.
6
.0'
implementation
'com.android.support:appcompat-v7:28.0.0'
implementation
'com.android.support:cardview-v7:28.0.0'
implementation
'com.android.support:recyclerview-v7:28.0.0'
...
...
app/src/main/java/com/vsoft/vera/CatalogueApplication.java
View file @
84d408af
...
...
@@ -150,10 +150,16 @@ public class CatalogueApplication extends MultiDexApplication {
IO
.
Options
options
=
new
IO
.
Options
();
options
.
forceNew
=
true
;
options
.
reconnection
=
true
;
options
.
reconnectionDelay
=
0
;
options
.
reconnectionAttempts
=
2000
;
options
.
transports
=
new
String
[]{
Polling
.
NAME
,
WebSocket
.
NAME
};
options
.
upgrade
=
true
;
mSocket
=
IO
.
socket
(
Constants
.
CHAT_SERVER_URL
,
options
);
mSocket
.
io
().
timeout
(-
1
);
mSocket
.
io
().
reconnection
(
true
);
mSocket
.
io
().
reconnectionDelay
(
0
);
mSocket
.
io
().
reconnectionAttempts
(
2000
);
}
catch
(
URISyntaxException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
app/src/main/java/com/vsoft/vera/ui/ChatActivity.java
View file @
84d408af
...
...
@@ -231,7 +231,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mSocket
.
on
(
Socket
.
EVENT_CONNECT
,
onConnect
);
mSocket
.
on
(
Socket
.
EVENT_DISCONNECT
,
onDisconnect
);
mSocket
.
on
(
Socket
.
EVENT_CONNECT_ERROR
,
onConnectError
);
mSocket
.
on
(
Socket
.
EVENT_CONNECT_TIMEOUT
,
onConnectError
);
mSocket
.
on
(
Socket
.
EVENT_CONNECT_TIMEOUT
,
onConnectTimeOut
);
mSocket
.
on
(
Socket
.
EVENT_RECONNECT
,
onReconnect
);
mSocket
.
on
(
NEW_MESSAGE
,
onNewMessage
);
mSocket
.
on
(
AUTHENTICATED
,
authenticated
);
mSocket
.
on
(
UNAUTHORIZED
,
unAuthorized
);
...
...
@@ -411,66 +412,64 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
String
getResults
()
{
try
{
if
(
checkDataBase
())
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
String
searchQuery
=
"SELECT * FROM "
+
TABLE_CHAT_BOT_HISTORY
;
Cursor
cursor
=
db
.
rawQuery
(
searchQuery
,
null
);
mLoggedInUsername
=
PrefManager
.
getSharedPref
(
this
,
PrefManager
.
PREFERENCE_USER_FIRST_NAME
);
try
{
if
(
checkDataBase
()
)
{
cursor
.
moveToFirst
();
while
(
cursor
.
isAfterLast
()
==
false
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
String
searchQuery
=
"SELECT * FROM "
+
TABLE_CHAT_BOT_HISTORY
;
Cursor
cursor
=
db
.
rawQuery
(
searchQuery
,
null
);
mLoggedInUsername
=
PrefManager
.
getSharedPref
(
this
,
PrefManager
.
PREFERENCE_USER_FIRST_NAME
);
int
totalColumn
=
cursor
.
getColumnCount
();
cursor
.
moveToFirst
();
while
(
cursor
.
isAfterLast
()
==
false
)
{
for
(
int
i
=
0
;
i
<
totalColumn
;
i
++)
{
if
(
cursor
.
getColumnName
(
i
)
!=
null
)
{
if
(
cursor
.
getColumnName
(
i
).
equals
(
DBConstants
.
CHAT_BOT_HISTORY_USER_ID
)
||
cursor
.
getColumnName
(
i
).
equals
(
DBConstants
.
CHAT_BOT_HISTORY_MESSAGE
)){
int
totalColumn
=
cursor
.
getColumnCount
();
try
{
if
(
cursor
.
getString
(
i
)
!=
null
)
{
String
userId
=
cursor
.
getColumnName
(
i
);
if
(
userId
.
equals
(
DBConstants
.
CHAT_BOT_HISTORY_USER_ID
))
{
String
userIdenty
=
cursor
.
getString
(
i
);
if
(
userIdenty
.
equals
(
"1"
))
{
chatHistroy
=
chatHistroy
+
mLoggedInUsername
+
" :"
;
}
else
{
chatHistroy
=
chatHistroy
+
"Bot "
+
":"
;
}
}
else
{
for
(
int
i
=
0
;
i
<
totalColumn
;
i
++)
{
if
(
cursor
.
getColumnName
(
i
)
!=
null
)
{
if
(
cursor
.
getColumnName
(
i
).
equals
(
DBConstants
.
CHAT_BOT_HISTORY_USER_ID
)
||
cursor
.
getColumnName
(
i
).
equals
(
DBConstants
.
CHAT_BOT_HISTORY_MESSAGE
)){
try
{
if
(
cursor
.
getString
(
i
)
!=
null
)
{
String
userId
=
cursor
.
getColumnName
(
i
);
if
(
userId
.
equals
(
DBConstants
.
CHAT_BOT_HISTORY_USER_ID
))
{
String
userIdenty
=
cursor
.
getString
(
i
);
if
(
userIdenty
.
equals
(
"1"
))
{
chatHistroy
=
chatHistroy
+
mLoggedInUsername
+
" :"
;
}
else
{
chatHistroy
=
chatHistroy
+
"Bot "
+
":"
;
}
}
else
{
String
sampleStr
=
Html
.
fromHtml
(
cursor
.
getString
(
i
)).
toString
();
chatHistroy
=
chatHistroy
+
sampleStr
+
"\n"
;
byte
[]
data
=
chatHistroy
.
getBytes
(
"UTF-8"
);
ChatHistorybase64
=
Base64
.
encodeToString
(
data
,
Base64
.
DEFAULT
);
}
String
sampleStr
=
Html
.
fromHtml
(
cursor
.
getString
(
i
)).
toString
();
chatHistroy
=
chatHistroy
+
sampleStr
+
"\n"
;
byte
[]
data
=
chatHistroy
.
getBytes
(
"UTF-8"
);
ChatHistorybase64
=
Base64
.
encodeToString
(
data
,
Base64
.
DEFAULT
);
}
}
}
catch
(
Exception
e
)
{
Log
.
d
(
"TAG_NAME"
,
e
.
getMessage
());
}
}
}
catch
(
Exception
e
)
{
Log
.
d
(
"TAG_NAME"
,
e
.
getMessage
());
}
}
cursor
.
moveToNext
();
}
cursor
.
close
();
Log
.
d
(
"TAG_NAME"
,
chatHistroy
);
}
else
{
Toast
.
makeText
(
ChatActivity
.
this
,
"Fail to get DB"
,
Toast
.
LENGTH_SHORT
).
show
();
}
cursor
.
moveToNext
();
}
cursor
.
close
();
Log
.
d
(
"TAG_NAME"
,
chatHistroy
);
}
else
{
Toast
.
makeText
(
ChatActivity
.
this
,
"Fail to get DB"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
catch
(
Exception
e
){
}
return
chatHistroy
;
}
public
void
clearChatAlertDialouge
()
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setMessage
(
R
.
string
.
home_screen_clear_chat_confirmation_msg_string
)
...
...
@@ -659,7 +658,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
String
message
=
mInputMessageView
.
getText
().
toString
().
trim
();
if
(!
TextUtils
.
isEmpty
(
message
)){
if
(
null
==
mLoggedInUsername
)
return
;
if
(!
mSocket
.
connected
())
return
;
if
(!
mSocket
.
connected
())
return
;
//Whenever we'll click on send button, running TTS speak should stop
if
(
speaker
!=
null
&&
speaker
.
isSpeaking
())
{
...
...
@@ -689,7 +689,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
mSocket
.
emit
(
NEW_MESSAGE
,
jsonObject
);
}
else
{
}
else
{
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.
...
...
@@ -732,7 +732,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
public
void
initChatMessage
(
String
message
)
{
//
textDotLoader.show();
//
textDotLoader.show();
if
(
message
.
contains
(
"stop"
)){
addMessage
(
mLoggedInUsername
,
message
,
""
);
...
...
@@ -776,6 +776,31 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
};
/**
* Chat server calls this if we will get connection time out in connection.
*/
private
Emitter
.
Listener
onConnectTimeOut
=
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
Toast
.
makeText
(
getApplicationContext
(),
"onConnectTimeOut Called"
,
Toast
.
LENGTH_LONG
).
show
();
//reconnect();
}
};
/**
* Chat server calls this if we will get reconnected.
*/
private
Emitter
.
Listener
onReconnect
=
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
Toast
.
makeText
(
getApplicationContext
(),
"Reconnection Called"
,
Toast
.
LENGTH_LONG
).
show
();
//reconnect();
}
};
/**
* Chat server calls this if we will get any error in connection.
*/
private
Emitter
.
Listener
onConnectError
=
new
Emitter
.
Listener
()
{
...
...
@@ -1187,7 +1212,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
public
void
onResume
()
{
super
.
onResume
();
mSocket
.
connect
();
if
(
mSocket
!=
null
&&
!
mSocket
.
connected
())
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
);
...
...
@@ -1196,6 +1222,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mLoaderCallback
.
onManagerConnected
(
LoaderCallbackInterface
.
SUCCESS
);
}
}
RecyclerView
.
OnItemTouchListener
mOnItemTouchListener
=
new
RecyclerView
.
OnItemTouchListener
()
{
@Override
public
boolean
onInterceptTouchEvent
(
RecyclerView
rv
,
MotionEvent
e
)
{
...
...
@@ -1301,7 +1328,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mSocket
.
off
(
Socket
.
EVENT_CONNECT
,
onConnect
);
mSocket
.
off
(
Socket
.
EVENT_DISCONNECT
,
onDisconnect
);
mSocket
.
off
(
Socket
.
EVENT_CONNECT_ERROR
,
onConnectError
);
mSocket
.
off
(
Socket
.
EVENT_CONNECT_TIMEOUT
,
onConnectError
);
mSocket
.
on
(
Socket
.
EVENT_CONNECT_TIMEOUT
,
onConnectTimeOut
);
mSocket
.
on
(
Socket
.
EVENT_RECONNECT
,
onReconnect
);
mSocket
.
off
(
NEW_MESSAGE
,
onNewMessage
);
mSocket
.
off
(
AUTHENTICATED
,
authenticated
);
mSocket
.
off
(
UNAUTHORIZED
,
unAuthorized
);
...
...
build.gradle
View file @
84d408af
...
...
@@ -8,7 +8,7 @@ buildscript {
maven
{
url
"https://jitpack.io"
}
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.
5.0
'
classpath
'com.android.tools.build:gradle:3.
4.2
'
classpath
'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath
'com.google.gms:google-services:4.2.0'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment