Commit 89e9deae authored by Willard's avatar Willard

Minor refactors to login activity

parent d9af2f9d
...@@ -37,6 +37,8 @@ public class LoginActivity extends AppCompatActivity { ...@@ -37,6 +37,8 @@ public class LoginActivity extends AppCompatActivity {
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
mUsernameView = (AutoCompleteTextView) findViewById(R.id.username); 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 = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
...@@ -73,19 +75,14 @@ public class LoginActivity extends AppCompatActivity { ...@@ -73,19 +75,14 @@ public class LoginActivity extends AppCompatActivity {
register(); register();
} }
}); });
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
} }
public void register() { public void register() {
Intent intent = new Intent(this, RegisterActivity.class); startActivity(new Intent(this, RegisterActivity.class));
startActivity(intent);
} }
public void guestLogin() { public void guestLogin() {
Intent intent = new Intent(this, NavDrawerActivity.class); startActivity(new Intent(this, NavDrawerActivity.class));
startActivity(intent);
} }
private void attemptLogin() { private void attemptLogin() {
...@@ -121,15 +118,14 @@ public class LoginActivity extends AppCompatActivity { ...@@ -121,15 +118,14 @@ public class LoginActivity extends AppCompatActivity {
@Override @Override
public void onResponse(Call<Token> call, Response<Token> response) { public void onResponse(Call<Token> call, Response<Token> response) {
showProgress(false); showProgress(false);
if(response.code() == 401) { if (response.code() == 401) {
mUsernameView.setError(""); mUsernameView.setError("");
mPasswordView.setError(""); mPasswordView.setError("");
Toast.makeText(LoginActivity.this, "Invalid credentials!", Toast.LENGTH_LONG).show(); Toast.makeText(LoginActivity.this, "Invalid credentials!", Toast.LENGTH_LONG).show();
} else { } else {
Toast.makeText(LoginActivity.this, "Logged in as " + AppUtils.getUsername() + " successfully.", Toast.LENGTH_LONG).show();
AppUtils.login(username, password, response.body().getId()); AppUtils.login(username, password, response.body().getId());
Intent intent = new Intent(LoginActivity.this, NavDrawerActivity.class); startActivity(new Intent(LoginActivity.this, NavDrawerActivity.class));
startActivity(intent); Toast.makeText(LoginActivity.this, "Logged in as " + AppUtils.getUsername() + " successfully.", Toast.LENGTH_LONG).show();
} }
} }
......
...@@ -3,25 +3,23 @@ ...@@ -3,25 +3,23 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="com.canteeneo.LoginActivity"> tools:context="com.canteeneo.LoginActivity">
<!-- Login progress -->
<ProgressBar <ProgressBar
android:id="@+id/login_progress" android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:visibility="gone" /> android:visibility="gone"/>
<ScrollView <ScrollView
android:id="@+id/login_form" android:id="@+id/login_form"
...@@ -36,8 +34,8 @@ ...@@ -36,8 +34,8 @@
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="166dp" 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.support.design.widget.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -49,7 +47,7 @@ ...@@ -49,7 +47,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/prompt_username" android:hint="@string/prompt_username"
android:inputType="text" android:inputType="text"
android:maxLines="1" /> android:maxLines="1"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
...@@ -66,7 +64,7 @@ ...@@ -66,7 +64,7 @@
android:imeActionLabel="@string/action_sign_in_short" android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified" android:imeOptions="actionUnspecified"
android:inputType="textPassword" android:inputType="textPassword"
android:maxLines="1" /> android:maxLines="1"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
...@@ -88,9 +86,9 @@ ...@@ -88,9 +86,9 @@
android:id="@+id/register_button" android:id="@+id/register_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/action_register"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:elevation="0dp"/> android:elevation="0dp"
android:text="@string/action_register"/>
</LinearLayout> </LinearLayout>
</ScrollView> </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