Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
c7704d02
Commit
c7704d02
authored
May 30, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store full body in database
parent
cdd4b1e0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DbDao.java
...src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DbDao.java
+6
-0
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragment/BodyFragment.java
...va/in/ac/iitb/gymkhana/iitbapp/fragment/BodyFragment.java
+15
-1
No files found.
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DbDao.java
View file @
c7704d02
...
@@ -21,6 +21,9 @@ public interface DbDao {
...
@@ -21,6 +21,9 @@ public interface DbDao {
@Query
(
"SELECT * FROM venues"
)
@Query
(
"SELECT * FROM venues"
)
List
<
Venue
>
getAllVenues
();
List
<
Venue
>
getAllVenues
();
@Query
(
"SELECT * FROM bodies WHERE id == :id"
)
public
Body
[]
getBody
(
String
id
);
@Query
(
"SELECT COUNT(*) from events"
)
@Query
(
"SELECT COUNT(*) from events"
)
int
countEvents
();
int
countEvents
();
...
@@ -36,6 +39,9 @@ public interface DbDao {
...
@@ -36,6 +39,9 @@ public interface DbDao {
@Insert
@Insert
void
insertBodies
(
List
<
Body
>
bodies
);
void
insertBodies
(
List
<
Body
>
bodies
);
@Insert
void
insertBody
(
Body
body
);
@Insert
@Insert
void
insertVenues
(
List
<
Venue
>
venues
);
void
insertVenues
(
List
<
Venue
>
venues
);
...
...
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/fragment/BodyFragment.java
View file @
c7704d02
...
@@ -15,6 +15,7 @@ import in.ac.iitb.gymkhana.iitbapp.MainActivity;
...
@@ -15,6 +15,7 @@ import in.ac.iitb.gymkhana.iitbapp.MainActivity;
import
in.ac.iitb.gymkhana.iitbapp.R
;
import
in.ac.iitb.gymkhana.iitbapp.R
;
import
in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface
;
import
in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface
;
import
in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator
;
import
in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator
;
import
in.ac.iitb.gymkhana.iitbapp.data.AppDatabase
;
import
in.ac.iitb.gymkhana.iitbapp.data.Body
;
import
in.ac.iitb.gymkhana.iitbapp.data.Body
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
...
@@ -30,6 +31,7 @@ public class BodyFragment extends Fragment {
...
@@ -30,6 +31,7 @@ public class BodyFragment extends Fragment {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private
static
final
String
ARG_BODY
=
"body"
;
private
static
final
String
ARG_BODY
=
"body"
;
private
AppDatabase
appDatabase
;
String
TAG
=
"BodyFragment"
;
String
TAG
=
"BodyFragment"
;
// TODO: Rename and change types of parameters
// TODO: Rename and change types of parameters
...
@@ -67,8 +69,17 @@ public class BodyFragment extends Fragment {
...
@@ -67,8 +69,17 @@ public class BodyFragment extends Fragment {
@Override
@Override
public
void
onStart
()
{
public
void
onStart
()
{
super
.
onStart
();
super
.
onStart
();
/* Initialize */
appDatabase
=
AppDatabase
.
getAppDatabase
(
getContext
());
Body
[]
inLocalDb
=
appDatabase
.
dbDao
().
getBody
(
min_body
.
getBodyID
());
if
(
inLocalDb
.
length
>
0
)
{
displayBody
(
inLocalDb
[
0
]);
}
else
{
updateBody
();
updateBody
();
}
}
}
private
void
updateBody
()
{
private
void
updateBody
()
{
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
RetrofitInterface
retrofitInterface
=
ServiceGenerator
.
createService
(
RetrofitInterface
.
class
);
...
@@ -77,6 +88,9 @@ public class BodyFragment extends Fragment {
...
@@ -77,6 +88,9 @@ public class BodyFragment extends Fragment {
public
void
onResponse
(
Call
<
Body
>
call
,
Response
<
Body
>
response
)
{
public
void
onResponse
(
Call
<
Body
>
call
,
Response
<
Body
>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
Body
body
=
response
.
body
();
Body
body
=
response
.
body
();
appDatabase
.
dbDao
().
insertBody
(
body
);
displayBody
(
body
);
displayBody
(
body
);
}
}
}
}
...
...
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