set the Login validation

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