Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-CanteeneoAndroid
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-CanteeneoAndroid
Commits
e4ac1aeb
Commit
e4ac1aeb
authored
Dec 01, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add registration feature
parent
f834e64b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
352 additions
and
25 deletions
+352
-25
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+15
-13
CanteeneoApiInterface.java
app/src/main/java/com/testapp/CanteeneoApiInterface.java
+7
-0
LoginActivity.java
app/src/main/java/com/testapp/LoginActivity.java
+15
-5
RegisterActivity.java
app/src/main/java/com/testapp/RegisterActivity.java
+166
-0
NewUserResult.java
app/src/main/java/com/testapp/entities/NewUserResult.java
+28
-0
activity_login.xml
app/src/main/res/layout/activity_login.xml
+4
-3
activity_register.xml
app/src/main/res/layout/activity_register.xml
+110
-0
strings.xml
app/src/main/res/values/strings.xml
+7
-4
No files found.
app/src/main/AndroidManifest.xml
View file @
e4ac1aeb
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.testapp"
>
package=
"com.testapp"
>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission
android:name=
"android.permission.GET_ACCOUNTS"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.GET_ACCOUNTS"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<application
android:name=
".CustomApplication"
...
...
@@ -20,31 +20,33 @@
android:name=
".LoginActivity"
android:label=
"@string/app_name"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".NavDrawerActivity"
android:label=
"@string/title_activity_nav_drawer"
android:theme=
"@style/AppTheme.NoActionBar"
/>
android:theme=
"@style/AppTheme.NoActionBar"
/>
<activity
android:name=
".SearchActivity"
android:label=
"@string/title_activity_search"
android:theme=
"@style/AppTheme.NoActionBar"
/>
android:theme=
"@style/AppTheme.NoActionBar"
/>
<activity
android:name=
".DishViewActivity"
android:label=
"@string/title_activity_blahblah"
android:theme=
"@style/AppTheme"
/>
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".StallViewActivity"
android:label=
"@string/title_activity_stall_view"
android:theme=
"@style/AppTheme"
/>
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".AddDishReviewActivity"
android:label=
"@string/title_activity_add_dish_review"
android:theme=
"@style/AppTheme"
></activity>
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".RegisterActivity"
>
</activity>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/com/testapp/CanteeneoApiInterface.java
View file @
e4ac1aeb
...
...
@@ -5,6 +5,7 @@ import com.testapp.entities.Dish;
import
com.testapp.entities.DishReview
;
import
com.testapp.entities.DishType
;
import
com.testapp.entities.Location
;
import
com.testapp.entities.NewUserResult
;
import
com.testapp.entities.Stall
;
import
com.testapp.entities.StallReview
;
import
com.testapp.entities.Token
;
...
...
@@ -15,6 +16,8 @@ import okhttp3.ResponseBody;
import
retrofit2.Call
;
import
retrofit2.http.Body
;
import
retrofit2.http.Field
;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
import
retrofit2.http.Path
;
...
...
@@ -54,6 +57,10 @@ public interface CanteeneoApiInterface {
@POST
(
"api/dishes/{id}/reviews"
)
Call
<
ResponseBody
>
newDishReview
(
@Path
(
"id"
)
int
id
,
@Body
DishReview
review
);
@FormUrlEncoded
@POST
(
"api/users/new"
)
Call
<
NewUserResult
>
newUser
(
@Field
(
"email"
)
String
email
,
@Field
(
"username"
)
String
username
,
@Field
(
"password"
)
String
password
);
@GET
(
"api/token"
)
Call
<
Token
>
getToken
();
}
app/src/main/java/com/testapp/LoginActivity.java
View file @
e4ac1aeb
...
...
@@ -69,10 +69,23 @@ public class LoginActivity extends AppCompatActivity {
}
});
Button
mRegisterButton
=
(
Button
)
findViewById
(
R
.
id
.
register_button
);
mRegisterButton
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
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
);
}
public
void
guestLogin
()
{
Intent
intent
=
new
Intent
(
this
,
NavDrawerActivity
.
class
);
startActivity
(
intent
);
...
...
@@ -92,8 +105,8 @@ public class LoginActivity extends AppCompatActivity {
boolean
cancel
=
false
;
View
focusView
=
null
;
if
(
!
TextUtils
.
isEmpty
(
password
))
{
m
PasswordView
.
setError
(
getString
(
R
.
string
.
error_invalid_passwor
d
));
if
(
TextUtils
.
isEmpty
(
password
))
{
m
UsernameView
.
setError
(
getString
(
R
.
string
.
error_field_require
d
));
focusView
=
mPasswordView
;
cancel
=
true
;
}
...
...
@@ -180,9 +193,6 @@ public class LoginActivity extends AppCompatActivity {
if
(
success
)
{
finish
();
}
else
{
mPasswordView
.
setError
(
getString
(
R
.
string
.
error_incorrect_password
));
mPasswordView
.
requestFocus
();
}
}
...
...
app/src/main/java/com/testapp/RegisterActivity.java
0 → 100644
View file @
e4ac1aeb
package
com
.
testapp
;
import
android.animation.Animator
;
import
android.animation.AnimatorListenerAdapter
;
import
android.annotation.TargetApi
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.v7.app.AppCompatActivity
;
import
android.text.TextUtils
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.View.OnClickListener
;
import
android.view.inputmethod.EditorInfo
;
import
android.widget.AutoCompleteTextView
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.testapp.entities.NewUserResult
;
import
com.testapp.entities.Token
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
RegisterActivity
extends
AppCompatActivity
{
private
EditText
mEmailView
;
private
EditText
mUsernameView
;
private
EditText
mPasswordView
;
private
EditText
mConfirmPasswordView
;
private
View
mProgressView
;
private
View
mRegisterFormView
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_register
);
mEmailView
=
(
EditText
)
findViewById
(
R
.
id
.
email
);
mUsernameView
=
(
EditText
)
findViewById
(
R
.
id
.
username
);
mPasswordView
=
(
EditText
)
findViewById
(
R
.
id
.
password
);
mConfirmPasswordView
=
(
EditText
)
findViewById
(
R
.
id
.
confirm_password
);
Button
mRegisterButton
=
(
Button
)
findViewById
(
R
.
id
.
register_button
);
mRegisterButton
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
attemptSignIn
();
}
});
mRegisterFormView
=
findViewById
(
R
.
id
.
register_form
);
mProgressView
=
findViewById
(
R
.
id
.
register_progress
);
}
private
void
attemptSignIn
()
{
mEmailView
.
setError
(
null
);
mUsernameView
.
setError
(
null
);
mPasswordView
.
setError
(
null
);
String
email
=
mEmailView
.
getText
().
toString
();
String
username
=
mUsernameView
.
getText
().
toString
();
String
password
=
mPasswordView
.
getText
().
toString
();
String
confirm_password
=
mConfirmPasswordView
.
getText
().
toString
();
boolean
cancel
=
false
;
View
focusView
=
null
;
if
(
TextUtils
.
isEmpty
(
email
))
{
mEmailView
.
setError
(
getString
(
R
.
string
.
error_field_required
));
focusView
=
mEmailView
;
cancel
=
true
;
}
if
(
TextUtils
.
isEmpty
(
password
))
{
mPasswordView
.
setError
(
getString
(
R
.
string
.
error_field_required
));
focusView
=
mPasswordView
;
cancel
=
true
;
}
if
(!
password
.
equals
(
confirm_password
))
{
mPasswordView
.
setError
(
getString
(
R
.
string
.
error_password_match
));
mConfirmPasswordView
.
setError
(
getString
(
R
.
string
.
error_password_match
));
focusView
=
mPasswordView
;
cancel
=
true
;
}
if
(
TextUtils
.
isEmpty
(
username
))
{
mUsernameView
.
setError
(
getString
(
R
.
string
.
error_field_required
));
focusView
=
mUsernameView
;
cancel
=
true
;
}
if
(
cancel
)
{
focusView
.
requestFocus
();
}
else
{
showProgress
(
true
);
Call
<
NewUserResult
>
call
=
AppUtils
.
service
.
newUser
(
email
,
username
,
password
);
call
.
enqueue
(
new
Callback
<
NewUserResult
>()
{
@Override
public
void
onResponse
(
Call
<
NewUserResult
>
call
,
Response
<
NewUserResult
>
response
)
{
showProgress
(
false
);
NewUserResult
result
=
response
.
body
();
if
(
result
.
isSuccess
())
{
Intent
intent
=
new
Intent
(
RegisterActivity
.
this
,
LoginActivity
.
class
);
startActivity
(
intent
);
}
else
{
registerError
(
result
.
getField
());
}
}
@Override
public
void
onFailure
(
Call
<
NewUserResult
>
call
,
Throwable
t
)
{
showProgress
(
false
);
Toast
.
makeText
(
RegisterActivity
.
this
,
"Server failure, please try again. Message: "
+
t
.
getMessage
(),
Toast
.
LENGTH_LONG
);
}
});
}
}
public
void
registerError
(
String
field
)
{
if
(
field
.
equals
(
"username"
))
{
mUsernameView
.
setError
(
getString
(
R
.
string
.
error_username_taken
));
mUsernameView
.
requestFocus
();
}
if
(
field
.
equals
(
"email"
))
{
mEmailView
.
setError
(
getString
(
R
.
string
.
error_email_taken
));
mEmailView
.
requestFocus
();
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
HONEYCOMB_MR2
)
private
void
showProgress
(
final
boolean
show
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
HONEYCOMB_MR2
)
{
int
shortAnimTime
=
getResources
().
getInteger
(
android
.
R
.
integer
.
config_shortAnimTime
);
mRegisterFormView
.
setVisibility
(
show
?
View
.
GONE
:
View
.
VISIBLE
);
mRegisterFormView
.
animate
().
setDuration
(
shortAnimTime
).
alpha
(
show
?
0
:
1
).
setListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
mRegisterFormView
.
setVisibility
(
show
?
View
.
GONE
:
View
.
VISIBLE
);
}
});
mProgressView
.
setVisibility
(
show
?
View
.
VISIBLE
:
View
.
GONE
);
mProgressView
.
animate
().
setDuration
(
shortAnimTime
).
alpha
(
show
?
1
:
0
).
setListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
mProgressView
.
setVisibility
(
show
?
View
.
VISIBLE
:
View
.
GONE
);
}
});
}
else
{
mProgressView
.
setVisibility
(
show
?
View
.
VISIBLE
:
View
.
GONE
);
mRegisterFormView
.
setVisibility
(
show
?
View
.
GONE
:
View
.
VISIBLE
);
}
}
}
app/src/main/java/com/testapp/entities/NewUserResult.java
0 → 100644
View file @
e4ac1aeb
package
com
.
testapp
.
entities
;
public
class
NewUserResult
{
boolean
success
;
String
field
;
public
NewUserResult
(
boolean
success
,
String
field
)
{
this
.
success
=
success
;
this
.
field
=
field
;
}
public
boolean
isSuccess
()
{
return
success
;
}
public
void
setSuccess
(
boolean
success
)
{
this
.
success
=
success
;
}
public
String
getField
()
{
return
field
;
}
public
void
setField
(
String
field
)
{
this
.
field
=
field
;
}
}
app/src/main/res/layout/activity_login.xml
View file @
e4ac1aeb
...
...
@@ -80,17 +80,18 @@
android:text=
"@string/action_sign_in"
/>
<Button
android:id=
"@+id/
register
_button"
android:id=
"@+id/
use_as_guest
_button"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
android:text=
"@string/action_guest"
/>
<Button
android:id=
"@+id/use_as_guest_button"
style=
"@android:style/Widget.Material.Light.Button.Borderless"
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"
/>
</LinearLayout>
...
...
app/src/main/res/layout/activity_register.xml
0 → 100644
View file @
e4ac1aeb
<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.testapp.RegisterActivity"
>
<ProgressBar
android:id=
"@+id/register_progress"
style=
"?android:attr/progressBarStyleLarge"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"8dp"
android:visibility=
"gone"
/>
<ScrollView
android:id=
"@+id/register_form"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<LinearLayout
android:id=
"@+id/email_login_form"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<ImageView
android:layout_width=
"match_parent"
android:layout_height=
"166dp"
app:srcCompat=
"@drawable/temp_logo"
android:id=
"@+id/imageView2"
android:scaleType=
"fitCenter"
/>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/email"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_email"
android:inputType=
"text"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_username"
android:inputType=
"text"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_password"
android:imeActionId=
"@+id/login"
android:imeActionLabel=
"@string/action_sign_in_short"
android:imeOptions=
"actionUnspecified"
android:inputType=
"textPassword"
android:maxLines=
"1"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/confirm_password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"@string/prompt_confirm_password"
android:imeActionId=
"@+id/register"
android:imeActionLabel=
"@string/action_sign_in_short"
android:imeOptions=
"actionUnspecified"
android:inputType=
"textPassword"
android:maxLines=
"1"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id=
"@+id/register_button"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
android:text=
"@string/action_register_short"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
app/src/main/res/values/strings.xml
View file @
e4ac1aeb
<resources>
<string
name=
"app_name"
>
Canteeneo
</string>
<
!-- Strings related to login --
>
<
string
name=
"prompt_email"
>
E-mail
</string
>
<string
name=
"prompt_username"
>
Username
</string>
<string
name=
"prompt_password"
>
Password
</string>
<string
name=
"prompt_confirm_password"
>
Confirm Password
</string>
<string
name=
"action_sign_in"
>
Sign in
</string>
<string
name=
"action_sign_in_short"
>
Sign in
</string>
<string
name=
"action_register"
>
New User? Register Here
</string>
<string
name=
"action_register"
>
Register
</string>
<string
name=
"action_register_short"
>
Register
</string>
<string
name=
"error_invalid_email"
>
This email address is invalid
</string>
<string
name=
"error_email_taken"
>
This email address is already in our database
</string>
<string
name=
"error_username_taken"
>
This username is already taken
</string>
<string
name=
"error_invalid_password"
>
This password is too short
</string>
<string
name=
"error_incorrect_password"
>
This password is incorrect
</string>
<string
name=
"error_field_required"
>
This field is required
</string>
<string
name=
"permission_rationale"
>
"Contacts permissions are needed for providing email
completions."
</string>
<string
name=
"error_password_match"
>
Passwords do not match!
</string>
<string
name=
"action_guest"
>
Use as guest
</string>
<string
name=
"title_activity_nav_drawer"
>
Main Menu
</string>
<string
name=
"drawer_1"
>
All Items
</string>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment