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
cfe3cf4f
authored
Apr 17, 2018
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added logout api.
parent
22845514
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
138 additions
and
10 deletions
app/src/main/java/com/vsoft/servicenow/api/interfaces/LoginApi.java
app/src/main/java/com/vsoft/servicenow/api/listeners/put/PutLogoutApiListener.java
app/src/main/java/com/vsoft/servicenow/api/managers/LoginApiManager.java
app/src/main/java/com/vsoft/servicenow/api/pojos/LoginApiResponse.java
app/src/main/java/com/vsoft/servicenow/ui/ChatActivity.java
app/src/main/java/com/vsoft/servicenow/ui/HomeScreen.java
app/src/main/java/com/vsoft/servicenow/utils/Constants.java
app/src/main/res/values/strings.xml
app/src/main/java/com/vsoft/servicenow/api/interfaces/LoginApi.java
View file @
cfe3cf4f
...
...
@@ -8,6 +8,8 @@ import retrofit2.Call;
import
retrofit2.http.Field
;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.POST
;
import
retrofit2.http.PUT
;
import
retrofit2.http.Query
;
/**
...
...
@@ -33,6 +35,9 @@ public interface LoginApi {
@Field
(
LoginApiResponse
.
Json
.
CLIENT_SECRET
)
String
clientSecret
,
@Field
(
LoginApiResponse
.
Json
.
REFRESH_TOKEN
)
String
refreshToken
);
@PUT
(
Constants
.
URL_PUT_LOGOUT
)
Call
<
ResponseBody
>
logout
(
@Query
(
LoginApiResponse
.
Json
.
JSON_SYS_ID
)
String
userSysId
);
}
app/src/main/java/com/vsoft/servicenow/api/listeners/put/PutLogoutApiListener.java
0 → 100644
View file @
cfe3cf4f
package
com
.
vsoft
.
servicenow
.
api
.
listeners
.
put
;
/**
* @since 1.0
* @author Kunj on 17/04/2018
*
*/
public
interface
PutLogoutApiListener
{
void
onDoneApiCall
();
void
onFailApiCall
();
}
app/src/main/java/com/vsoft/servicenow/api/managers/LoginApiManager.java
View file @
cfe3cf4f
...
...
@@ -3,6 +3,7 @@ package com.vsoft.servicenow.api.managers;
import
android.content.Context
;
import
android.content.Intent
;
import
android.support.v4.content.LocalBroadcastManager
;
import
android.util.Log
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
...
...
@@ -13,6 +14,7 @@ import com.google.gson.JsonParseException;
import
com.vsoft.servicenow.api.RestClient
;
import
com.vsoft.servicenow.api.interfaces.LoginApi
;
import
com.vsoft.servicenow.api.listeners.get.GetUserLoginApiListener
;
import
com.vsoft.servicenow.api.listeners.put.PutLogoutApiListener
;
import
com.vsoft.servicenow.api.pojos.LoginApiResponse
;
import
com.vsoft.servicenow.utils.Constants
;
import
com.vsoft.servicenow.enums.SyncStatus
;
...
...
@@ -55,7 +57,7 @@ public class LoginApiManager {
try
{
value
=
json
.
getAsLong
();
}
catch
(
NumberFormatException
e
)
{
CatalogueLog
.
d
(
"LoginApiManager:
getCatalogues
: deserialize: long.class: NumberFormatException: "
);
CatalogueLog
.
d
(
"LoginApiManager:
logout
: deserialize: long.class: NumberFormatException: "
);
}
return
value
;
}
...
...
@@ -147,4 +149,41 @@ public class LoginApiManager {
return
SyncStatus
.
FAIL
;
}
}
public
static
void
logout
(
Context
context
,
PutLogoutApiListener
listener
)
{
CatalogueLog
.
d
(
"LoginApiManager: logout"
);
String
accessToken
=
PrefManager
.
getSharedPref
(
context
,
PrefManager
.
PREFERENCE_ACCESS_TOKEN
);
String
userSysId
=
PrefManager
.
getSharedPref
(
context
,
PrefManager
.
PREFERENCE_USER_SYS_ID
);
if
(
accessToken
.
isEmpty
()
||
userSysId
.
isEmpty
())
{
listener
.
onFailApiCall
();
return
;
}
final
Retrofit
retrofit
=
RestClient
.
getInitializedRestAdapter
(
accessToken
);
Call
<
ResponseBody
>
call
=
retrofit
.
create
(
LoginApi
.
class
).
logout
(
userSysId
);
try
{
Response
<
ResponseBody
>
response
=
call
.
execute
();
if
(
response
.
isSuccessful
())
{
listener
.
onDoneApiCall
();
}
else
{
CatalogueLog
.
d
(
"LoginApiManager: logout: response is not success"
);
if
(
response
.
code
()
==
401
)
{
Log
.
d
(
Constants
.
TAG
,
"-- is 401, try refresh token..."
);
Log
.
d
(
Constants
.
TAG
,
"refresh token: "
+
PrefManager
.
getSharedPref
(
context
,
PrefManager
.
PREFERENCE_REFRESH_TOKEN
));
SyncStatus
status
=
LoginApiManager
.
refreshLogin
(
context
,
PrefManager
.
getSharedPref
(
context
,
PrefManager
.
PREFERENCE_REFRESH_TOKEN
));
if
(
status
==
SyncStatus
.
SUCCESS
)
{
CatalogueLog
.
d
(
"refresh token success, retry same..."
);
logout
(
context
,
listener
);
}
else
{
CatalogueLog
.
d
(
"refresh token failed, return FAIL"
);
}
}
else
{
listener
.
onFailApiCall
();
}
}
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"logout: IOException: "
,
e
);
listener
.
onFailApiCall
();
}
}
}
app/src/main/java/com/vsoft/servicenow/api/pojos/LoginApiResponse.java
View file @
cfe3cf4f
...
...
@@ -73,5 +73,6 @@ public class LoginApiResponse {
public
static
final
String
REFRESH_TOKEN
=
"refresh_token"
;
public
static
final
String
JSON_ACCESS_TOKEN
=
"access_token"
;
public
static
final
String
JSON_SYS_ID
=
"sys_id"
;
}
}
app/src/main/java/com/vsoft/servicenow/ui/ChatActivity.java
View file @
cfe3cf4f
...
...
@@ -38,6 +38,7 @@ import com.vsoft.servicenow.speechRecognizer.OnDSPermissionsListener;
import
com.vsoft.servicenow.utils.CatalogueLog
;
import
com.vsoft.servicenow.utils.Constants
;
import
com.vsoft.servicenow.utils.PrefManager
;
import
com.vsoft.servicenow.utils.Util
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -185,6 +186,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
mVoiceButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Util
.
hideSoftKeyboard
(
ChatActivity
.
this
,
v
);
if
(
null
==
mLoggedInUsername
)
return
;
if
(!
mSocket
.
connected
())
return
;
...
...
@@ -254,7 +257,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
addMessage
(
mLoggedInUsername
,
message
);
// perform the sending message attempt.
JSONObject
jsonObject
=
new
JSONObject
();
try
{
jsonObject
.
put
(
CLIENT_MESSAGE_KEY
,
message
);
...
...
@@ -262,7 +264,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
CatalogueLog
.
e
(
"jsonObject: "
+
jsonObject
);
mSocket
.
emit
(
NEW_MESSAGE
,
jsonObject
);
}
...
...
app/src/main/java/com/vsoft/servicenow/ui/HomeScreen.java
View file @
cfe3cf4f
package
com
.
vsoft
.
servicenow
.
ui
;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.support.v7.app.AlertDialog
;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
import
android.widget.GridView
;
import
com.google.android.gms.analytics.Tracker
;
...
...
@@ -12,10 +15,20 @@ import com.vsoft.servicenow.CatalogueApplication;
import
com.vsoft.servicenow.MenuProvider
;
import
com.vsoft.servicenow.R
;
import
com.vsoft.servicenow.adapters.HomeScreenAdapter
;
import
com.vsoft.servicenow.api.interfaces.LoginApi
;
import
com.vsoft.servicenow.api.listeners.get.GetCatalogueApiListener
;
import
com.vsoft.servicenow.api.listeners.put.PutLogoutApiListener
;
import
com.vsoft.servicenow.api.managers.CatalogueApiManager
;
import
com.vsoft.servicenow.api.managers.LoginApiManager
;
import
com.vsoft.servicenow.db.managers.CatalogueManager
;
import
com.vsoft.servicenow.db.models.Catalogue
;
import
com.vsoft.servicenow.enums.SyncStatus
;
import
com.vsoft.servicenow.menu.HomeScreenMenuItemData
;
import
com.vsoft.servicenow.utils.PrefManager
;
import
com.vsoft.servicenow.utils.Util
;
import
java.util.List
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.OnClick
;
...
...
@@ -25,8 +38,10 @@ import butterknife.OnItemClick;
* Created by Kunj on 11/8/16.
*/
public
class
HomeScreen
extends
HandleNotificationActivity
{
@BindView
(
R
.
id
.
tool_bar_view
)
Toolbar
mToolbar
;
@BindView
(
R
.
id
.
home_screen_grid_view
)
GridView
mGridView
;
@BindView
(
R
.
id
.
tool_bar_view
)
Toolbar
mToolbar
;
@BindView
(
R
.
id
.
home_screen_grid_view
)
GridView
mGridView
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -34,8 +49,6 @@ public class HomeScreen extends HandleNotificationActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
home_screen
);
CatalogueApplication
app
=
(
CatalogueApplication
)
getApplication
();
ButterKnife
.
bind
(
this
);
CatalogueApplication
application
=
(
CatalogueApplication
)
getApplication
();
...
...
@@ -62,6 +75,55 @@ public class HomeScreen extends HandleNotificationActivity {
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
ok_string
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
new
LogoutTask
().
execute
();
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
dialog
.
dismiss
();
}
});
AlertDialog
alert
=
builder
.
create
();
alert
.
show
();
}
class
LogoutTask
extends
AsyncTask
<
String
,
Void
,
SyncStatus
>
{
private
ProgressDialog
progressDialog
;
private
SyncStatus
syncStatus
=
SyncStatus
.
FAIL
;
@Override
protected
void
onPreExecute
()
{
super
.
onPreExecute
();
progressDialog
=
new
ProgressDialog
(
HomeScreen
.
this
);
progressDialog
.
setMessage
(
getString
(
R
.
string
.
loading_string
));
progressDialog
.
show
();
progressDialog
.
setCancelable
(
false
);
}
@Override
protected
SyncStatus
doInBackground
(
String
...
params
)
{
LoginApiManager
.
logout
(
HomeScreen
.
this
,
new
PutLogoutApiListener
()
{
@Override
public
void
onDoneApiCall
()
{
syncStatus
=
SyncStatus
.
SUCCESS
;
}
@Override
public
void
onFailApiCall
()
{
syncStatus
=
SyncStatus
.
FAIL
;
}
});
return
syncStatus
;
}
@Override
protected
void
onPostExecute
(
SyncStatus
syncStatus
)
{
super
.
onPostExecute
(
syncStatus
);
if
(
progressDialog
!=
null
&&
progressDialog
.
isShowing
())
{
progressDialog
.
dismiss
();
}
if
(
syncStatus
==
SyncStatus
.
SUCCESS
)
{
PrefManager
.
setSharedPref
(
HomeScreen
.
this
,
PrefManager
.
PREFERENCE_ACCESS_TOKEN
,
""
);
PrefManager
.
setSharedPref
(
HomeScreen
.
this
,
PrefManager
.
PREFERENCE_REFRESH_TOKEN
,
""
);
PrefManager
.
setSharedPref
(
HomeScreen
.
this
,
PrefManager
.
PREFERENCE_USER_LAST_NAME
,
""
);
...
...
@@ -73,11 +135,18 @@ public class HomeScreen extends HandleNotificationActivity {
Intent
loginIntent
=
new
Intent
(
HomeScreen
.
this
,
LoginScreen
.
class
);
loginIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
|
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
);
startActivity
(
loginIntent
);
}
else
{
showErrorDialog
(
R
.
string
.
failed_to_logout_string
);
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
new
DialogInterface
.
OnClickListener
()
{
}
}
private
void
showErrorDialog
(
int
message
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setMessage
(
message
)
.
setCancelable
(
false
)
.
setPositiveButton
(
android
.
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
dialog
.
dismiss
();
}
});
AlertDialog
alert
=
builder
.
create
();
...
...
app/src/main/java/com/vsoft/servicenow/utils/Constants.java
View file @
cfe3cf4f
...
...
@@ -150,6 +150,7 @@ public class Constants {
public
static
final
String
URL_REFRESH_LOGIN
=
URL_POST_LOGIN_ITEM
;
public
static
final
String
URL_PUT_DEVICE_REGISTERATION
=
"api/now/table/sys_user/{user_sys_id}"
;
public
static
final
String
URL_GET_USERDETAILS
=
API_PATH
+
"sys_user"
;
public
static
final
String
URL_PUT_LOGOUT
=
"/api/vsng2/uofl_mobile/logout"
;
/*Catalogue Category API */
public
static
final
String
URL_GET_CATALOGUE
=
DOMAIN
+
AppConfig
.
URL_GET_CATALOGUE
;
...
...
app/src/main/res/values/strings.xml
View file @
cfe3cf4f
...
...
@@ -39,6 +39,7 @@
<string
name=
"failed_to_fetch_user_detail_string"
>
Failed to fetch User Details.
</string>
<string
name=
"failed_to_fetch_hr_case_category_string"
>
Failed to fetch HR Case Category.
</string>
<string
name=
"failed_to_fetch_hr_case_items_category_string"
>
Failed to fetch HR Case Category Items.
</string>
<string
name=
"failed_to_logout_string"
>
Failed to logout.
</string>
<!--Login Screen-->
<string
name=
"prompt_relogin_login_expired"
>
Login expired, please login again
…
</string>
...
...
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