set the Login validation

parent a26400fe
...@@ -23,11 +23,18 @@ public class LoginApiManger { ...@@ -23,11 +23,18 @@ public class LoginApiManger {
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
if (response.code() == 200) { ResponseBody body = response.body();
if (body != null) {
if (body.contentLength() != -1) {
return SyncStatus.SUCCESS; return SyncStatus.SUCCESS;
} else { } else {
return SyncStatus.SERVICEDOWN;
}
} else {
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e); CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL; return SyncStatus.FAIL;
......
...@@ -49,9 +49,12 @@ import butterknife.Unbinder; ...@@ -49,9 +49,12 @@ import butterknife.Unbinder;
*/ */
public class SelectReferenceDialog extends DialogFragment { public class SelectReferenceDialog extends DialogFragment {
@BindView(R.id.dialog_list_view) ListView mListView; @BindView(R.id.dialog_list_view)
@BindView(R.id.dialog_title) TextView mTitleTextView; ListView mListView;
@BindView(R.id.dialog_edit_text) EditText mEditText; @BindView(R.id.dialog_title)
TextView mTitleTextView;
@BindView(R.id.dialog_edit_text)
EditText mEditText;
private ReferenceListener mListener; private ReferenceListener mListener;
private Unbinder mUnbinder; private Unbinder mUnbinder;
...@@ -95,8 +98,8 @@ public class SelectReferenceDialog extends DialogFragment { ...@@ -95,8 +98,8 @@ public class SelectReferenceDialog extends DialogFragment {
super.onStart(); super.onStart();
Dialog dialog = getDialog(); Dialog dialog = getDialog();
if (dialog != null) { if (dialog != null) {
int width = 4 * (getResources().getDisplayMetrics().widthPixels/5); int width = 4 * (getResources().getDisplayMetrics().widthPixels / 5);
int height = 3 * (getResources().getDisplayMetrics().heightPixels/4); int height = 3 * (getResources().getDisplayMetrics().heightPixels / 4);
dialog.getWindow().setLayout(width, height); dialog.getWindow().setLayout(width, height);
} }
} }
...@@ -117,8 +120,8 @@ public class SelectReferenceDialog extends DialogFragment { ...@@ -117,8 +120,8 @@ public class SelectReferenceDialog extends DialogFragment {
final int DRAWABLE_RIGHT = 2; final int DRAWABLE_RIGHT = 2;
Drawable drawable = mEditText.getCompoundDrawables()[DRAWABLE_RIGHT]; Drawable drawable = mEditText.getCompoundDrawables()[DRAWABLE_RIGHT];
Rect bounds = drawable.getBounds(); Rect bounds = drawable.getBounds();
if(event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() >= (mEditText.getRight() + mEditText.getLeft() - (bounds.width() / getResources().getDisplayMetrics().density))) { if (event.getRawX() >= (mEditText.getRight() + mEditText.getLeft() - (bounds.width() / getResources().getDisplayMetrics().density))) {
mEditText.setText(""); mEditText.setText("");
return true; return true;
} else { } else {
...@@ -136,18 +139,19 @@ public class SelectReferenceDialog extends DialogFragment { ...@@ -136,18 +139,19 @@ public class SelectReferenceDialog extends DialogFragment {
@OnItemClick(R.id.dialog_list_view) @OnItemClick(R.id.dialog_list_view)
void listViewItemClick(int position) { void listViewItemClick(int position) {
Reference reference = mReferenceList.get(position); Reference reference = mReferenceList.get(position);
if(reference != null) if (reference != null)
mListener.positiveButtonClick(reference); mListener.positiveButtonClick(reference);
else else
mListener.negativeButtonClick(); mListener.negativeButtonClick();
getDialog().dismiss(); getDialog().dismiss();
} }
@OnEditorAction(R.id.dialog_edit_text) boolean onEditorAction(TextView v, int actionId, KeyEvent event) { @OnEditorAction(R.id.dialog_edit_text)
if(actionId == EditorInfo.IME_ACTION_SEARCH) { boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Util.hideSoftKeyboard(getActivity(), v); Util.hideSoftKeyboard(getActivity(), v);
if(!mEditText.getText().toString().isEmpty()) { if (!mEditText.getText().toString().isEmpty()) {
if(mApplication.isNetConnected()) { if (mApplication.isNetConnected()) {
new FetchReference().execute(mEditText.getText().toString()); new FetchReference().execute(mEditText.getText().toString());
} else { } else {
DialogUtils.showNoConnectionDialogWithCloseActivity(getActivity()); DialogUtils.showNoConnectionDialogWithCloseActivity(getActivity());
...@@ -185,10 +189,10 @@ public class SelectReferenceDialog extends DialogFragment { ...@@ -185,10 +189,10 @@ public class SelectReferenceDialog extends DialogFragment {
@Override @Override
protected void onPostExecute(SyncStatus syncStatus) { protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus); super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) { if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss(); progressDialog.dismiss();
} }
if(syncStatus == SyncStatus.SUCCESS) { if (syncStatus == SyncStatus.SUCCESS) {
ArrayAdapter<String> adapter = new ArrayAdapter(getActivity(), ArrayAdapter<String> adapter = new ArrayAdapter(getActivity(),
android.R.layout.simple_list_item_1, android.R.layout.simple_list_item_1,
android.R.id.text1, android.R.id.text1,
......
...@@ -7,7 +7,8 @@ package com.vsoft.uoflservicenow.enums; ...@@ -7,7 +7,8 @@ package com.vsoft.uoflservicenow.enums;
*/ */
public enum SyncStatus { public enum SyncStatus {
SUCCESS (1), SUCCESS (1),
FAIL (2); FAIL (2),
SERVICEDOWN (3);
int id; int id;
......
...@@ -250,7 +250,6 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -250,7 +250,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
/*Create label with mandatory value*/ /*Create label with mandatory value*/
LinearLayout labelLayout = new LinearLayout(CatalogueVariableScreen.this); LinearLayout labelLayout = new LinearLayout(CatalogueVariableScreen.this);
labelLayout.setOrientation(LinearLayout.HORIZONTAL); labelLayout.setOrientation(LinearLayout.HORIZONTAL);
TextView label = new TextView(CatalogueVariableScreen.this); TextView label = new TextView(CatalogueVariableScreen.this);
label.setText(catalogueVariable.getQuestionText()); label.setText(catalogueVariable.getQuestionText());
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin); childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
......
...@@ -38,8 +38,10 @@ import butterknife.OnClick; ...@@ -38,8 +38,10 @@ import butterknife.OnClick;
*/ */
public class LoginScreen extends Activity { public class LoginScreen extends Activity {
@BindView(R.id.login_screen_username_edit_text) EditText mUserNameEditText; @BindView(R.id.login_screen_username_edit_text)
@BindView(R.id.login_screen_password_edit_text) EditText mPasswordEditText; EditText mUserNameEditText;
@BindView(R.id.login_screen_password_edit_text)
EditText mPasswordEditText;
private List<UserApiValues> mUserDetails; private List<UserApiValues> mUserDetails;
private CatalogueApplication mApplication; private CatalogueApplication mApplication;
...@@ -55,7 +57,7 @@ public class LoginScreen extends Activity { ...@@ -55,7 +57,7 @@ public class LoginScreen extends Activity {
mApplication = (CatalogueApplication) getApplication(); mApplication = (CatalogueApplication) getApplication();
PrefManager prefManager = PrefManager.getInstance(); PrefManager prefManager = PrefManager.getInstance();
prefManager.init(LoginScreen.this); prefManager.init(LoginScreen.this);
CheckLoginValues(); //CheckLoginValues();
mPasswordEditText.setOnKeyListener(new View.OnKeyListener() { mPasswordEditText.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) { public boolean onKey(View v, int keyCode, KeyEvent event) {
...@@ -128,21 +130,43 @@ public class LoginScreen extends Activity { ...@@ -128,21 +130,43 @@ public class LoginScreen extends Activity {
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
SyncStatus syncStatus; SyncStatus syncStatus = null;
userName = params[0];//"a0kuma18"; userName = params[0];//"a0kuma18";
String password = params[1];//"v$0ftA$win"; String password = params[1];//"v$0ftA$win";
try {
syncStatus = LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants syncStatus = LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName, password); .CLIENT_SECRET, userName, password);
if (syncStatus != null && syncStatus == SyncStatus.SUCCESS) {
if (syncStatus != null) {
if (syncStatus == SyncStatus.SUCCESS) {
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() { return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
@Override @Override
public void onDoneApiCall(List<UserApiValues> userValues) { public void onDoneApiCall(List<UserApiValues> userValues) {
mUserDetails = userValues; mUserDetails = userValues;
} }
}); });
} else { } else if (syncStatus == SyncStatus.SERVICEDOWN) {
return syncStatus; runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.server_not_reachable, Toast.LENGTH_LONG).show();
}
});
} else if (syncStatus == SyncStatus.FAIL) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_usernane_and_password_string, Toast.LENGTH_LONG).show();
} }
});
}
}
} catch (Exception e) {
}
return syncStatus;
} }
@Override @Override
...@@ -159,9 +183,9 @@ public class LoginScreen extends Activity { ...@@ -159,9 +183,9 @@ public class LoginScreen extends Activity {
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstName, lastName, sysid); PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstName, lastName, sysid);
startActivity(new Intent(LoginScreen.this, HomeScreen.class)); startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish(); finish();
}
} else { } else {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_usernane_and_password_string, Toast.LENGTH_LONG).show(); Toast.makeText(LoginScreen.this, R.string.user_detail_not_available, Toast.LENGTH_LONG).show();
}
} }
} }
} }
......
...@@ -38,7 +38,6 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -38,7 +38,6 @@ public class MyIncidentScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar; @BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.my_incidents_screen_list_view) ListView mListView; @BindView(R.id.my_incidents_screen_list_view) ListView mListView;
private List<Incident> mIncidentList; private List<Incident> mIncidentList;
@Override @Override
......
...@@ -97,7 +97,7 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -97,7 +97,7 @@ public class MyRequestActivity extends AppCompatActivity {
if(mMyRequestList !=null) if(mMyRequestList !=null)
setData(mMyRequestList); setData(mMyRequestList);
} else { } else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_string); showErrorDialog(R.string.failed_to_fetch_my_request_string);
} }
} }
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
android:background="@drawable/username_under_bg_box" android:background="@drawable/username_under_bg_box"
android:drawableLeft="@mipmap/ic_user_icon" android:drawableLeft="@mipmap/ic_user_icon"
android:hint="@string/username_string" android:hint="@string/username_string"
android:text="a0kuma18"
android:lines="1" android:lines="1"
android:padding="@dimen/normal_margin" android:padding="@dimen/normal_margin"
android:singleLine="true" /> android:singleLine="true" />
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
android:background="@drawable/username_under_bg_box" android:background="@drawable/username_under_bg_box"
android:drawableLeft="@mipmap/ic_password_icon" android:drawableLeft="@mipmap/ic_password_icon"
android:hint="@string/password_string" android:hint="@string/password_string"
android:text="v$0ftA$win"
android:inputType="textPassword" android:inputType="textPassword"
android:lines="1" android:lines="1"
android:padding="@dimen/normal_margin" android:padding="@dimen/normal_margin"
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<!--Failed to fetch--> <!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string> <string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_my_request_string">Failed to fetch MyRequest</string>
<string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string> <string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string>
<string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string> <string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string>
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string> <string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
...@@ -36,6 +37,9 @@ ...@@ -36,6 +37,9 @@
<!--Login Screen--> <!--Login Screen-->
<string name="login_screen_login_string">Login</string> <string name="login_screen_login_string">Login</string>
<string name="login_screen_invalid_usernane_and_password_string">Invalid username and password</string> <string name="login_screen_invalid_usernane_and_password_string">Invalid username and password</string>
<string name="server_not_reachable">Unable to connect to server. Please try again later.</string>
<string name="user_detail_not_available">Unable to fetch user details.</string>
<string name="user_error">Please enter username</string> <string name="user_error">Please enter username</string>
<string name="pasw_error">Please enter password</string> <string name="pasw_error">Please enter password</string>
<string name="username_string">Username</string> <string name="username_string">Username</string>
......
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