logout issue reslove

parent 0b9ca7bc
...@@ -72,7 +72,7 @@ android { ...@@ -72,7 +72,7 @@ android {
vportal { vportal {
applicationId "com.vsoft.vera.vportal" applicationId "com.vsoft.vera.vportal"
versionCode 1 versionCode 1
versionName "0.1.4" versionName "0.1.5"
} }
} }
} }
......
...@@ -83,6 +83,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -83,6 +83,7 @@ public class ADALActivity extends AppCompatActivity {
private static final int API_SUCCESS_USER_DETAIL = 3; private static final int API_SUCCESS_USER_DETAIL = 3;
private static final int API_FAIL_USER_DETAIL = 4; private static final int API_FAIL_USER_DETAIL = 4;
private List<UserApiValues> mUserDetails; private List<UserApiValues> mUserDetails;
private ProgressDialog mProgressDlg;
/* Azure AD Constants */ /* Azure AD Constants */
/* Authority is in the form of https://login.microsoftonline.com/yourtenant.onmicrosoft.com */ /* Authority is in the form of https://login.microsoftonline.com/yourtenant.onmicrosoft.com */
...@@ -140,6 +141,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -140,6 +141,7 @@ public class ADALActivity extends AppCompatActivity {
setContentView(R.layout.adal_main); setContentView(R.layout.adal_main);
mainLayt = (LinearLayout) findViewById(R.id.activity_main); mainLayt = (LinearLayout) findViewById(R.id.activity_main);
logo_banner = findViewById(R.id.logo_banner);
Glide.with(this).load(R.drawable.fulton_bg).into(new SimpleTarget<Drawable>() { Glide.with(this).load(R.drawable.fulton_bg).into(new SimpleTarget<Drawable>() {
@Override @Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
...@@ -162,14 +164,16 @@ public class ADALActivity extends AppCompatActivity { ...@@ -162,14 +164,16 @@ public class ADALActivity extends AppCompatActivity {
callGraphButton = (Button) findViewById(R.id.callGraph); callGraphButton = (Button) findViewById(R.id.callGraph);
signOutButton = (Button) findViewById(R.id.clearCache); signOutButton = (Button) findViewById(R.id.clearCache);
login_with_otp = (Button) findViewById(R.id.login_with_otp); login_with_otp = (Button) findViewById(R.id.login_with_otp);
logo_banner = findViewById(R.id.logo_banner);
callGraphButton.setOnClickListener(new View.OnClickListener() { callGraphButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
if (NetworkConnectivity.haveNetworkConnection(ADALActivity.this)) { if (NetworkConnectivity.haveNetworkConnection(ADALActivity.this)) {
onCallGraphClicked(); onCallGraphClicked();
} else { } else {
DialogUtils.showNoConnectionDialog(ADALActivity .this); DialogUtils.showNoConnectionDialog(ADALActivity .this);
} }
...@@ -275,6 +279,12 @@ public class ADALActivity extends AppCompatActivity { ...@@ -275,6 +279,12 @@ public class ADALActivity extends AppCompatActivity {
} }
private void callGraphAPI() { private void callGraphAPI() {
mProgressDlg = new ProgressDialog(ADALActivity.this);
mProgressDlg.setMessage(getString(R.string.loading_string));
mProgressDlg.show();
mProgressDlg.setCancelable(false);
Log.d(TAG, "Starting volley request to graph"); Log.d(TAG, "Starting volley request to graph");
/* Make sure we have a token to send to graph */ /* Make sure we have a token to send to graph */
...@@ -292,6 +302,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -292,6 +302,7 @@ public class ADALActivity extends AppCompatActivity {
parameters,new Response.Listener<JSONObject>() { parameters,new Response.Listener<JSONObject>() {
@Override @Override
public void onResponse(JSONObject response) { public void onResponse(JSONObject response) {
mProgressDlg.dismiss();
/* Successfully called graph, process data and send to UI */ /* Successfully called graph, process data and send to UI */
Log.d(TAG, "Response: " + response.toString()); Log.d(TAG, "Response: " + response.toString());
JSONObject root = null; JSONObject root = null;
...@@ -315,6 +326,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -315,6 +326,7 @@ public class ADALActivity extends AppCompatActivity {
}, new Response.ErrorListener() { }, new Response.ErrorListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
mProgressDlg.dismiss();
Log.d(TAG, "Error: " + error.toString()); Log.d(TAG, "Error: " + error.toString());
} }
}) { }) {
...@@ -361,10 +373,8 @@ public class ADALActivity extends AppCompatActivity { ...@@ -361,10 +373,8 @@ public class ADALActivity extends AppCompatActivity {
private void updateSuccessUI() { private void updateSuccessUI() {
// Called on success from /me endpoint // Called on success from /me endpoint
// Removed call Graph API button and paint Sign out // Removed call Graph API button and paint Sign out
callGraphButton.setVisibility(View.GONE);
signOutButton.setVisibility(View.GONE); signOutButton.setVisibility(View.GONE);
login_with_otp.setVisibility(View.GONE);
logo_banner.setVisibility(View.GONE);
findViewById(R.id.welcome).setVisibility(View.GONE); findViewById(R.id.welcome).setVisibility(View.GONE);
((TextView) findViewById(R.id.welcome)).setText("Welcome, " + ((TextView) findViewById(R.id.welcome)).setText("Welcome, " +
mAuthResult.getUserInfo().getGivenName()); mAuthResult.getUserInfo().getGivenName());
...@@ -412,10 +422,9 @@ public class ADALActivity extends AppCompatActivity { ...@@ -412,10 +422,9 @@ public class ADALActivity extends AppCompatActivity {
} }
/* Successfully got a token, call graph now */ /* Successfully got a token, call graph now */
Log.d(TAG, "Successfully authenticated"); Log.d(TAG, "Successfully authenticated");
callGraphButton.setVisibility(View.GONE);
signOutButton.setVisibility(View.GONE);
login_with_otp.setVisibility(View.GONE);
logo_banner.setVisibility(View.GONE);
/* Store the mAuthResult */ /* Store the mAuthResult */
mAuthResult = authenticationResult; mAuthResult = authenticationResult;
......
...@@ -11,8 +11,10 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -11,8 +11,10 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
...@@ -43,9 +45,12 @@ import android.view.inputmethod.EditorInfo; ...@@ -43,9 +45,12 @@ import android.view.inputmethod.EditorInfo;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.github.nkzawa.emitter.Emitter; import com.github.nkzawa.emitter.Emitter;
import com.github.nkzawa.socketio.client.Socket; import com.github.nkzawa.socketio.client.Socket;
import com.vsoft.vera.CatalogueApplication; import com.vsoft.vera.CatalogueApplication;
...@@ -174,6 +179,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -174,6 +179,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private static final String HTTPS = "https://"; private static final String HTTPS = "https://";
private static final String HTTP = "http://"; private static final String HTTP = "http://";
private LinearLayout mainLayt;
@Override @Override
...@@ -181,6 +187,15 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -181,6 +187,15 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.chat_activity); setContentView(R.layout.chat_activity);
mainLayt = (LinearLayout) findViewById(R.id.chat_activity_main);
Glide.with(this).load(R.drawable.chat_back_bg).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mainLayt.setBackground(resource);
}
}
});
mLoggedInUserSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_SYS_ID); mLoggedInUserSysId = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_SYS_ID);
mLoggedInUsername = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_FIRST_NAME); mLoggedInUsername = PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_FIRST_NAME);
......
...@@ -2,19 +2,25 @@ package com.vsoft.vera.ui; ...@@ -2,19 +2,25 @@ package com.vsoft.vera.ui;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.android.volley.DefaultRetryPolicy; import com.android.volley.DefaultRetryPolicy;
...@@ -24,6 +30,9 @@ import com.android.volley.Response; ...@@ -24,6 +30,9 @@ import com.android.volley.Response;
import com.android.volley.VolleyError; import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley; import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.microsoft.aad.adal.ADALError; import com.microsoft.aad.adal.ADALError;
import com.microsoft.aad.adal.AuthenticationCallback; import com.microsoft.aad.adal.AuthenticationCallback;
import com.microsoft.aad.adal.AuthenticationContext; import com.microsoft.aad.adal.AuthenticationContext;
...@@ -35,7 +44,22 @@ import com.microsoft.aad.adal.PromptBehavior; ...@@ -35,7 +44,22 @@ import com.microsoft.aad.adal.PromptBehavior;
import com.microsoft.aad.adal.Telemetry; import com.microsoft.aad.adal.Telemetry;
import com.vsoft.vera.CatalogueApplication; import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.R; import com.vsoft.vera.R;
import com.vsoft.vera.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.vera.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.vera.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.vera.api.managers.LoginApiManager;
import com.vsoft.vera.api.managers.UserApiManager;
import com.vsoft.vera.api.pojos.LoginApiResponse;
import com.vsoft.vera.db.managers.ChatBotHistoryManager;
import com.vsoft.vera.db.managers.ChatBotUserManager;
import com.vsoft.vera.db.models.ChatBotUser;
import com.vsoft.vera.db.models.UserApiValues; import com.vsoft.vera.db.models.UserApiValues;
import com.vsoft.vera.utils.Constants;
import com.vsoft.vera.utils.DialogUtils;
import com.vsoft.vera.utils.GenerateRandomString;
import com.vsoft.vera.utils.NetworkConnectivity;
import com.vsoft.vera.utils.PrefManager;
import com.vsoft.vera.utils.Util;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -51,10 +75,17 @@ import butterknife.OnClick; ...@@ -51,10 +75,17 @@ import butterknife.OnClick;
public class LoginChooseActivity extends Activity { public class LoginChooseActivity extends Activity {
TextView loginSSO,loginOTP;
/* UI & Debugging Variables */ /* UI & Debugging Variables */
private static final String TAG = ADALActivity.class.getSimpleName(); private static final String TAG = ADALActivity.class.getSimpleName();
private static final int API_SUCCESS_USER_LOGIN = 1;
private static final int API_FAIL_USER_LOGIN = 2;
private static final int API_SUCCESS_USER_DETAIL = 3;
private static final int API_FAIL_USER_DETAIL = 4;
private List<UserApiValues> mUserDetails;
private ProgressDialog mProgressDlg;
/* Azure AD Constants */ /* Azure AD Constants */
/* Authority is in the form of https://login.microsoftonline.com/yourtenant.onmicrosoft.com */ /* Authority is in the form of https://login.microsoftonline.com/yourtenant.onmicrosoft.com */
private static final String AUTHORITY = "https://login.microsoftonline.com/common"; private static final String AUTHORITY = "https://login.microsoftonline.com/common";
...@@ -69,7 +100,7 @@ public class LoginChooseActivity extends Activity { ...@@ -69,7 +100,7 @@ public class LoginChooseActivity extends Activity {
private final static String MSGRAPH_URL = "https://graph.microsoft.com/v1.0/me"; private final static String MSGRAPH_URL = "https://graph.microsoft.com/v1.0/me";
/* Azure AD Variables */ /* Azure AD Variables */
private AuthenticationContext mAuthContext; private AuthenticationContext mAuthContext;
private AuthenticationResult mAuthResult; private AuthenticationResult mAuthResult;
/* Handler to do an interactive sign in and acquire token */ /* Handler to do an interactive sign in and acquire token */
...@@ -84,9 +115,13 @@ public class LoginChooseActivity extends Activity { ...@@ -84,9 +115,13 @@ public class LoginChooseActivity extends Activity {
/* Constant to store user id in shared preferences */ /* Constant to store user id in shared preferences */
private static final String USER_ID = "user_id"; private static final String USER_ID = "user_id";
private boolean isLogin= false;
private boolean sspLogin= false;
/* Telemetry variables */ /* Telemetry variables */
// Flag to turn event aggregation on/off // Flag to turn event aggregation on/off
private static final boolean sTelemetryAggregationIsRequired = true; private static final boolean sTelemetryAggregationIsRequired = true;
private LinearLayout mainLayt;
/* Telemetry dispatcher registration */ /* Telemetry dispatcher registration */
static { static {
...@@ -102,32 +137,23 @@ public class LoginChooseActivity extends Activity { ...@@ -102,32 +137,23 @@ public class LoginChooseActivity extends Activity {
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
loginSSO = findViewById(R.id.login_with_sso); mainLayt = (LinearLayout) findViewById(R.id.activity_main_login);
loginOTP = findViewById(R.id.login_with_otp); Glide.with(this).load(R.drawable.fulton_bg).into(new SimpleTarget<Drawable>() {
loginSSO.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
// Intent intent = new Intent(LoginChooseActivity.this,ADALActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
// startActivity(intent); mainLayt.setBackground(resource);
}
onCallGraphClicked();
} }
}); });
loginOTP.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
// callGraphButton = (Button) findViewById(R.id.callGraph);
// signOutButton = (Button) findViewById(R.id.clearCache);
...@@ -141,7 +167,7 @@ public class LoginChooseActivity extends Activity { ...@@ -141,7 +167,7 @@ public class LoginChooseActivity extends Activity {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
if( sIntSignInInvoked.compareAndSet(false, true)) { if( sIntSignInInvoked.compareAndSet(false, true)) {
if (msg.what == MSG_INTERACTIVE_SIGN_IN_PROMPT_AUTO){ if (msg.what == MSG_INTERACTIVE_SIGN_IN_PROMPT_AUTO){
mAuthContext.acquireToken(getActivity(), RESOURCE_ID, CLIENT_ID, REDIRECT_URI, PromptBehavior.Auto, getAuthInteractiveCallback()); mAuthContext.acquireToken(getActivity(), RESOURCE_ID, CLIENT_ID, REDIRECT_URI, PromptBehavior.Always, getAuthInteractiveCallback());
}else if(msg.what == MSG_INTERACTIVE_SIGN_IN_PROMPT_ALWAYS){ }else if(msg.what == MSG_INTERACTIVE_SIGN_IN_PROMPT_ALWAYS){
mAuthContext.acquireToken(getActivity(), RESOURCE_ID, CLIENT_ID, REDIRECT_URI, PromptBehavior.Always, getAuthInteractiveCallback()); mAuthContext.acquireToken(getActivity(), RESOURCE_ID, CLIENT_ID, REDIRECT_URI, PromptBehavior.Always, getAuthInteractiveCallback());
} }
...@@ -164,9 +190,68 @@ public class LoginChooseActivity extends Activity { ...@@ -164,9 +190,68 @@ public class LoginChooseActivity extends Activity {
String userId = preferences.getString(USER_ID, ""); String userId = preferences.getString(USER_ID, "");
if(!TextUtils.isEmpty(userId)){ if(!TextUtils.isEmpty(userId)){
mAuthContext.acquireTokenSilentAsync(RESOURCE_ID, CLIENT_ID, userId, getAuthSilentCallback()); mAuthContext.acquireTokenSilentAsync(RESOURCE_ID, CLIENT_ID, userId, getAuthSilentCallback());
}else {
mAuthContext.getCache().removeAll();
}
CheckLoginValues();
}
private void CheckLoginValues() {
String sysId = PrefManager.getSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_SYS_ID);
if (!TextUtils.isEmpty(sysId)) {
/*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(LoginChooseActivity.this).sendBroadcast(intent);
Bundle bundle = getIntent().getExtras();
if(bundle != null) {
int requestCode = bundle.getInt(Constants.DATA_KEY_LOGIN_REQUEST_CODE);
if (requestCode == Constants.LOGIN_SCREEN_REQUEST_CODE) {
setResult(Constants.LOGIN_SCREEN_REQUEST_CODE, new Intent());
} else {
startActivity(new Intent(LoginChooseActivity.this, HomeScreen.class));
}
} else {
startActivity(new Intent(LoginChooseActivity.this, HomeScreen.class));
}
isLogin = true;
finish();
}else {
if (NetworkConnectivity.haveNetworkConnection(LoginChooseActivity.this)) {
onCallGraphClicked();
} else {
DialogUtils.showNoConnectionDialog(LoginChooseActivity .this);
}
} }
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
} }
//
// Core Auth methods used by ADAL
// ==================================
// onActivityResult() - handles redirect from System browser
// onCallGraphClicked() - attempts to get tokens for graph, if it succeeds calls graph & updates UI
// callGraphAPI() - called on successful token acquisition which makes an HTTP request to graph
// onSignOutClicked() - Signs user out of the app & updates UI
//
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mAuthContext.onActivityResult(requestCode, resultCode, data);
}
/* /*
* End user clicked call Graph API button, time for Auth * End user clicked call Graph API button, time for Auth
* Use ADAL to get an Access token for the Microsoft Graph API * Use ADAL to get an Access token for the Microsoft Graph API
...@@ -176,6 +261,12 @@ public class LoginChooseActivity extends Activity { ...@@ -176,6 +261,12 @@ public class LoginChooseActivity extends Activity {
} }
private void callGraphAPI() { private void callGraphAPI() {
mProgressDlg = new ProgressDialog(LoginChooseActivity.this);
mProgressDlg.setMessage(getString(R.string.loading_string));
mProgressDlg.show();
mProgressDlg.setCancelable(false);
Log.d(TAG, "Starting volley request to graph"); Log.d(TAG, "Starting volley request to graph");
/* Make sure we have a token to send to graph */ /* Make sure we have a token to send to graph */
...@@ -189,28 +280,35 @@ public class LoginChooseActivity extends Activity { ...@@ -189,28 +280,35 @@ public class LoginChooseActivity extends Activity {
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, "Failed to put parameters: " + e.toString()); Log.d(TAG, "Failed to put parameters: " + e.toString());
} }
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, MSGRAPH_URL, final JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, MSGRAPH_URL,
parameters,new Response.Listener<JSONObject>() { parameters,new Response.Listener<JSONObject>() {
@Override @Override
public void onResponse(JSONObject response) { public void onResponse(JSONObject response) {
mProgressDlg.dismiss();
/* Successfully called graph, process data and send to UI */ /* Successfully called graph, process data and send to UI */
Log.d(TAG, "Response: " + response.toString()); Log.d(TAG, "Response: " + response.toString());
updateGraphUI(response);
JSONObject root = null; JSONObject root = null;
try { try {
root = new JSONObject(response.toString()); root = new JSONObject(response.toString());
String userLoginName = root.getString("givenName"); String userLoginName = root.getString("givenName");
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_FULL_NAME, userLoginName);
/*Send broadcast to start SyncService*/
if(!isLogin){
new LoginDetailsSendToServer().execute();
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
// updateGraphUI(response);
} }
}, new Response.ErrorListener() { }, new Response.ErrorListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
mProgressDlg.dismiss();
Log.d(TAG, "Error: " + error.toString()); Log.d(TAG, "Error: " + error.toString());
} }
}) { }) {
...@@ -230,12 +328,12 @@ public class LoginChooseActivity extends Activity { ...@@ -230,12 +328,12 @@ public class LoginChooseActivity extends Activity {
queue.add(request); queue.add(request);
} }
private void onSignOutClicked() { private void onSignOutClicked() {
// End user has clicked the Sign Out button // End user has clicked the Sign Out button
// Kill the token cache // Kill the token cache
// Optionally call the signout endpoint to fully sign out the user account // Optionally call the signout endpoint to fully sign out the user account
mAuthContext.getCache().removeAll(); mAuthContext.getCache().removeAll();
updateSignedOutUI(); // updateSignedOutUI();
} }
// //
...@@ -249,12 +347,16 @@ public class LoginChooseActivity extends Activity { ...@@ -249,12 +347,16 @@ public class LoginChooseActivity extends Activity {
private void updateGraphUI(JSONObject response) { private void updateGraphUI(JSONObject response) {
// Called on success from /me endpoint // Called on success from /me endpoint
// Writes graph data to the UI // Writes graph data to the UI
// TextView graphText = (TextView) findViewById(R.id.graphData); TextView graphText = (TextView) findViewById(R.id.graphData);
// graphText.setText(response.toString()); graphText.setText(response.toString());
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private void updateSuccessUI() { private void updateSuccessUI() {
// Called on success from /me endpoint
// Removed call Graph API button and paint Sign out
} }
...@@ -262,6 +364,7 @@ public class LoginChooseActivity extends Activity { ...@@ -262,6 +364,7 @@ public class LoginChooseActivity extends Activity {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private void updateSignedOutUI() { private void updateSignedOutUI() {
} }
// //
...@@ -293,8 +396,12 @@ public class LoginChooseActivity extends Activity { ...@@ -293,8 +396,12 @@ public class LoginChooseActivity extends Activity {
} }
/* Successfully got a token, call graph now */ /* Successfully got a token, call graph now */
Log.d(TAG, "Successfully authenticated"); Log.d(TAG, "Successfully authenticated");
/* Store the mAuthResult */ /* Store the mAuthResult */
mAuthResult = authenticationResult; mAuthResult = authenticationResult;
/* call graph */ /* call graph */
callGraphAPI(); callGraphAPI();
...@@ -303,6 +410,7 @@ public class LoginChooseActivity extends Activity { ...@@ -303,6 +410,7 @@ public class LoginChooseActivity extends Activity {
@Override @Override
public void run() { public void run() {
updateSuccessUI(); updateSuccessUI();
} }
}); });
} }
...@@ -412,4 +520,165 @@ public class LoginChooseActivity extends Activity { ...@@ -412,4 +520,165 @@ public class LoginChooseActivity extends Activity {
} }
}; };
} }
private class LoginDetailsSendToServer extends AsyncTask<Void, Integer, Integer> {
private ProgressDialog progressDialog;
private static final int USER_DETAIL = 1;
private int apiStatus;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginChooseActivity.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected Integer doInBackground(Void... params) {
LoginApiManager.submitLoginValues(LoginApiResponse.Json.PASSWORD, Constants.LOGIN_CLIENT_ID, Constants
.LOGIN_CLIENT_SECRET, Constants.FULTON_LOGIN_USERNAME,Constants.FULTON_LOGIN_PASSWORD, new GetUserLoginApiListener() {
@Override
public void onDoneApiCall(LoginApiResponse loginApiResponse) {
apiStatus = API_SUCCESS_USER_LOGIN;
publishProgress(USER_DETAIL);
/*Save access token in Preference*/
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_ACCESS_TOKEN, loginApiResponse.getAccessToken());
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_REFRESH_TOKEN, loginApiResponse.getRefreshToken());
UserApiManager.getUserDetailResponse(LoginChooseActivity.this, Constants.FULTON_LOGIN_USERNAME, new GetUserDetailApiListener() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
mUserDetails = userValues;
if(Util.isNotificationsItemEnabled()) {
UserApiManager.putDeviceRegistration(LoginChooseActivity.this, userValues.get(0).getSysId(), new PutDeviceRegistrationApiListener() {
@Override
public void onDoneApiCall() {
apiStatus = API_SUCCESS_USER_DETAIL;
}
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_DETAIL;
}
});
} else {
apiStatus = API_SUCCESS_USER_DETAIL;
}
}
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_DETAIL;
}
});
}
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_LOGIN;
}
});
return apiStatus;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
if(values[0] == USER_DETAIL) {
// progressDialog.setMessage(getString(R.string.login_screen_getting_user_detail_loading_string));
}
}
@Override
protected void onPostExecute(Integer syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == API_SUCCESS_USER_DETAIL) {
if (mUserDetails != null) {
isLogin = true;
if (((CatalogueApplication) getApplication()).isNetConnected()) {
ChatBotHistoryManager.delete();
String generateRandomStrPharma = GenerateRandomString.randomString(30);
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.SESSION_ID, generateRandomStrPharma);
} else {
DialogUtils.showNoConnectionDialog(LoginChooseActivity.this);
}
String generateRandoStrPharma = GenerateRandomString.randomString(30);
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.SESSION_ID, generateRandoStrPharma);
String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId();
String userFullName = mUserDetails.get(0).getFullName();
String userId = mUserDetails.get(0).getUserId();
String userEmailId = mUserDetails.get(0).getUserEmailId();
if(Util.isChatItemEnabled()) {
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(sysid);
if (localChatBotUser == null) {
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager.deleteAllRows();
ChatBotUserManager.deleteAllRows();
/*Save Logged in user in local db for chat screen*/
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setUserSysId(sysid)
.setName(firstName)
.build();
ChatBotUserManager.save(chatBotUser);
} else {//Update the name of user
localChatBotUser.setName(firstName);
ChatBotUserManager.update(localChatBotUser);
}
}
/*End Chat Local DB Part*/
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_FIRST_NAME, firstName);
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_LAST_NAME, lastName);
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_SYS_ID, sysid);
/*For pre fill value in variable form*/
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_ID, userId);
PrefManager.setSharedPref(LoginChooseActivity.this, PrefManager.PREFERENCE_USER_EMAIL_ID, userEmailId);
// /*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(LoginChooseActivity.this).sendBroadcast(intent);
Bundle bundle = getIntent().getExtras();
if(bundle != null) {
int requestCode = bundle.getInt(Constants.DATA_KEY_LOGIN_REQUEST_CODE);
if (requestCode == Constants.LOGIN_SCREEN_REQUEST_CODE) {
startActivity(new Intent(LoginChooseActivity.this, ChatActivity.class));
} else {
startActivity(new Intent(LoginChooseActivity.this, HomeScreen.class));
}
} else {
startActivity(new Intent(LoginChooseActivity.this, HomeScreen.class));
}
//
} else {
Util.simpleAlert(LoginChooseActivity.this,getResources().getString(R.string.user_detail_not_available));
}
} else if (syncStatus == API_FAIL_USER_LOGIN) {
Util.simpleAlert(LoginChooseActivity.this,getResources().getString(R.string.login_screen_invalid_username_and_password_string));
} else if (syncStatus == API_FAIL_USER_DETAIL) {
Util.simpleAlert(LoginChooseActivity.this,getResources().getString(R.string.failed_to_fetch_user_detail_string));
}
}
}
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main_login"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbarStyle="insideOverlay"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/normal_margin"
android:orientation="vertical">
<ImageView </LinearLayout>
android:layout_width="wrap_content" \ No newline at end of file
android:layout_height="wrap_content"
android:visibility="visible"
android:background="@drawable/ic_login_banner" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/login_with_sso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/normal_margin"
android:layout_marginLeft="@dimen/extra_large_margin"
android:layout_marginRight="@dimen/extra_large_margin"
android:layout_marginTop="30dp"
android:background="@drawable/login_bg"
android:gravity="center"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:text="Login with ADAL"
android:textColor="@android:color/white"
android:textSize="@dimen/large_text_size" />
<TextView
android:id="@+id/login_with_otp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/normal_margin"
android:layout_marginLeft="@dimen/extra_large_margin"
android:layout_marginRight="@dimen/extra_large_margin"
android:layout_marginTop="30dp"
android:background="@drawable/login_bg"
android:gravity="center"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:text="Login with otp"
android:textColor="@android:color/white"
android:textSize="@dimen/large_text_size" />
</LinearLayout>
</LinearLayout>
</ScrollView>
\ No newline at end of file
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/LightBackgroundStyle" style="@style/LightBackgroundStyle"
android:id="@+id/chat_activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@drawable/chat_back_bg"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
tools:context=".ui.ChatActivity"> tools:context=".ui.ChatActivity">
......
The file could not be displayed because it is too large.
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"0.1.4","enabled":true,"outputFile":"app-vportal-staging.apk","fullName":"vportalStaging","baseName":"vportal-staging"},"path":"app-vportal-staging.apk","properties":{}}] [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"0.1.5","enabled":true,"outputFile":"app-vportal-staging.apk","fullName":"vportalStaging","baseName":"vportal-staging"},"path":"app-vportal-staging.apk","properties":{}}]
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment