use of org.fossasia.openevent.data.SessionType 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.SessionType in project open-event-android by fossasia.
the class SessionViewHolder method bindSession.
public void bindSession(int type, int colorInTracks, RealmDataRepository realmRepo) {
String sessionTitleString = Utils.checkStringEmpty(session.getTitle());
String sessionSubTitle = Utils.checkStringEmpty(session.getSubtitle());
int color = ContextCompat.getColor(context, R.color.color_primary);
sessionTitle.setText(sessionTitleString);
if (Utils.isEmpty(sessionSubTitle)) {
sessionSubtitle.setVisibility(View.GONE);
} else {
sessionSubtitle.setVisibility(View.VISIBLE);
sessionSubtitle.setText(sessionSubTitle);
}
SessionType sessionType = session.getSessionType();
if (sessionType != null) {
subtitle.setVisibility(View.VISIBLE);
subtitle.setText(sessionType.getName());
}
sessionStatus.setVisibility(View.GONE);
setSessionStatus();
Track track = session.getTrack();
if (!RealmDataRepository.isNull(track)) {
int storedColor = Color.parseColor(track.getColor());
if (type != trackWiseSessionList) {
color = storedColor;
} else {
color = colorInTracks;
}
TextDrawable drawable = Views.getTextDrawableBuilder().round().build(String.valueOf(track.getName().charAt(0)), storedColor);
trackImageIcon.setImageDrawable(drawable);
trackImageIcon.setBackgroundColor(Color.TRANSPARENT);
sessionTrack.setText(track.getName());
} else {
trackImageIcon.setVisibility(View.GONE);
sessionTrack.setVisibility(View.GONE);
Timber.d("This session has a null or incomplete track somehow : " + session.getTitle() + " " + track);
}
itemView.setOnClickListener(v -> onItemClickListener.itemOnClick(session, getLayoutPosition()));
String date = DateConverter.formatDateWithDefault(DateConverter.FORMAT_DATE_COMPLETE, session.getStartsAt());
sessionDate.setText(date);
sessionTime.setText(String.format("%s - %s", DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getStartsAt()), DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getEndsAt())));
if (session.getMicrolocation() != null) {
String locationName = Utils.checkStringEmpty(session.getMicrolocation().getName());
sessionLocation.setText(locationName);
} else {
sessionLocation.setText(context.getString(R.string.location_not_decided));
}
setSpeakerView();
handleVisibilityByType(type);
setBookmarkClickListener(realmRepo, track);
// Set color generated by palette on views
sessionHeader.setBackgroundColor(color);
if (track != null && track.isValid()) {
sessionTitle.setTextColor(Color.parseColor(track.getFontColor()));
setBookmarkIcon(sessionBookmarkIcon, session.getIsBookmarked(), track.getFontColor());
}
}
use of org.fossasia.openevent.data.SessionType 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