Commit 89e9deae authored by Willard's avatar Willard

Minor refactors to login activity

parent d9af2f9d
......@@ -37,6 +37,8 @@ public class LoginActivity extends AppCompatActivity {
setContentView(R.layout.activity_login);
mUsernameView = (AutoCompleteTextView) findViewById(R.id.username);
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
......@@ -73,19 +75,14 @@ public class LoginActivity extends AppCompatActivity {
register();
}
});
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
}
public void register() {
Intent intent = new Intent(this, RegisterActivity.class);
startActivity(intent);
startActivity(new Intent(this, RegisterActivity.class));
}
public void guestLogin() {
Intent intent = new Intent(this, NavDrawerActivity.class);
startActivity(intent);
startActivity(new Intent(this, NavDrawerActivity.class));
}
private void attemptLogin() {
......@@ -121,15 +118,14 @@ public class LoginActivity extends AppCompatActivity {
@Override
public void onResponse(Call<Token> call, Response<Token> response) {
showProgress(false);
if(response.code() == 401) {
if (response.code() == 401) {
mUsernameView.setError("");
mPasswordView.setError("");
Toast.makeText(LoginActivity.this, "Invalid credentials!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(LoginActivity.this, "Logged in as " + AppUtils.getUsername() + " successfully.", Toast.LENGTH_LONG).show();
AppUtils.login(username, password, response.body().getId());
Intent intent = new Intent(LoginActivity.this, NavDrawerActivity.class);
startActivity(intent);
startActivity(new Intent(LoginActivity.this, NavDrawerActivity.class));
Toast.makeText(LoginActivity.this, "Logged in as " + AppUtils.getUsername() + " successfully.", Toast.LENGTH_LONG).show();
}
}
......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="com.canteeneo.LoginActivity">
<!-- Login progress -->
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.canteeneo.LoginActivity">
<ProgressBar
android:id="@+id/login_progress"
......@@ -21,7 +19,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
android:visibility="gone"/>
<ScrollView
android:id="@+id/login_form"
......@@ -36,8 +34,8 @@
<ImageView
android:layout_width="match_parent"
android:layout_height="166dp"
app:srcCompat="@drawable/temp_logo"
android:scaleType="fitCenter" />
android:scaleType="fitCenter"
app:srcCompat="@drawable/temp_logo"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
......@@ -49,7 +47,7 @@
android:layout_height="wrap_content"
android:hint="@string/prompt_username"
android:inputType="text"
android:maxLines="1" />
android:maxLines="1"/>
</android.support.design.widget.TextInputLayout>
......@@ -66,7 +64,7 @@
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1" />
android:maxLines="1"/>
</android.support.design.widget.TextInputLayout>
......@@ -88,9 +86,9 @@
android:id="@+id/register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_register"
android:layout_marginTop="16dp"
android:elevation="0dp"/>
android:elevation="0dp"
android:text="@string/action_register"/>
</LinearLayout>
</ScrollView>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment