Set the single asyncTask inLoginpage

parent a7dfa538
...@@ -24,8 +24,10 @@ import butterknife.OnItemClick; ...@@ -24,8 +24,10 @@ import butterknife.OnItemClick;
* Created by Kunj on 11/8/16. * Created by Kunj on 11/8/16.
*/ */
public class HomeScreen extends AppCompatActivity { public class HomeScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar; @BindView(R.id.tool_bar_view)
@BindView(R.id.home_screen_grid_view) GridView mGridView; Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view)
GridView mGridView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
......
...@@ -8,12 +8,9 @@ import android.content.Intent; ...@@ -8,12 +8,9 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
...@@ -49,7 +46,6 @@ import butterknife.internal.Utils; ...@@ -49,7 +46,6 @@ import butterknife.internal.Utils;
*/ */
public class LoginScreen extends Activity { public class LoginScreen extends Activity {
@BindView(R.id.login_screen_username_edit_text) @BindView(R.id.login_screen_username_edit_text)
EditText userName; EditText userName;
@BindView(R.id.errormessage) @BindView(R.id.errormessage)
...@@ -105,7 +101,6 @@ public class LoginScreen extends Activity { ...@@ -105,7 +101,6 @@ public class LoginScreen extends Activity {
CatalogueApplication application = (CatalogueApplication) getApplication(); CatalogueApplication application = (CatalogueApplication) getApplication();
Tracker tracker = application.getDefaultTracker(); Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.login_screen_string)); Util.sendScreenName(tracker, getString(R.string.login_screen_string));
} }
...@@ -141,7 +136,6 @@ public class LoginScreen extends Activity { ...@@ -141,7 +136,6 @@ public class LoginScreen extends Activity {
@OnClick(R.id.login_screen_login_text_view) @OnClick(R.id.login_screen_login_text_view)
void onLoginClicked() { void onLoginClicked() {
//startActivity(new Intent(LoginScreen.this, HomeScreen.class));
callLoginAPI(); callLoginAPI();
} }
...@@ -161,50 +155,21 @@ public class LoginScreen extends Activity { ...@@ -161,50 +155,21 @@ public class LoginScreen extends Activity {
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
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";
return LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants syncStatus = LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName, .CLIENT_SECRET, userName, password);
password); if (syncStatus != null && syncStatus == SyncStatus.SUCCESS) {
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
new UserApiDetails().execute(userName);
} else {
errorMessage.setVisibility(View.VISIBLE);
errorMessage.setText("Invalid username and password");
//Toast.makeText(LoginScreen.this, "Invalid username and password", Toast.LENGTH_SHORT).show();
}
}
private class UserApiDetails extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
String userName = params[0];
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 {
return syncStatus;
}
} }
@Override @Override
...@@ -213,7 +178,7 @@ public class LoginScreen extends Activity { ...@@ -213,7 +178,7 @@ public class LoginScreen extends Activity {
if (progressDialog != null && progressDialog.isShowing()) { if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss(); progressDialog.dismiss();
} }
if (syncStatus == SyncStatus.SUCCESS) { if (syncStatus != null && syncStatus == SyncStatus.SUCCESS) {
if (mUserDetails != null) { if (mUserDetails != null) {
String firstname = mUserDetails.get(0).getFirstName(); String firstname = mUserDetails.get(0).getFirstName();
String lasrname = mUserDetails.get(0).getLastName(); String lasrname = mUserDetails.get(0).getLastName();
...@@ -222,7 +187,9 @@ public class LoginScreen extends Activity { ...@@ -222,7 +187,9 @@ public class LoginScreen extends Activity {
startActivity(new Intent(LoginScreen.this, HomeScreen.class)); startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish(); finish();
} }
} } else {
errorMessage.setVisibility(View.VISIBLE);
errorMessage.setText("Invalid username and password");
} }
} }
} }
......
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