use of org.fossasia.openevent.data.Microlocation 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.Microlocation in project open-event-android by fossasia.
the class OSMapFragment method showEvent.
private void showEvent() {
if (!event.isValid())
return;
try {
int id = SharedPreferencesUtil.getInt(ConstantStrings.SESSION_MAP_ID, -1);
if (id != -1) {
Session session = realmRepo.getSessionSync(id);
Microlocation microlocation = session.getMicrolocation();
if (microlocation.getLatitude() == 0 && microlocation.getLongitude() == 0) {
setDestinationLatitude(event.getLatitude());
setDestinationLongitude(event.getLongitude());
setDestinationName(event.getLocationName());
} else {
setDestinationLatitude(microlocation.getLatitude());
setDestinationLongitude(microlocation.getLongitude());
setDestinationName(microlocation.getName());
}
} else {
setDestinationLatitude(event.getLatitude());
setDestinationLongitude(event.getLongitude());
setDestinationName(event.getLocationName());
}
} catch (Exception e) {
setDestinationLatitude(event.getLatitude());
setDestinationLongitude(event.getLongitude());
setDestinationName(event.getLocationName());
}
}
use of org.fossasia.openevent.data.Microlocation in project open-event-android by fossasia.
the class MapsFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (getArguments() != null) {
isFragmentFromMainActivity = getArguments().getBoolean(ConstantStrings.IS_MAP_FRAGMENT_FROM_MAIN_ACTIVITY);
fragmentLocationName = getArguments().getString(ConstantStrings.LOCATION_NAME);
}
if (isFragmentFromMainActivity) {
setHasOptionsMenu(true);
}
View view = inflater.inflate(R.layout.fragment_map, container, false);
if (savedInstanceState != null && savedInstanceState.getString(SEARCH) != null) {
searchText = savedInstanceState.getString(SEARCH);
}
SupportMapFragment supportMapFragment = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map));
supportMapFragment.getMapAsync(this);
realmRepo.getLocations().addChangeListener((microlocations, orderedCollectionChangeSet) -> {
mLocations.clear();
for (Microlocation microlocation : microlocations) {
mLocations.add(new MicrolocationClusterWrapper(microlocation));
}
});
return view;
}
use of org.fossasia.openevent.data.Microlocation in project open-event-android by fossasia.
the class GlobalSearchAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
switch(holder.getItemViewType()) {
case TRACK:
TrackViewHolder trackSearchHolder = (TrackViewHolder) holder;
Track currentTrack = (Track) getItem(position);
trackSearchHolder.bindTrack(currentTrack);
break;
case SPEAKER:
SpeakerViewHolder speakerSearchHolder = (SpeakerViewHolder) holder;
Speaker speaker = (Speaker) getItem(position);
speakerSearchHolder.bindSpeaker(speaker);
break;
case LOCATION:
LocationViewHolder locationSearchHolder = (LocationViewHolder) holder;
Microlocation location = (Microlocation) getItem(position);
locationSearchHolder.bindLocation(location);
break;
case DIVIDER:
DividerViewHolder resultTypeViewHolder = (DividerViewHolder) holder;
String headerItem = (String) getItem(position);
resultTypeViewHolder.bindHeader(headerItem);
break;
case SESSION:
DayScheduleViewHolder bookmarkTypeViewHolder = (DayScheduleViewHolder) holder;
Session bookmarkItem = (Session) getItem(position);
bookmarkTypeViewHolder.setSession(bookmarkItem);
bookmarkTypeViewHolder.bindSession(realmRepo);
break;
default:
// If viewType is none of the above then nothing is done
break;
}
}
use of org.fossasia.openevent.data.Microlocation in project open-event-android by fossasia.
the class SessionDetailActivity method updateSession.
private void updateSession() {
if (hasTrack)
setUiColor();
Timber.d("Updated");
speakers.clear();
speakers.addAll(session.getSpeakers());
adapter.notifyDataSetChanged();
updateFloatingIcon();
Microlocation microlocation = session.getMicrolocation();
if (microlocation != null) {
location = microlocation.getName();
text_room1.setText(microlocation.getName());
} else {
location = getString(R.string.location_not_decided);
text_room1.setText(location);
}
SessionType type = session.getSessionType();
if (type != null) {
sessionType.setText(type.getName());
typelayout.setVisibility(View.VISIBLE);
}
text_title.setText(title);
if (TextUtils.isEmpty(session.getSubtitle())) {
text_subtitle.setVisibility(View.GONE);
}
text_subtitle.setText(session.getSubtitle());
if (hasTrack) {
trackLabel.setVisibility(View.VISIBLE);
text_track.setVisibility(View.VISIBLE);
text_track.setText(trackName);
} else {
trackLabel.setVisibility(View.GONE);
text_track.setVisibility(View.GONE);
}
String video_link = session.getVideoUrl();
if (!Utils.isEmpty(video_link)) {
playButton.setVisibility(View.VISIBLE);
if (video_link.contains(ConstantStrings.YOUTUBE)) {
youtubeThumbnail.setVisibility(View.VISIBLE);
Picasso.with(this).load(ConstantStrings.YOUTUBE_URI_1 + video_link.substring(video_link.length() - 11) + ConstantStrings.YOUTUBE_URI_2).into(youtubeThumbnail);
}
playButton.setOnClickListener(v -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(video_link))));
}
String date = DateConverter.formatDateWithDefault(DateConverter.FORMAT_DATE_COMPLETE, session.getStartsAt());
String startTime = DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getStartsAt());
String endTime = DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getEndsAt());
text_start_time.setText(startTime);
text_end_time.setText(endTime);
text_date.setText(date);
Timber.d("Date: %s\nStart: %s\nEnd: %s", date, startTime, endTime);
Views.setHtml(summary, session.getShortAbstract(), true);
Views.setHtml(descrip, session.getLongAbstract(), true);
}
Aggregations