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> {
|
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);
|
Button mPhoneSignInButton = findViewById(R.id.phone_sign_in_button);
|
||||||
mEmailSignInButton.setOnClickListener(new OnClickListener() {
|
mPhoneSignInButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
attemptLogin();
|
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.
|
* 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.
|
* errors are presented and no actual login attempt is made.
|
||||||
*/
|
*/
|
||||||
private void attemptLogin() {
|
private void attemptLogin() {
|
||||||
|
|
@ -84,21 +84,21 @@ public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbac
|
||||||
mPinView.setError(null);
|
mPinView.setError(null);
|
||||||
|
|
||||||
// Store values at the time of the login attempt.
|
// Store values at the time of the login attempt.
|
||||||
String email = mPhoneView.getText().toString();
|
String phone = mPhoneView.getText().toString();
|
||||||
String password = mPinView.getText().toString();
|
String pin = mPinView.getText().toString();
|
||||||
|
|
||||||
boolean cancel = false;
|
boolean cancel = false;
|
||||||
View focusView = null;
|
View focusView = null;
|
||||||
|
|
||||||
// Check for a valid password, if the user entered one.
|
// Check for a valid pin, if the user entered one.
|
||||||
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
|
if (!TextUtils.isEmpty(pin) && !isPinValid(pin)) {
|
||||||
mPinView.setError(getString(R.string.error_invalid_pin));
|
mPinView.setError(getString(R.string.error_invalid_pin));
|
||||||
focusView = mPinView;
|
focusView = mPinView;
|
||||||
cancel = true;
|
cancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a valid email address.
|
// Check for a valid phone address.
|
||||||
if (TextUtils.isEmpty(email)) {
|
if (TextUtils.isEmpty(phone)) {
|
||||||
mPhoneView.setError(getString(R.string.error_field_required));
|
mPhoneView.setError(getString(R.string.error_field_required));
|
||||||
focusView = mPhoneView;
|
focusView = mPhoneView;
|
||||||
cancel = true;
|
cancel = true;
|
||||||
|
|
@ -112,14 +112,14 @@ public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbac
|
||||||
// Show a progress spinner, and kick off a background task to
|
// Show a progress spinner, and kick off a background task to
|
||||||
// perform the user login attempt.
|
// perform the user login attempt.
|
||||||
showProgress(true);
|
showProgress(true);
|
||||||
mAuthTask = new RequestHandler(email, password, this);
|
mAuthTask = new RequestHandler(phone, pin, this);
|
||||||
mAuthTask.execute((Void) null);
|
mAuthTask.execute((Void) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPasswordValid(String password) {
|
private boolean isPinValid(String pin) {
|
||||||
//TODO: Replace this with your own logic
|
//TODO: Replace this with your own logic
|
||||||
return password.length() == 6;
|
return pin.length() == 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.example.hochi.nextcompanion;
|
package com.example.hochi.nextcompanion;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
|
@ -10,8 +9,6 @@ public class RentActivity extends AppCompatActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_rent);
|
setContentView(R.layout.activity_rent);
|
||||||
ActionBar actionBar = getActionBar();
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
package com.example.hochi.nextcompanion;
|
package com.example.hochi.nextcompanion;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
|
@ -31,7 +25,7 @@ public class RequestHandler extends AsyncTask<Void, Void, String> {
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... params) {
|
protected String doInBackground(Void... params) {
|
||||||
StringBuilder response = new StringBuilder();
|
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;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue