tidy up
This commit is contained in:
parent
abe95da7d1
commit
7f3159b0bc
3 changed files with 14 additions and 23 deletions
|
|
@ -23,7 +23,7 @@ import org.json.JSONObject;
|
|||
|
||||
|
||||
/**
|
||||
* A login screen that offers login via email/password.
|
||||
* A login screen that offers login via phone number/pin.
|
||||
*/
|
||||
public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbacks<String> {
|
||||
|
||||
|
|
@ -57,8 +57,8 @@ public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbac
|
|||
}
|
||||
});
|
||||
|
||||
Button mEmailSignInButton = findViewById(R.id.phone_sign_in_button);
|
||||
mEmailSignInButton.setOnClickListener(new OnClickListener() {
|
||||
Button mPhoneSignInButton = findViewById(R.id.phone_sign_in_button);
|
||||
mPhoneSignInButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
attemptLogin();
|
||||
|
|
@ -71,7 +71,7 @@ public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbac
|
|||
|
||||
/**
|
||||
* Attempts to sign in or register the account specified by the login form.
|
||||
* If there are form errors (invalid email, missing fields, etc.), the
|
||||
* If there are form errors (invalid phone number, missing fields, etc.), the
|
||||
* errors are presented and no actual login attempt is made.
|
||||
*/
|
||||
private void attemptLogin() {
|
||||
|
|
@ -84,21 +84,21 @@ public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbac
|
|||
mPinView.setError(null);
|
||||
|
||||
// Store values at the time of the login attempt.
|
||||
String email = mPhoneView.getText().toString();
|
||||
String password = mPinView.getText().toString();
|
||||
String phone = mPhoneView.getText().toString();
|
||||
String pin = mPinView.getText().toString();
|
||||
|
||||
boolean cancel = false;
|
||||
View focusView = null;
|
||||
|
||||
// Check for a valid password, if the user entered one.
|
||||
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
|
||||
// Check for a valid pin, if the user entered one.
|
||||
if (!TextUtils.isEmpty(pin) && !isPinValid(pin)) {
|
||||
mPinView.setError(getString(R.string.error_invalid_pin));
|
||||
focusView = mPinView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
// Check for a valid email address.
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
// Check for a valid phone address.
|
||||
if (TextUtils.isEmpty(phone)) {
|
||||
mPhoneView.setError(getString(R.string.error_field_required));
|
||||
focusView = mPhoneView;
|
||||
cancel = true;
|
||||
|
|
@ -112,14 +112,14 @@ public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbac
|
|||
// Show a progress spinner, and kick off a background task to
|
||||
// perform the user login attempt.
|
||||
showProgress(true);
|
||||
mAuthTask = new RequestHandler(email, password, this);
|
||||
mAuthTask = new RequestHandler(phone, pin, this);
|
||||
mAuthTask.execute((Void) null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPasswordValid(String password) {
|
||||
private boolean isPinValid(String pin) {
|
||||
//TODO: Replace this with your own logic
|
||||
return password.length() == 6;
|
||||
return pin.length() == 6;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.example.hochi.nextcompanion;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
|
@ -10,8 +9,6 @@ public class RentActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_rent);
|
||||
ActionBar actionBar = getActionBar();
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
package com.example.hochi.nextcompanion;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
|
|
@ -31,7 +25,7 @@ public class RequestHandler extends AsyncTask<Void, Void, String> {
|
|||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
StringBuilder response = new StringBuilder();
|
||||
String urlParameters = "apikey=rXXqTgQZUPZ89lzB&mobile=" + mPhone + "&pin=" + mPin;
|
||||
String urlParameters = "apikey=" + R.string.loginKey + "&mobile=" + mPhone + "&pin=" + mPin;
|
||||
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue