use of org.fossasia.openevent.data.Event in project open-event-android by fossasia.
the class MainActivity method handleJsonEvent.
@Subscribe
public void handleJsonEvent(final JsonReadEvent jsonReadEvent) {
final String name = jsonReadEvent.getName();
final String json = jsonReadEvent.getJson();
disposable.add(Completable.fromAction(() -> {
ObjectMapper objectMapper = APIClient.getObjectMapper();
// Need separate instance for background thread
Realm realm = Realm.getDefaultInstance();
RealmDataRepository realmDataRepository = RealmDataRepository.getInstance(realm);
switch(name) {
case ConstantStrings.EVENT:
{
Event event = objectMapper.readValue(json, Event.class);
saveEventDates(event);
realmDataRepository.saveEvent(event).subscribe();
realmDataRepository.saveEvent(event).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new EventDownloadEvent(true));
break;
}
case ConstantStrings.TRACKS:
{
List<Track> tracks = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Track.class));
realmDataRepository.saveTracks(tracks).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new TracksDownloadEvent(true));
break;
}
case ConstantStrings.SESSIONS:
{
List<Session> sessions = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Session.class));
for (Session current : sessions) {
current.setStartDate(current.getStartsAt().split("T")[0]);
}
realmDataRepository.saveSessions(sessions).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SessionDownloadEvent(true));
break;
}
case ConstantStrings.SPEAKERS:
{
List<Speaker> speakers = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Speaker.class));
realmRepo.saveSpeakers(speakers).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SpeakerDownloadEvent(true));
break;
}
case ConstantStrings.SPONSORS:
{
List<Sponsor> sponsors = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Sponsor.class));
realmRepo.saveSponsors(sponsors).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SponsorDownloadEvent(true));
break;
}
case ConstantStrings.MICROLOCATIONS:
{
List<Microlocation> microlocations = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Microlocation.class));
realmRepo.saveLocations(microlocations).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new MicrolocationDownloadEvent(true));
break;
}
case ConstantStrings.SESSION_TYPES:
{
List<SessionType> sessionTypes = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, SessionType.class));
realmRepo.saveSessionTypes(sessionTypes).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SessionTypesDownloadEvent(true));
break;
}
default:
}
realm.close();
}).observeOn(Schedulers.computation()).subscribe(() -> Timber.d("Saved event from JSON"), throwable -> {
throwable.printStackTrace();
Timber.e(throwable);
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new RetrofitError(throwable));
}));
}
use of org.fossasia.openevent.data.Event in project open-event-android by fossasia.
the class APITest method testEventAPIResponse.
public void testEventAPIResponse() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
APIClient.getOpenEventAPI().getEvent(59).enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
if (response.isSuccessful()) {
assertNotNull(response.body());
latch.countDown();
} else {
fail("API Request Failed");
latch.countDown();
}
}
@Override
public void onFailure(Call<Event> call, Throwable t) {
fail("API Request Failed");
latch.countDown();
}
});
latch.await();
}
use of org.fossasia.openevent.data.Event in project open-event-android by fossasia.
the class MapsFragment method showEventLocationOnMap.
private void showEventLocationOnMap() {
Event event = realmRepo.getEventSync();
if (event == null)
return;
double latitude = event.getLatitude();
double longitude = event.getLongitude();
String locationTitle = event.getLocationName();
LatLng location = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(location).title(locationTitle).icon(ImageUtils.vectorToBitmap(getContext(), R.drawable.map_marker, R.color.color_primary_dark)));
}
use of org.fossasia.openevent.data.Event in project open-event-android by fossasia.
the class SettingsActivity method updateEventDates.
private void updateEventDates() {
Event event = RealmDataRepository.getDefaultInstance().getEventSync();
String startTime = event.getStartsAt();
String endTime = event.getEndsAt();
try {
RealmDataRepository.getDefaultInstance().saveEventDates(DateConverter.getDaysInBetween(startTime, endTime)).subscribe();
} catch (DateTimeParseException pe) {
Toast.makeText(this, "DateTimeParseException : Error updating event dates", Toast.LENGTH_SHORT).show();
Timber.e("Error updating event dates : enable to parse start date: %s and end date: %s in ISO format", startTime, endTime);
}
}
use of org.fossasia.openevent.data.Event in project open-event-android by fossasia.
the class JSONDeserializationTest method testEventModelDeserialization.
@Test
public void testEventModelDeserialization() throws IOException {
Event event = objectMapper.readValue(readFile("event"), Event.class);
assertNotNull(event);
assertEquals(6, event.getId());
assertTrue(event.getIsSessionsSpeakersEnabled());
assertEquals(9, event.getSocialLinks().size());
}
Aggregations