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
210a9bf5
Commit
210a9bf5
authored
Nov 07, 2016
by
Tup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Listview is in the nav drawer activity na
parent
04405aae
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
126 additions
and
45 deletions
+126
-45
gradle.xml
.idea/gradle.xml
+1
-1
misc.xml
.idea/misc.xml
+0
-31
vcs.xml
.idea/vcs.xml
+1
-1
NavDrawerActivity.java
app/src/main/java/com/testapp/NavDrawerActivity.java
+110
-3
content_nav_drawer.xml
app/src/main/res/layout/content_nav_drawer.xml
+7
-0
content_search.xml
app/src/main/res/layout/content_search.xml
+1
-9
strings.xml
app/src/main/res/values/strings.xml
+6
-0
No files found.
.idea/gradle.xml
View file @
210a9bf5
...
...
@@ -5,7 +5,7 @@
<GradleProjectSettings>
<option
name=
"distributionType"
value=
"LOCAL"
/>
<option
name=
"externalProjectPath"
value=
"$PROJECT_DIR$"
/>
<option
name=
"gradleHome"
value=
"
C:\Program Files\Android
\Android Studio\gradle\gradle-2.14.1"
/>
<option
name=
"gradleHome"
value=
"
D:\Software
\Android Studio\gradle\gradle-2.14.1"
/>
<option
name=
"modules"
>
<set>
<option
value=
"$PROJECT_DIR$"
/>
...
...
.idea/misc.xml
View file @
210a9bf5
...
...
@@ -27,22 +27,6 @@
</value>
</option>
</component>
<component
name=
"ProjectInspectionProfilesVisibleTreeState"
>
<entry
key=
"Project Default"
>
<profile-state>
<expanded-state>
<State>
<id
/>
</State>
</expanded-state>
<selected-state>
<State>
<id>
Android
</id>
</State>
</selected-state>
</profile-state>
</entry>
</component>
<component
name=
"ProjectLevelVcsManager"
settingsEditedManually=
"false"
>
<OptionsSetting
value=
"true"
id=
"Add"
/>
<OptionsSetting
value=
"true"
id=
"Remove"
/>
...
...
@@ -59,19 +43,4 @@
<component
name=
"ProjectType"
>
<option
name=
"id"
value=
"Android"
/>
</component>
<component
name=
"masterDetails"
>
<states>
<state
key=
"ScopeChooserConfigurable.UI"
>
<settings>
<splitter-proportions>
<option
name=
"proportions"
>
<list>
<option
value=
"0.2"
/>
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>
\ No newline at end of file
.idea/vcs.xml
View file @
210a9bf5
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"
$PROJECT_DIR$
"
vcs=
"Git"
/>
<mapping
directory=
""
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
app/src/main/java/com/testapp/NavDrawerActivity.java
View file @
210a9bf5
package
com
.
testapp
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.support.design.widget.FloatingActionButton
;
...
...
@@ -15,11 +16,37 @@ import android.support.v7.app.AppCompatActivity;
import
android.support.v7.widget.Toolbar
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.widget.ListView
;
import
android.widget.Toast
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.testapp.entities.CData
;
import
com.testapp.entities.Dish
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
okhttp3.Cache
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
public
class
NavDrawerActivity
extends
AppCompatActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
private
CanteeneoApiInterface
service
;
private
static
Context
c
;
private
DishAdapter
adapter
;
private
ArrayList
<
Dish
>
dishes
=
new
ArrayList
<>();
public
static
String
EXTRA_MESSAGE
=
"com.testapp.MESSAGE"
;
@Override
...
...
@@ -55,9 +82,52 @@ public class NavDrawerActivity extends AppCompatActivity
public
void
goToSearchPage
(
String
query
)
{
Intent
intent
=
new
Intent
(
this
,
SearchActivity
.
class
);
intent
.
putExtra
(
"query"
,
query
);
startActivity
(
intent
);
String
dishName
=
query
;
ListView
lv
=
(
ListView
)
findViewById
(
R
.
id
.
listView
);
adapter
=
new
DishAdapter
(
this
,
dishes
);
lv
.
setAdapter
(
adapter
);
c
=
getApplicationContext
();
File
httpCacheDirectory
=
new
File
(
this
.
getCacheDir
(),
"responses"
);
int
cacheSize
=
10
*
1024
*
1024
;
// 10 MiB
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
);
getAllData
();
searchDish
(
dishName
);
}
private
void
getAllData
()
{
Call
<
CData
>
call
=
service
.
getAll
();
call
.
enqueue
(
new
Callback
<
CData
>()
{
@Override
public
void
onResponse
(
Call
<
CData
>
call
,
Response
<
CData
>
response
)
{
int
statusCode
=
response
.
code
();
CData
cdata
=
response
.
body
();
}
@Override
public
void
onFailure
(
Call
<
CData
>
call
,
Throwable
throwable
)
{
}
});
}
@Override
...
...
@@ -128,4 +198,41 @@ public class NavDrawerActivity extends AppCompatActivity
drawer
.
closeDrawer
(
GravityCompat
.
START
);
return
true
;
}
private
void
searchDish
(
String
name
)
{
Call
<
List
<
Dish
>>
call
=
service
.
searchByName
(
name
);
call
.
enqueue
(
new
Callback
<
List
<
Dish
>>()
{
@Override
public
void
onResponse
(
Call
<
List
<
Dish
>>
call
,
Response
<
List
<
Dish
>>
response
)
{
List
<
Dish
>
newDishes
=
response
.
body
();
dishes
.
clear
();
dishes
.
addAll
(
newDishes
);
adapter
.
notifyDataSetChanged
();
}
@Override
public
void
onFailure
(
Call
<
List
<
Dish
>>
call
,
Throwable
t
)
{
}
});
}
private
static
final
Interceptor
REWRITE_CACHE_CONTROL_INTERCEPTOR
=
new
Interceptor
()
{
@Override
public
okhttp3
.
Response
intercept
(
Chain
chain
)
throws
IOException
{
okhttp3
.
Response
origResponse
=
chain
.
proceed
(
chain
.
request
());
if
(
AppUtils
.
isNetworkAvailable
(
c
))
{
int
maxAge
=
60
;
// read from cache for 1 minute
return
origResponse
.
newBuilder
()
.
header
(
"Cache-Control"
,
"public, max-age="
+
maxAge
)
.
build
();
}
else
{
int
maxStale
=
60
*
60
*
24
*
28
;
// tolerate 4-weeks stale
return
origResponse
.
newBuilder
()
.
header
(
"Cache-Control"
,
"public, only-if-cached, max-stale="
+
maxStale
)
.
build
();
}
}
};
}
app/src/main/res/layout/content_nav_drawer.xml
View file @
210a9bf5
...
...
@@ -13,4 +13,11 @@
tools:context=
"com.testapp.NavDrawerActivity"
tools:showIn=
"@layout/app_bar_nav_drawer"
>
<ListView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/listView"
android:layout_alignParentTop=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
/>
</RelativeLayout>
app/src/main/res/layout/content_search.xml
View file @
210a9bf5
...
...
@@ -11,13 +11,5 @@
android:paddingTop=
"@dimen/activity_vertical_margin"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:context=
"com.testapp.SearchActivity"
tools:showIn=
"@layout/activity_search"
>
<ListView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/listView"
android:layout_alignParentTop=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
/>
tools:showIn=
"@layout/activity_search"
>
</RelativeLayout>
app/src/main/res/values/strings.xml
View file @
210a9bf5
...
...
@@ -25,4 +25,10 @@
<string
name=
"title_activity_search"
>
SearchActivity
</string>
<string
name=
"server_ip"
>
192.168.43.250
</string>
<string-array
name=
"sampleEntries"
>
<item>
Item 1
</item>
<item>
Item 2
</item>
<item>
Item 3
</item>
</string-array>
</resources>
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