use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class AboutFragmentViewModel method getSessionsList.
private List<Object> getSessionsList(List<Session> bookmarked) {
List<Object> sessionsList = new ArrayList<>();
for (String eventDate : getDateList()) {
boolean headerCheck = false;
for (Session bookmarkedSession : bookmarked) {
if (bookmarkedSession.getStartDate() != null && bookmarkedSession.getStartDate().equals(eventDate)) {
if (!headerCheck) {
String headerDate = "Invalid";
try {
headerDate = DateConverter.formatDay(eventDate);
} catch (DateTimeParseException e) {
e.printStackTrace();
}
sessionsList.add(headerDate);
headerCheck = true;
}
sessionsList.add(bookmarkedSession);
}
}
}
return sessionsList;
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class DayScheduleAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(DayScheduleViewHolder holder, int position) {
Session currentSession = getItem(position);
holder.setSession(currentSession);
holder.bindSession(realmRepo);
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class SessionDetailActivity method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
title = getIntent().getStringExtra(ConstantStrings.SESSION);
trackName = getIntent().getStringExtra(ConstantStrings.TRACK);
if (TextUtils.isEmpty(trackName))
hasTrack = false;
id = getIntent().getIntExtra(ConstantStrings.ID, 0);
Timber.tag(TAG).d(title);
appBarLayout.addOnOffsetChangedListener(this);
adapter = new SessionSpeakerListAdapter(speakers);
sessionDetailActivityViewModel = ViewModelProviders.of(this).get(SessionDetailActivityViewModel.class);
fabSessionBookmark.setOnClickListener(view -> {
if (session == null)
return;
if (RealmDataRepository.isNull(session.getTrack())) {
Snackbar.make(speakersRecyclerView, R.string.invalid_track, Snackbar.LENGTH_SHORT).show();
return;
}
if (session.getIsBookmarked()) {
Timber.tag(TAG).d("Bookmark Removed");
sessionDetailActivityViewModel.setBookmark(session, false);
fabSessionBookmark.setImageResource(R.drawable.ic_bookmark_border_white_24dp);
showSnackbar(new BookmarkStatus(Color.parseColor(session.getTrack().getColor()), session.getId(), BookmarkStatus.Status.CODE_UNDO_REMOVED));
} else {
Timber.tag(TAG).d("Bookmark Added");
sessionDetailActivityViewModel.setBookmark(session, true);
fabSessionBookmark.setImageResource(R.drawable.ic_bookmark_white_24dp);
compositeDisposable.add(NotificationUtil.createNotification(session, getApplicationContext()).subscribe(() -> showSnackbar(new BookmarkStatus(Color.parseColor(session.getTrack().getColor()), session.getId(), BookmarkStatus.Status.CODE_UNDO_ADDED)), throwable -> showSnackbar(new BookmarkStatus(Color.parseColor(session.getTrack().getColor()), session.getId(), BookmarkStatus.Status.CODE_ERROR))));
}
WidgetUpdater.updateWidget(getApplicationContext());
});
speakersRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
speakersRecyclerView.setNestedScrollingEnabled(false);
speakersRecyclerView.setAdapter(adapter);
speakersRecyclerView.setItemAnimator(new DefaultItemAnimator());
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class SessionsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final SessionViewHolder holder, final int position) {
Session session = getItem(position);
// removing draft sessions
if ((!Utils.isEmpty(session.getState())) && session.getState().equals("draft")) {
getDataList().remove(position);
notifyItemRemoved(position);
return;
}
holder.setSession(session);
holder.bindSession(type, color, realmRepo);
}
use of org.fossasia.openevent.data.Session 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));
}));
}
Aggregations