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

Loading…
Cancel
Save