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
4fbdc581
Commit
4fbdc581
authored
Dec 01, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to favorite stalls
parent
4f4cf8d4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
5 deletions
+83
-5
CanteeneoApiInterface.java
app/src/main/java/com/testapp/CanteeneoApiInterface.java
+8
-0
StallViewActivity.java
app/src/main/java/com/testapp/StallViewActivity.java
+36
-2
StallFavoriteInfo.java
...src/main/java/com/testapp/entities/StallFavoriteInfo.java
+27
-0
content_stall_view.xml
app/src/main/res/layout/content_stall_view.xml
+12
-3
No files found.
app/src/main/java/com/testapp/CanteeneoApiInterface.java
View file @
4fbdc581
...
...
@@ -7,6 +7,7 @@ import com.testapp.entities.DishType;
import
com.testapp.entities.Location
;
import
com.testapp.entities.NewUserResult
;
import
com.testapp.entities.Stall
;
import
com.testapp.entities.StallFavoriteInfo
;
import
com.testapp.entities.StallReview
;
import
com.testapp.entities.Token
;
...
...
@@ -51,6 +52,13 @@ public interface CanteeneoApiInterface {
@GET
(
"api/stalls"
)
Call
<
Stall
>
getStallByName
(
@Query
(
"name"
)
String
name
);
@FormUrlEncoded
@POST
(
"api/stalls/{id}/favorites"
)
Call
<
StallFavoriteInfo
>
setStallFavorite
(
@Path
(
"id"
)
int
id
,
@Field
(
"favorited"
)
boolean
favorited
);
@GET
(
"api/stalls/{id}/favorites"
)
Call
<
StallFavoriteInfo
>
getStallFavorite
(
@Path
(
"id"
)
int
id
);
@GET
(
"api/stalls/{id}/dishes"
)
Call
<
List
<
Dish
>>
getDishesByStall
(
@Path
(
"id"
)
int
id
);
...
...
app/src/main/java/com/testapp/StallViewActivity.java
View file @
4fbdc581
...
...
@@ -8,6 +8,7 @@ import android.util.Log;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.CheckBox
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.TextView
;
...
...
@@ -16,6 +17,7 @@ import android.widget.Toast;
import
com.squareup.picasso.Picasso
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.Stall
;
import
com.testapp.entities.StallFavoriteInfo
;
import
com.testapp.entities.StallReview
;
import
java.util.ArrayList
;
...
...
@@ -32,6 +34,7 @@ public class StallViewActivity extends AppCompatActivity {
private
ArrayList
<
StallReview
>
reviews
=
new
ArrayList
<>();
private
StallReviewAdapter
srAdapter
;
private
DishAdapter
dAdapter
;
private
CheckBox
favoriteCheckbox
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -69,11 +72,43 @@ public class StallViewActivity extends AppCompatActivity {
Stall
s
=
response
.
body
();
id
=
s
.
getId
();
TextView
location
=
(
TextView
)
findViewById
(
R
.
id
.
stall_location
);
location
.
setText
(
s
.
getLocation
()
+
" "
+
id
);
location
.
setText
(
s
.
getLocation
());
TextView
description
=
(
TextView
)
findViewById
(
R
.
id
.
stall_description
);
description
.
setText
(
s
.
getDescription
());
ImageView
image
=
(
ImageView
)
findViewById
(
R
.
id
.
stall_logo
);
Picasso
.
with
(
getApplicationContext
()).
load
(
"http://"
+
getResources
().
getString
(
R
.
string
.
server_ip
)
+
":5000/static/uploads/"
+
s
.
getImagePath
()).
fit
().
centerCrop
().
into
(
image
);
favoriteCheckbox
=
(
CheckBox
)
findViewById
(
R
.
id
.
favorite_checkbox
);
favoriteCheckbox
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Call
<
StallFavoriteInfo
>
favoriteCall
=
AppUtils
.
service
.
setStallFavorite
(
id
,
favoriteCheckbox
.
isChecked
());
favoriteCall
.
enqueue
(
new
Callback
<
StallFavoriteInfo
>()
{
@Override
public
void
onResponse
(
Call
<
StallFavoriteInfo
>
call
,
Response
<
StallFavoriteInfo
>
response
)
{
favoriteCheckbox
.
setText
(
"Favorite ("
+
response
.
body
().
getCount
()
+
")"
);
}
@Override
public
void
onFailure
(
Call
<
StallFavoriteInfo
>
call
,
Throwable
t
)
{
}
});
}
});
Call
<
StallFavoriteInfo
>
countCall
=
AppUtils
.
service
.
getStallFavorite
(
id
);
countCall
.
enqueue
(
new
Callback
<
StallFavoriteInfo
>()
{
@Override
public
void
onResponse
(
Call
<
StallFavoriteInfo
>
call
,
Response
<
StallFavoriteInfo
>
response
)
{
favoriteCheckbox
.
setChecked
(
response
.
body
().
isFavorited
());
favoriteCheckbox
.
setText
(
"Favorite ("
+
response
.
body
().
getCount
()
+
")"
);
}
@Override
public
void
onFailure
(
Call
<
StallFavoriteInfo
>
call
,
Throwable
t
)
{
favoriteCheckbox
.
setText
(
"Favorite (-1)"
);
}
});
ListView
lvDishes
=
(
ListView
)
findViewById
(
R
.
id
.
stall_dishes
);
dAdapter
=
new
DishAdapter
(
StallViewActivity
.
this
,
dishes
);
...
...
@@ -116,7 +151,6 @@ public class StallViewActivity extends AppCompatActivity {
dishes
.
clear
();
dishes
.
addAll
(
newDishes
);
dAdapter
.
notifyDataSetChanged
();
Toast
.
makeText
(
StallViewActivity
.
this
,
newDishes
.
size
()
+
""
,
Toast
.
LENGTH_LONG
).
show
();
}
@Override
...
...
app/src/main/java/com/testapp/entities/StallFavoriteInfo.java
0 → 100644
View file @
4fbdc581
package
com
.
testapp
.
entities
;
public
class
StallFavoriteInfo
{
int
count
;
boolean
favorited
;
public
StallFavoriteInfo
(
int
count
,
boolean
favorited
)
{
this
.
count
=
count
;
this
.
favorited
=
favorited
;
}
public
int
getCount
()
{
return
count
;
}
public
void
setCount
(
int
count
)
{
this
.
count
=
count
;
}
public
boolean
isFavorited
()
{
return
favorited
;
}
public
void
setFavorited
(
boolean
favorited
)
{
this
.
favorited
=
favorited
;
}
}
app/src/main/res/layout/content_stall_view.xml
View file @
4fbdc581
...
...
@@ -36,6 +36,13 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:text=
"Location: "
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textSize=
"18sp"
/>
<TextView
android:text=
"Location"
android:layout_width=
"wrap_content"
...
...
@@ -43,12 +50,14 @@
android:id=
"@+id/stall_location"
android:layout_weight=
"1"
/>
<
Button
<
CheckBox
android:text=
"Favorite"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/stall_favorite"
android:layout_weight=
"1"
/>
android:layout_gravity=
"right"
android:id=
"@+id/favorite_checkbox"
android:layout_weight=
"1"
android:elevation=
"0dp"
/>
</LinearLayout>
...
...
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