Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-android
Commits
f2806d13
Commit
f2806d13
authored
Dec 28, 2016
by
Robert Hitt
Browse files
Fixed the Json deserialization
- Also changed the .gitignore and readme's slightly
parent
5b82c670
Changes
9
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
f2806d13
...
...
@@ -34,9 +34,7 @@ captures/
# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/libraries
.idea/
# Keystore files
*.jks
...
...
README.md
View file @
f2806d13
...
...
@@ -28,7 +28,7 @@ To get started, you'll need the following installed:
*
[
Android Studio
](
https://developer.android.com/studio/index.html
)
```
bash
git clone http://git.gmu.edu/srct/whats-open-android.git
git clone http
s
://git.gmu.edu/srct/whats-open-android.git
```
That's about it. From there you can use Android Studio's built in VCS tools,
...
...
app/src/main/java/srct/whatsopen/model/Facility.java
View file @
f2806d13
...
...
@@ -9,17 +9,23 @@ import io.realm.annotations.PrimaryKey;
public
class
Facility
extends
RealmObject
{
@PrimaryKey
private
String
name
;
@SerializedName
(
"name"
)
private
String
mName
;
@SerializedName
(
"location"
)
private
String
mLocation
;
@SerializedName
(
"main_schedule"
)
private
MainSchedule
mMainSchedule
;
private
boolean
isFavorited
;
private
RealmList
<
OpenTimes
>
mOpenTimes
;
public
String
getName
()
{
return
n
ame
;
return
mN
ame
;
}
public
void
setName
(
String
name
)
{
this
.
n
ame
=
name
;
this
.
mN
ame
=
name
;
}
public
boolean
isFavorited
()
{
...
...
@@ -30,11 +36,19 @@ public class Facility extends RealmObject {
isFavorited
=
favorited
;
}
public
RealmList
<
OpenTimes
>
getOpenTimes
()
{
return
mOpenTimes
;
public
String
getLocation
()
{
return
mLocation
;
}
public
void
setLocation
(
String
location
)
{
mLocation
=
location
;
}
public
MainSchedule
getMainSchedule
()
{
return
mMainSchedule
;
}
public
void
set
OpenTimes
(
RealmList
<
OpenTimes
>
openTimes
)
{
this
.
mOpenTimes
=
openTimes
;
public
void
set
MainSchedule
(
MainSchedule
mainSchedule
)
{
mMainSchedule
=
mainSchedule
;
}
}
app/src/main/java/srct/whatsopen/model/MainSchedule.java
0 → 100644
View file @
f2806d13
package
srct.whatsopen.model
;
import
com.google.gson.annotations.SerializedName
;
import
io.realm.RealmList
;
import
io.realm.RealmObject
;
public
class
MainSchedule
extends
RealmObject
{
@SerializedName
(
"open_times"
)
private
RealmList
<
OpenTimes
>
mOpenTimesList
;
public
RealmList
<
OpenTimes
>
getOpenTimesList
()
{
return
mOpenTimesList
;
}
public
void
setOpenTimesList
(
RealmList
<
OpenTimes
>
openTimesList
)
{
mOpenTimesList
=
openTimesList
;
}
}
app/src/main/java/srct/whatsopen/service/WhatsOpenClient.java
→
app/src/main/java/srct/whatsopen/service
s
/WhatsOpenClient.java
View file @
f2806d13
package
srct.whatsopen.service
;
import
com.google.gson.ExclusionStrategy
;
import
com.google.gson.FieldAttributes
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.reflect.TypeToken
;
import
io.realm.RealmList
;
import
io.realm.RealmObject
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
srct.whatsopen.util.OpenTimesDeserializer
;
import
srct.whatsopen.util.OpenTimesListDeserializer
;
import
srct.whatsopen.model.OpenTimes
;
/**
* Singleton for Retrofit instance
*/
public
class
WhatsOpenClient
{
private
static
volatile
Retrofit
sRetrofit
=
null
;
private
static
WhatsOpenService
mService
;
private
static
final
String
BASE_URL
=
"https://whatsopen.gmu.edu/api/"
;
public
WhatsOpenClient
()
{
}
// Returns a singleton of WhatsOpenService
public
static
WhatsOpenService
getInstance
()
{
if
(
mService
==
null
)
{
synchronized
(
WhatsOpenClient
.
class
)
{
if
(
mService
==
null
)
{
mService
=
getRetrofit
().
create
(
WhatsOpenService
.
class
);
}
}
}
return
mService
;
}
// Configures Retrofit's JSON parsing logic
private
synchronized
static
Retrofit
getRetrofit
()
{
if
(
sRetrofit
==
null
)
{
synchronized
(
WhatsOpenClient
.
class
)
{
if
(
sRetrofit
==
null
)
{
Gson
gson
=
new
GsonBuilder
()
// Ensures Retrofit plays nicely with Realm
.
setExclusionStrategies
(
new
ExclusionStrategy
()
{
@Override
public
boolean
shouldSkipField
(
FieldAttributes
f
)
{
return
f
.
getDeclaredClass
().
equals
(
RealmObject
.
class
);
}
@Override
public
boolean
shouldSkipClass
(
Class
<?>
clazz
)
{
return
false
;
}
})
.
registerTypeAdapter
(
OpenTimes
.
class
,
new
OpenTimesDeserializer
())
.
registerTypeAdapter
(
new
TypeToken
<
RealmList
<
OpenTimes
>>(){}.
getType
(),
new
OpenTimesListDeserializer
())
.
create
();
sRetrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
BASE_URL
)
.
addConverterFactory
(
GsonConverterFactory
.
create
(
gson
))
.
build
();
}
}
}
return
sRetrofit
;
}
}
package
srct.whatsopen.services
;
import
com.google.gson.ExclusionStrategy
;
import
com.google.gson.FieldAttributes
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
io.realm.RealmObject
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
/**
* Singleton for Retrofit instance
*/
public
class
WhatsOpenClient
{
private
static
volatile
Retrofit
sRetrofit
=
null
;
private
static
WhatsOpenService
mService
;
private
static
final
String
BASE_URL
=
"https://whatsopen.gmu.edu/api/"
;
public
WhatsOpenClient
()
{
}
// Returns a singleton of WhatsOpenService
public
static
WhatsOpenService
getInstance
()
{
if
(
mService
==
null
)
{
synchronized
(
WhatsOpenClient
.
class
)
{
if
(
mService
==
null
)
{
mService
=
getRetrofit
().
create
(
WhatsOpenService
.
class
);
}
}
}
return
mService
;
}
// Configures Retrofit's JSON parsing logic
private
synchronized
static
Retrofit
getRetrofit
()
{
if
(
sRetrofit
==
null
)
{
synchronized
(
WhatsOpenClient
.
class
)
{
if
(
sRetrofit
==
null
)
{
Gson
gson
=
new
GsonBuilder
()
// Ensures Retrofit plays nicely with Realm
.
setExclusionStrategies
(
new
ExclusionStrategy
()
{
@Override
public
boolean
shouldSkipField
(
FieldAttributes
f
)
{
return
f
.
getDeclaredClass
().
equals
(
RealmObject
.
class
);
}
@Override
public
boolean
shouldSkipClass
(
Class
<?>
clazz
)
{
return
false
;
}
})
.
create
();
sRetrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
BASE_URL
)
.
addConverterFactory
(
GsonConverterFactory
.
create
(
gson
))
.
build
();
}
}
}
return
sRetrofit
;
}
}
app/src/main/java/srct/whatsopen/service/WhatsOpenService.java
→
app/src/main/java/srct/whatsopen/service
s
/WhatsOpenService.java
View file @
f2806d13
package
srct.whatsopen.service
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.http.GET
;
import
srct.whatsopen.model.Facility
;
// Interface for Retrofit's Http request
public
interface
WhatsOpenService
{
@GET
(
"
schedul
es"
)
Call
<
List
<
Facility
>>
facilityList
();
}
package
srct.whatsopen.service
s
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.http.GET
;
import
srct.whatsopen.model.Facility
;
// Interface for Retrofit's Http request
public
interface
WhatsOpenService
{
@GET
(
"
faciliti
es"
)
Call
<
List
<
Facility
>>
facilityList
();
}
app/src/main/java/srct/whatsopen/ui/MainActivity.java
View file @
f2806d13
...
...
@@ -16,8 +16,8 @@ import retrofit2.Callback;
import
retrofit2.Response
;
import
srct.whatsopen.R
;
import
srct.whatsopen.service.WhatsOpenClient
;
import
srct.whatsopen.service.WhatsOpenService
;
import
srct.whatsopen.service
s
.WhatsOpenClient
;
import
srct.whatsopen.service
s
.WhatsOpenService
;
import
srct.whatsopen.model.Facility
;
public
class
MainActivity
extends
AppCompatActivity
{
...
...
app/src/main/java/srct/whatsopen/util/OpenTimesDeserializer.java
deleted
100644 → 0
View file @
5b82c670
package
srct.whatsopen.util
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonDeserializationContext
;
import
com.google.gson.JsonDeserializer
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonParseException
;
import
java.lang.reflect.Type
;
import
srct.whatsopen.model.OpenTimes
;
// Deserializer for a nested Json object, OpenTimes
public
class
OpenTimesDeserializer
implements
JsonDeserializer
<
OpenTimes
>
{
@Override
public
OpenTimes
deserialize
(
JsonElement
je
,
Type
type
,
JsonDeserializationContext
jdc
)
throws
JsonParseException
{
JsonElement
openTimes
=
je
.
getAsJsonObject
().
get
(
"open_time"
);
return
new
Gson
().
fromJson
(
openTimes
,
OpenTimes
.
class
);
}
}
app/src/main/java/srct/whatsopen/util/OpenTimesListDeserializer.java
deleted
100644 → 0
View file @
5b82c670
package
srct.whatsopen.util
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonDeserializationContext
;
import
com.google.gson.JsonDeserializer
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonParseException
;
import
java.lang.reflect.Type
;
import
io.realm.RealmList
;
import
srct.whatsopen.model.OpenTimes
;
// Json Deserializer for a list of OpenTimes
public
class
OpenTimesListDeserializer
implements
JsonDeserializer
<
RealmList
<
OpenTimes
>>
{
@Override
public
RealmList
<
OpenTimes
>
deserialize
(
JsonElement
json
,
Type
type
,
JsonDeserializationContext
jdc
)
throws
JsonParseException
{
RealmList
<
OpenTimes
>
openTimes
=
new
RealmList
<>();
JsonArray
ja
=
json
.
getAsJsonArray
();
for
(
JsonElement
je
:
ja
)
{
openTimes
.
add
((
OpenTimes
)
jdc
.
deserialize
(
je
,
OpenTimes
.
class
));
}
return
openTimes
;
}
}
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