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
f9f1baee
Commit
f9f1baee
authored
Nov 23, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make filter checkboxes get data from server
parent
f5c51e6b
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
212 additions
and
124 deletions
+212
-124
CanteeneoApiInterface.java
app/src/main/java/com/testapp/CanteeneoApiInterface.java
+12
-0
NavDrawerActivity.java
app/src/main/java/com/testapp/NavDrawerActivity.java
+105
-22
Cuisine.java
app/src/main/java/com/testapp/entities/Cuisine.java
+31
-0
DishType.java
app/src/main/java/com/testapp/entities/DishType.java
+31
-0
activity_nav_drawer.xml
app/src/main/res/layout/activity_nav_drawer.xml
+22
-101
search_checkbox.xml
app/src/main/res/layout/search_checkbox.xml
+10
-0
strings.xml
app/src/main/res/values/strings.xml
+1
-1
No files found.
app/src/main/java/com/testapp/CanteeneoApiInterface.java
View file @
f9f1baee
package
com
.
testapp
;
package
com
.
testapp
;
import
com.testapp.entities.CData
;
import
com.testapp.entities.CData
;
import
com.testapp.entities.Cuisine
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.DishType
;
import
com.testapp.entities.Location
;
import
java.util.List
;
import
java.util.List
;
...
@@ -26,6 +29,15 @@ public interface CanteeneoApiInterface {
...
@@ -26,6 +29,15 @@ public interface CanteeneoApiInterface {
@GET
(
"api/search/dish"
)
@GET
(
"api/search/dish"
)
Call
<
List
<
Dish
>>
searchByName
(
@Query
(
"name"
)
String
name
);
Call
<
List
<
Dish
>>
searchByName
(
@Query
(
"name"
)
String
name
);
@GET
(
"api/locations"
)
Call
<
List
<
Location
>>
getLocations
();
@GET
(
"api/types"
)
Call
<
List
<
DishType
>>
getDishTypes
();
@GET
(
"api/cuisines"
)
Call
<
List
<
Cuisine
>>
getCuisines
();
// @GET("static/uploads/{filename}")
// @GET("static/uploads/{filename}")
// Call<ResponseBody> downloadImage(@Path("filename") String filename);
// Call<ResponseBody> downloadImage(@Path("filename") String filename);
...
...
app/src/main/java/com/testapp/NavDrawerActivity.java
View file @
f9f1baee
...
@@ -7,6 +7,8 @@ import android.support.design.widget.FloatingActionButton;
...
@@ -7,6 +7,8 @@ import android.support.design.widget.FloatingActionButton;
import
android.support.design.widget.Snackbar
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.view.MenuItemCompat
;
import
android.support.v4.view.MenuItemCompat
;
import
android.support.v7.widget.SearchView
;
import
android.support.v7.widget.SearchView
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.support.design.widget.NavigationView
;
import
android.support.design.widget.NavigationView
;
import
android.support.v4.view.GravityCompat
;
import
android.support.v4.view.GravityCompat
;
...
@@ -17,13 +19,18 @@ import android.support.v7.widget.Toolbar;
...
@@ -17,13 +19,18 @@ import android.support.v7.widget.Toolbar;
import
android.view.Menu
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.view.MenuItem
;
import
android.widget.ArrayAdapter
;
import
android.widget.ArrayAdapter
;
import
android.widget.CheckBox
;
import
android.widget.LinearLayout
;
import
android.widget.ListView
;
import
android.widget.ListView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
com.testapp.entities.CData
;
import
com.testapp.entities.CData
;
import
com.testapp.entities.Cuisine
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.DishType
;
import
com.testapp.entities.Location
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -53,6 +60,29 @@ public class NavDrawerActivity extends AppCompatActivity
...
@@ -53,6 +60,29 @@ public class NavDrawerActivity extends AppCompatActivity
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
File
httpCacheDirectory
=
new
File
(
this
.
getCacheDir
(),
"responses"
);
int
cacheSize
=
10
*
1024
*
1024
;
// 10MiB
Cache
cache
=
new
Cache
(
httpCacheDirectory
,
cacheSize
);
OkHttpClient
client
=
new
OkHttpClient
().
newBuilder
()
.
addNetworkInterceptor
(
REWRITE_CACHE_CONTROL_INTERCEPTOR
)
.
cache
(
cache
)
.
build
();
Gson
gson
=
new
GsonBuilder
()
.
setDateFormat
(
"yyyy-MM-dd'T'HH:mm:ssZ"
)
.
create
();
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
"http://"
+
getResources
().
getString
(
R
.
string
.
server_ip
)
+
":5000/"
)
.
client
(
client
)
.
addConverterFactory
(
GsonConverterFactory
.
create
(
gson
))
.
build
();
service
=
retrofit
.
create
(
CanteeneoApiInterface
.
class
);
c
=
getApplicationContext
();
setContentView
(
R
.
layout
.
activity_nav_drawer
);
setContentView
(
R
.
layout
.
activity_nav_drawer
);
Toolbar
toolbar
=
(
Toolbar
)
findViewById
(
R
.
id
.
toolbar
);
Toolbar
toolbar
=
(
Toolbar
)
findViewById
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
setSupportActionBar
(
toolbar
);
...
@@ -79,38 +109,91 @@ public class NavDrawerActivity extends AppCompatActivity
...
@@ -79,38 +109,91 @@ public class NavDrawerActivity extends AppCompatActivity
String
message
=
intent
.
getStringExtra
(
LoginActivity
.
EXTRA_MESSAGE
);
String
message
=
intent
.
getStringExtra
(
LoginActivity
.
EXTRA_MESSAGE
);
Toast
.
makeText
(
NavDrawerActivity
.
this
,
message
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
NavDrawerActivity
.
this
,
message
,
Toast
.
LENGTH_SHORT
).
show
();
populateDishTypeFilters
();
populateCuisineFilters
();
populateLocationFilters
();
}
}
public
void
goToSearchPage
(
String
query
)
{
public
void
populateDishTypeFilters
()
{
final
LinearLayout
type_checkboxes
=
(
LinearLayout
)
findViewById
(
R
.
id
.
type_checkboxes
);
type_checkboxes
.
removeAllViewsInLayout
();
String
dishName
=
query
;
Call
<
List
<
DishType
>>
call
=
service
.
getDishTypes
();
call
.
enqueue
(
new
Callback
<
List
<
DishType
>>()
{
@Override
public
void
onResponse
(
Call
<
List
<
DishType
>>
call
,
Response
<
List
<
DishType
>>
response
)
{
List
<
DishType
>
types
=
response
.
body
();
LayoutInflater
checkboxInflater
=
(
LayoutInflater
)
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
);
for
(
DishType
t:
types
)
{
CheckBox
checkbox
=
(
CheckBox
)
checkboxInflater
.
inflate
(
R
.
layout
.
search_checkbox
,
null
);
checkbox
.
setId
(
t
.
getId
());
checkbox
.
setText
(
t
.
getName
());
type_checkboxes
.
addView
(
checkbox
);
}
}
ListView
lv
=
(
ListView
)
findViewById
(
R
.
id
.
listView
);
@Override
adapter
=
new
DishAdapter
(
this
,
dishes
);
public
void
onFailure
(
Call
<
List
<
DishType
>>
call
,
Throwable
t
)
{
lv
.
setAdapter
(
adapter
);
}
});
}
c
=
getApplicationContext
();
public
void
populateCuisineFilters
()
{
final
LinearLayout
cuisine_checkboxes
=
(
LinearLayout
)
findViewById
(
R
.
id
.
cuisine_checkboxes
);
cuisine_checkboxes
.
removeAllViewsInLayout
();
File
httpCacheDirectory
=
new
File
(
this
.
getCacheDir
(),
"responses"
);
Call
<
List
<
Cuisine
>>
call
=
service
.
getCuisines
();
int
cacheSize
=
10
*
1024
*
1024
;
// 10MiB
call
.
enqueue
(
new
Callback
<
List
<
Cuisine
>>()
{
Cache
cache
=
new
Cache
(
httpCacheDirectory
,
cacheSize
);
@Override
public
void
onResponse
(
Call
<
List
<
Cuisine
>>
call
,
Response
<
List
<
Cuisine
>>
response
)
{
List
<
Cuisine
>
cuisines
=
response
.
body
();
LayoutInflater
checkboxInflater
=
(
LayoutInflater
)
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
);
for
(
Cuisine
c:
cuisines
)
{
CheckBox
checkbox
=
(
CheckBox
)
checkboxInflater
.
inflate
(
R
.
layout
.
search_checkbox
,
null
);
checkbox
.
setId
(
c
.
getId
());
checkbox
.
setText
(
c
.
getName
());
cuisine_checkboxes
.
addView
(
checkbox
);
}
}
OkHttpClient
client
=
new
OkHttpClient
().
newBuilder
()
@Override
.
addNetworkInterceptor
(
REWRITE_CACHE_CONTROL_INTERCEPTOR
)
public
void
onFailure
(
Call
<
List
<
Cuisine
>>
call
,
Throwable
t
)
{
.
cache
(
cache
)
}
.
build
();
});
}
Gson
gson
=
new
GsonBuilder
()
public
void
populateLocationFilters
()
{
.
setDateFormat
(
"yyyy-MM-dd'T'HH:mm:ssZ"
)
final
LinearLayout
location_checkboxes
=
(
LinearLayout
)
findViewById
(
R
.
id
.
location_checkboxes
);
.
create
();
location_checkboxes
.
removeAllViewsInLayout
();
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
Call
<
List
<
Location
>>
call
=
service
.
getLocations
();
.
baseUrl
(
"http://"
+
getResources
().
getString
(
R
.
string
.
server_ip
)
+
":5000/"
)
call
.
enqueue
(
new
Callback
<
List
<
Location
>>()
{
.
client
(
client
)
@Override
.
addConverterFactory
(
GsonConverterFactory
.
create
(
gson
))
public
void
onResponse
(
Call
<
List
<
Location
>>
call
,
Response
<
List
<
Location
>>
response
)
{
.
build
();
List
<
Location
>
locations
=
response
.
body
();
LayoutInflater
checkboxInflater
=
(
LayoutInflater
)
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
);
for
(
Location
l:
locations
)
{
CheckBox
checkbox
=
(
CheckBox
)
checkboxInflater
.
inflate
(
R
.
layout
.
search_checkbox
,
null
);
checkbox
.
setId
(
l
.
getId
());
checkbox
.
setText
(
l
.
getName
());
location_checkboxes
.
addView
(
checkbox
);
}
}
service
=
retrofit
.
create
(
CanteeneoApiInterface
.
class
);
@Override
public
void
onFailure
(
Call
<
List
<
Location
>>
call
,
Throwable
t
)
{
}
});
}
public
void
goToSearchPage
(
String
query
)
{
String
dishName
=
query
;
ListView
lv
=
(
ListView
)
findViewById
(
R
.
id
.
listView
);
adapter
=
new
DishAdapter
(
this
,
dishes
);
lv
.
setAdapter
(
adapter
);
getAllData
();
getAllData
();
searchDish
(
dishName
);
searchDish
(
dishName
);
...
...
app/src/main/java/com/testapp/entities/Cuisine.java
0 → 100644
View file @
f9f1baee
package
com
.
testapp
.
entities
;
/**
* Created by candy on 10/19/16.
*/
public
class
Cuisine
{
int
id
;
String
name
;
public
Cuisine
(
int
id
,
String
name
)
{
this
.
id
=
id
;
this
.
name
=
name
;
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
app/src/main/java/com/testapp/entities/DishType.java
0 → 100644
View file @
f9f1baee
package
com
.
testapp
.
entities
;
/**
* Created by candy on 10/19/16.
*/
public
class
DishType
{
int
id
;
String
name
;
public
DishType
(
int
id
,
String
name
)
{
this
.
id
=
id
;
this
.
name
=
name
;
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
app/src/main/res/layout/activity_nav_drawer.xml
View file @
f9f1baee
...
@@ -79,42 +79,15 @@
...
@@ -79,42 +79,15 @@
android:paddingTop=
"5dp"
android:paddingTop=
"5dp"
android:paddingBottom=
"5dp"
/>
android:paddingBottom=
"5dp"
/>
<CheckBox
android:typeface=
"monospace"
android:text=
"@string/drawer_3_1"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/nav_main"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<CheckBox
android:typeface=
"monospace"
android:text=
"@string/drawer_3_2"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/nav_drink"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<CheckBox
android:typeface=
"monospace"
android:text=
"@string/drawer_3_3"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/nav_dessert"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/type_checkboxes"
android:orientation=
"vertical"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
</LinearLayout>
<TextView
<TextView
android:text=
"Cuisine"
android:text=
"Cuisine"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
@@ -127,38 +100,12 @@
...
@@ -127,38 +100,12 @@
android:paddingBottom=
"5dp"
android:paddingBottom=
"5dp"
android:paddingLeft=
"10dp"
/>
android:paddingLeft=
"10dp"
/>
<CheckBox
<LinearLayout
android:text=
"American"
android:id=
"@+id/cuisine_checkboxes"
android:layout_width=
"match_parent"
android:orientation=
"vertical"
android:layout_height=
"wrap_content"
android:id=
"@+id/cuisine_american"
android:typeface=
"monospace"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<CheckBox
android:text=
"Japanese"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"match_parent"
>
android:id=
"@+id/cuisine_japanese"
android:typeface=
"monospace"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<CheckBox
android:text=
"Chinese"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/cuisine_chinese"
android:typeface=
"monospace"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
</LinearLayout>
</LinearLayout>
<TextView
<TextView
...
@@ -191,39 +138,13 @@
...
@@ -191,39 +138,13 @@
android:paddingLeft=
"10dp"
android:paddingLeft=
"10dp"
android:paddingTop=
"5dp"
android:paddingTop=
"5dp"
android:paddingBottom=
"5dp"
/>
android:paddingBottom=
"5dp"
/>
<LinearLayout
<CheckBox
android:id=
"@+id/location_checkboxes"
android:typeface=
"monospace"
android:orientation=
"vertical"
android:text=
"@string/drawer_5_1"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/nav_gonzaga"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<CheckBox
android:typeface=
"monospace"
android:text=
"@string/drawer_5_2"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"match_parent"
>
android:id=
"@+id/nav_jsec"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<CheckBox
</LinearLayout>
android:text=
"@string/drawer_5_3"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/nav_zekaf"
android:typeface=
"monospace"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
<Button
<Button
android:text=
"@string/hint_search"
android:text=
"@string/hint_search"
...
...
app/src/main/res/layout/search_checkbox.xml
0 → 100644
View file @
f9f1baee
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:typeface=
"monospace"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:checked=
"false"
android:button=
"@null"
android:drawableRight=
"?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft=
"20dp"
/>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
f9f1baee
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
<string
name=
"action_settings"
>
Settings
</string>
<string
name=
"action_settings"
>
Settings
</string>
<string
name=
"title_activity_search"
>
SearchActivity
</string>
<string
name=
"title_activity_search"
>
SearchActivity
</string>
<string
name=
"server_ip"
>
192.168.
43.250
</string>
<string
name=
"server_ip"
>
192.168.
11.18
</string>
<string-array
name=
"sampleEntries"
>
<string-array
name=
"sampleEntries"
>
<item>
Item 111
</item>
<item>
Item 111
</item>
...
...
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