|
@ -1,13 +1,15 @@ |
|
|
package gr.thmmy.mthmmy.activities; |
|
|
package gr.thmmy.mthmmy.activities; |
|
|
|
|
|
|
|
|
import android.app.ProgressDialog; |
|
|
|
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.util.Log; |
|
|
import android.util.Log; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
|
|
|
import android.view.inputmethod.InputMethodManager; |
|
|
import android.widget.Button; |
|
|
import android.widget.Button; |
|
|
import android.widget.EditText; |
|
|
import android.widget.EditText; |
|
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
|
import android.widget.ScrollView; |
|
|
import android.widget.Toast; |
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
@ -100,6 +102,7 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
if (username.isEmpty()) { |
|
|
if (username.isEmpty()) { |
|
|
inputUsername.setError("Enter a valid username"); |
|
|
inputUsername.setError("Enter a valid username"); |
|
|
|
|
|
inputUsername.requestFocus(); |
|
|
valid = false; |
|
|
valid = false; |
|
|
} else { |
|
|
} else { |
|
|
inputUsername.setError(null); |
|
|
inputUsername.setError(null); |
|
@ -107,6 +110,8 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
if (password.isEmpty()) { |
|
|
if (password.isEmpty()) { |
|
|
inputPassword.setError("Enter a valid password", null); |
|
|
inputPassword.setError("Enter a valid password", null); |
|
|
|
|
|
if (valid) |
|
|
|
|
|
inputPassword.requestFocus(); |
|
|
valid = false; |
|
|
valid = false; |
|
|
} else { |
|
|
} else { |
|
|
inputPassword.setError(null); |
|
|
inputPassword.setError(null); |
|
@ -118,7 +123,8 @@ public class LoginActivity extends BaseActivity { |
|
|
//--------------------------------------------LOGIN-------------------------------------------------
|
|
|
//--------------------------------------------LOGIN-------------------------------------------------
|
|
|
private class LoginTask extends AsyncTask<String, Void, Integer> { |
|
|
private class LoginTask extends AsyncTask<String, Void, Integer> { |
|
|
//Class variables
|
|
|
//Class variables
|
|
|
ProgressDialog progressDialog; |
|
|
private LinearLayout spinner; |
|
|
|
|
|
private ScrollView loginContent; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected Integer doInBackground(String... params) { |
|
|
protected Integer doInBackground(String... params) { |
|
@ -129,11 +135,17 @@ public class LoginActivity extends BaseActivity { |
|
|
protected void onPreExecute() { //Show a progress dialog until done
|
|
|
protected void onPreExecute() { //Show a progress dialog until done
|
|
|
btnLogin.setEnabled(false); //Login button shouldn't be pressed during this
|
|
|
btnLogin.setEnabled(false); //Login button shouldn't be pressed during this
|
|
|
|
|
|
|
|
|
progressDialog = new ProgressDialog(LoginActivity.this,R.style.AppTheme_Dark_Dialog); |
|
|
spinner = (LinearLayout) findViewById(R.id.login_progress_bar); |
|
|
progressDialog.setCancelable(false); |
|
|
loginContent = (ScrollView) findViewById(R.id.inner_scroll_view); |
|
|
progressDialog.setIndeterminate(true); |
|
|
|
|
|
progressDialog.setMessage("Authenticating..."); |
|
|
View view = getCurrentFocus(); |
|
|
progressDialog.show(); |
|
|
if (view != null) { |
|
|
|
|
|
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); |
|
|
|
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
loginContent.setVisibility(View.INVISIBLE); |
|
|
|
|
|
spinner.setVisibility(View.VISIBLE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -153,10 +165,12 @@ public class LoginActivity extends BaseActivity { |
|
|
case WRONG_USER: |
|
|
case WRONG_USER: |
|
|
Toast.makeText(getApplicationContext(), |
|
|
Toast.makeText(getApplicationContext(), |
|
|
"Wrong username!", Toast.LENGTH_LONG).show(); |
|
|
"Wrong username!", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
inputUsername.requestFocus(); |
|
|
break; |
|
|
break; |
|
|
case WRONG_PASSWORD: |
|
|
case WRONG_PASSWORD: |
|
|
Toast.makeText(getApplicationContext(), |
|
|
Toast.makeText(getApplicationContext(), |
|
|
"Wrong password!", Toast.LENGTH_LONG).show(); |
|
|
"Wrong password!", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
inputPassword.requestFocus(); |
|
|
break; |
|
|
break; |
|
|
case FAILURE: |
|
|
case FAILURE: |
|
|
Toast.makeText(getApplicationContext(), |
|
|
Toast.makeText(getApplicationContext(), |
|
@ -174,9 +188,10 @@ public class LoginActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
//Login failed
|
|
|
//Login failed
|
|
|
btnLogin.setEnabled(true); //Re-enable login button
|
|
|
btnLogin.setEnabled(true); //Re-enable login button
|
|
|
progressDialog.dismiss(); //Hide progress dialog
|
|
|
|
|
|
|
|
|
loginContent.setVisibility(View.VISIBLE); |
|
|
|
|
|
spinner.setVisibility(View.INVISIBLE); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//---------------------------------------LOGIN ENDS-------------------------------------------------
|
|
|
//---------------------------------------LOGIN ENDS-------------------------------------------------
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|