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
fff5654f
Commit
fff5654f
authored
Nov 23, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove redundant code in checkboxes by using generics and interfaces
parent
b229f697
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
73 deletions
+30
-73
NavDrawerActivity.java
app/src/main/java/com/testapp/NavDrawerActivity.java
+19
-66
Cuisine.java
app/src/main/java/com/testapp/entities/Cuisine.java
+1
-1
DishType.java
app/src/main/java/com/testapp/entities/DishType.java
+1
-1
Filter.java
app/src/main/java/com/testapp/entities/Filter.java
+8
-0
Location.java
app/src/main/java/com/testapp/entities/Location.java
+1
-1
activity_nav_drawer.xml
app/src/main/res/layout/activity_nav_drawer.xml
+0
-1
strings.xml
app/src/main/res/values/strings.xml
+0
-3
No files found.
app/src/main/java/com/testapp/NavDrawerActivity.java
View file @
fff5654f
...
...
@@ -26,6 +26,7 @@ import com.google.gson.GsonBuilder;
import
com.testapp.entities.Cuisine
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.DishType
;
import
com.testapp.entities.Filter
;
import
com.testapp.entities.Location
;
import
java.io.File
;
import
java.io.IOException
;
...
...
@@ -41,9 +42,7 @@ import retrofit2.Response;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
public
class
NavDrawerActivity
extends
AppCompatActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
public
class
NavDrawerActivity
extends
AppCompatActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
private
CanteeneoApiInterface
service
;
private
static
Context
c
;
...
...
@@ -104,81 +103,35 @@ public class NavDrawerActivity extends AppCompatActivity
String
message
=
intent
.
getStringExtra
(
LoginActivity
.
EXTRA_MESSAGE
);
Toast
.
makeText
(
NavDrawerActivity
.
this
,
message
,
Toast
.
LENGTH_SHORT
).
show
();
populate
DishTypeFilters
(
);
populate
CuisineFilters
(
);
populate
LocationFilters
(
);
populate
Filter
(
service
.
getDishTypes
(),
R
.
id
.
type_checkboxes
);
populate
Filter
(
service
.
getCuisines
(),
R
.
id
.
cuisine_checkboxes
);
populate
Filter
(
service
.
getLocations
(),
R
.
id
.
location_checkboxes
);
}
public
void
populateDishTypeFilters
(
)
{
final
LinearLayout
type_checkboxes
=
(
LinearLayout
)
findViewById
(
R
.
id
.
type_checkboxes
);
type_
checkboxes
.
removeAllViewsInLayout
();
public
<
T
extends
Filter
>
void
populateFilter
(
Call
<
List
<
T
>>
call
,
int
layout_id
)
{
final
LinearLayout
checkboxes
=
(
LinearLayout
)
findViewById
(
layout_id
);
checkboxes
.
removeAllViewsInLayout
();
Call
<
List
<
DishType
>>
call
=
service
.
getDishTypes
();
call
.
enqueue
(
new
Callback
<
List
<
DishType
>>()
{
call
.
enqueue
(
new
Callback
<
List
<
T
>>()
{
@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
);
public
void
onResponse
(
Call
<
List
<
T
>>
call
,
Response
<
List
<
T
>>
response
)
{
List
<
T
>
filters
=
response
.
body
();
LayoutInflater
inflater
=
(
LayoutInflater
)
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
);
for
(
T
filter:
filters
)
{
CheckBox
checkbox
=
(
CheckBox
)
inflater
.
inflate
(
R
.
layout
.
search_checkbox
,
null
);
checkbox
.
setId
(
filter
.
getId
());
checkbox
.
setText
(
filter
.
getName
());
checkbox
.
setChecked
(
true
);
checkboxes
.
addView
(
checkbox
);
}
}
@Override
public
void
onFailure
(
Call
<
List
<
DishType
>>
call
,
Throwable
t
)
{
}
});
}
public
void
populateCuisineFilters
()
{
final
LinearLayout
cuisine_checkboxes
=
(
LinearLayout
)
findViewById
(
R
.
id
.
cuisine_checkboxes
);
cuisine_checkboxes
.
removeAllViewsInLayout
();
Call
<
List
<
Cuisine
>>
call
=
service
.
getCuisines
();
call
.
enqueue
(
new
Callback
<
List
<
Cuisine
>>()
{
@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
);
}
}
public
void
onFailure
(
Call
<
List
<
T
>>
call
,
Throwable
t
)
{
@Override
public
void
onFailure
(
Call
<
List
<
Cuisine
>>
call
,
Throwable
t
)
{
}
});
}
public
void
populateLocationFilters
()
{
final
LinearLayout
location_checkboxes
=
(
LinearLayout
)
findViewById
(
R
.
id
.
location_checkboxes
);
location_checkboxes
.
removeAllViewsInLayout
();
Call
<
List
<
Location
>>
call
=
service
.
getLocations
();
call
.
enqueue
(
new
Callback
<
List
<
Location
>>()
{
@Override
public
void
onResponse
(
Call
<
List
<
Location
>>
call
,
Response
<
List
<
Location
>>
response
)
{
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
);
}
}
@Override
public
void
onFailure
(
Call
<
List
<
Location
>>
call
,
Throwable
t
)
{
}
});
}
...
...
app/src/main/java/com/testapp/entities/Cuisine.java
View file @
fff5654f
package
com
.
testapp
.
entities
;
public
class
Cuisine
{
public
class
Cuisine
implements
Filter
{
int
id
;
String
name
;
...
...
app/src/main/java/com/testapp/entities/DishType.java
View file @
fff5654f
package
com
.
testapp
.
entities
;
public
class
DishType
{
public
class
DishType
implements
Filter
{
int
id
;
String
name
;
...
...
app/src/main/java/com/testapp/entities/Filter.java
0 → 100644
View file @
fff5654f
package
com
.
testapp
.
entities
;
public
interface
Filter
{
int
getId
();
void
setId
(
int
id
);
String
getName
();
void
setName
(
String
name
);
}
app/src/main/java/com/testapp/entities/Location.java
View file @
fff5654f
package
com
.
testapp
.
entities
;
public
class
Location
{
public
class
Location
implements
Filter
{
int
id
;
String
name
;
...
...
app/src/main/res/layout/activity_nav_drawer.xml
View file @
fff5654f
...
...
@@ -85,7 +85,6 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
</LinearLayout>
<TextView
...
...
app/src/main/res/values/strings.xml
View file @
fff5654f
...
...
@@ -26,9 +26,6 @@
<string
name=
"drawer_5_2"
>
JSEC
</string>
<string
name=
"drawer_5_3"
>
Zekaf
</string>
<string
name=
"drawer_6"
>
Cuisine
</string>
<string
name=
"drawer_6_1"
>
American
</string>
<string
name=
"drawer_6_2"
>
Japanese
</string>
<string
name=
"drawer_6_3"
>
Chinese
</string>
<string
name=
"hint_search"
>
Search
</string>
<string
name=
"navigation_drawer_open"
>
Open navigation drawer
</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