Browse Source

login fix

no work on main thread
pull/24/head
Iason Karakostas 8 years ago
parent
commit
69a86eb93a
  1. 122
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

122
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -10,8 +10,6 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.concurrent.ExecutionException;
import gr.thmmy.mthmmy.R;
import static gr.thmmy.mthmmy.utils.Thmmy.CERTIFICATE_ERROR;
@ -62,47 +60,49 @@ public class LoginActivity extends BaseActivity {
String username = inputUsername.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
// login user
try {
switch (new LoginTask().execute(username, password).get()) {
case WRONG_USER:
Toast.makeText(getApplicationContext(),
"Wrong username!", Toast.LENGTH_LONG)
.show();
break;
case WRONG_PASSWORD:
Toast.makeText(getApplicationContext(),
"Wrong password!", Toast.LENGTH_LONG)
.show();
break;
case FAILED:
Toast.makeText(getApplicationContext(),
"Check your connection!", Toast.LENGTH_LONG)
.show();
break;
case CERTIFICATE_ERROR:
Toast.makeText(getApplicationContext(),
"Certificate error!", Toast.LENGTH_LONG)
.show();
break;
case OTHER_ERROR:
Toast.makeText(getApplicationContext(),
"Check your connection!", Toast.LENGTH_LONG)
.show();
break;
case LOGGED_IN:
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),
"Login successful!", Toast.LENGTH_LONG)
.show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break;
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
new LoginTask().execute(username,password);
// try {
// switch (new LoginTask().execute(username, password).get()) {
// case WRONG_USER:
// Toast.makeText(getApplicationContext(),
// "Wrong username!", Toast.LENGTH_LONG)
// .show();
// break;
// case WRONG_PASSWORD:
// Toast.makeText(getApplicationContext(),
// "Wrong password!", Toast.LENGTH_LONG)
// .show();
// break;
// case FAILED:
// Toast.makeText(getApplicationContext(),
// "Check your connection!", Toast.LENGTH_LONG)
// .show();
// break;
// case CERTIFICATE_ERROR:
// Toast.makeText(getApplicationContext(),
// "Certificate error!", Toast.LENGTH_LONG)
// .show();
// break;
// case OTHER_ERROR:
// Toast.makeText(getApplicationContext(),
// "Check your connection!", Toast.LENGTH_LONG)
// .show();
// break;
// case LOGGED_IN:
// progressDialog.dismiss();
// Toast.makeText(getApplicationContext(),
// "Login successful!", Toast.LENGTH_LONG)
// .show();
// Intent intent = new Intent(LoginActivity.this, MainActivity.class);
// startActivity(intent);
// finish();
// overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
// break;
// }
// } catch (InterruptedException | ExecutionException e) {
// e.printStackTrace();
// }
progressDialog.dismiss();
btnLogin.setEnabled(true);
}
@ -139,6 +139,42 @@ public class LoginActivity extends BaseActivity {
@Override
protected void onPostExecute(Integer result) {
switch (loginData.getStatus()) {
case WRONG_USER:
Toast.makeText(getApplicationContext(),
"Wrong username!", Toast.LENGTH_LONG).show();
break;
case WRONG_PASSWORD:
Toast.makeText(getApplicationContext(),
"Wrong password!", Toast.LENGTH_LONG)
.show();
break;
case FAILED:
Toast.makeText(getApplicationContext(),
"Check your connection!", Toast.LENGTH_LONG)
.show();
break;
case CERTIFICATE_ERROR:
Toast.makeText(getApplicationContext(),
"Certificate error!", Toast.LENGTH_LONG)
.show();
break;
case OTHER_ERROR:
Toast.makeText(getApplicationContext(),
"Check your connection!", Toast.LENGTH_LONG)
.show();
break;
case LOGGED_IN:
//progressDialog.dismiss();
Toast.makeText(getApplicationContext(),
"Login successful!", Toast.LENGTH_LONG)
.show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break;
}
}
@Override

Loading…
Cancel
Save