Search in sources :

Example 1 with Session

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;
}
Also used : DateTimeParseException(org.threeten.bp.format.DateTimeParseException) ArrayList(java.util.ArrayList) Session(org.fossasia.openevent.data.Session)

Example 2 with Session

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);
}
Also used : Session(org.fossasia.openevent.data.Session)

Example 3 with Session

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());
}
Also used : ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) DrawableCompat(android.support.v4.graphics.drawable.DrawableCompat) SnackbarUtil(org.fossasia.openevent.common.ui.SnackbarUtil) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) CalendarContract(android.provider.CalendarContract) BindView(butterknife.BindView) ColorStateList(android.content.res.ColorStateList) Picasso(com.squareup.picasso.Picasso) Views(org.fossasia.openevent.common.ui.Views) Track(org.fossasia.openevent.data.Track) View(android.view.View) R(org.fossasia.openevent.R) FloatingActionButton(android.support.design.widget.FloatingActionButton) WidgetUpdater(org.fossasia.openevent.common.ui.WidgetUpdater) SessionType(org.fossasia.openevent.data.SessionType) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) NotificationUtil(org.fossasia.openevent.common.notification.NotificationUtil) PorterDuff(android.graphics.PorterDuff) SharedPreferencesUtil(org.fossasia.openevent.common.utils.SharedPreferencesUtil) Timber(timber.log.Timber) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) Html(android.text.Html) OnBookmarkSelectedListener(org.fossasia.openevent.core.bookmark.OnBookmarkSelectedListener) Snackbar(android.support.design.widget.Snackbar) AppBarLayout(android.support.design.widget.AppBarLayout) ConstantStrings(org.fossasia.openevent.common.ConstantStrings) Utils(org.fossasia.openevent.common.utils.Utils) Intent(android.content.Intent) BaseActivity(org.fossasia.openevent.common.ui.base.BaseActivity) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Toast(android.widget.Toast) Menu(android.view.Menu) NestedScrollView(android.support.v4.widget.NestedScrollView) Speaker(org.fossasia.openevent.data.Speaker) Build(android.os.Build) BookmarkStatus(org.fossasia.openevent.core.bookmark.BookmarkStatus) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) StrategyRegistry(org.fossasia.openevent.config.StrategyRegistry) DateConverter(org.fossasia.openevent.common.date.DateConverter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Color(android.graphics.Color) ViewModelProviders(android.arch.lifecycle.ViewModelProviders) RecyclerView(android.support.v7.widget.RecyclerView) FragmentManager(android.support.v4.app.FragmentManager) Toolbar(android.support.v7.widget.Toolbar) Microlocation(org.fossasia.openevent.data.Microlocation) Session(org.fossasia.openevent.data.Session) FragmentTransaction(android.support.v4.app.FragmentTransaction) RealmDataRepository(org.fossasia.openevent.data.repository.RealmDataRepository) BookmarkStatus(org.fossasia.openevent.core.bookmark.BookmarkStatus) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 4 with Session

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);
}
Also used : Session(org.fossasia.openevent.data.Session)

Example 5 with Session

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));
    }));
}
Also used : SpeakerDownloadEvent(org.fossasia.openevent.common.events.SpeakerDownloadEvent) Bundle(android.os.Bundle) Completable(io.reactivex.Completable) ImageView(android.widget.ImageView) DataDownloadEvent(org.fossasia.openevent.common.events.DataDownloadEvent) Track(org.fossasia.openevent.data.Track) Handler(android.os.Handler) ConnectivityManager(android.net.ConnectivityManager) SmoothActionBarDrawerToggle(org.fossasia.openevent.common.ui.SmoothActionBarDrawerToggle) Realm(io.realm.Realm) TracksDownloadEvent(org.fossasia.openevent.common.events.TracksDownloadEvent) SessionType(org.fossasia.openevent.data.SessionType) Fragment(android.support.v4.app.Fragment) LocationsFragment(org.fossasia.openevent.core.location.LocationsFragment) Snackbar(android.support.design.widget.Snackbar) DialogFactory(org.fossasia.openevent.common.ui.DialogFactory) Sponsor(org.fossasia.openevent.data.Sponsor) ConstantStrings(org.fossasia.openevent.common.ConstantStrings) FacebookApi(org.fossasia.openevent.core.feed.facebook.api.FacebookApi) ButterKnife(butterknife.ButterKnife) UserProfileActivity(org.fossasia.openevent.core.auth.profile.UserProfileActivity) Dialog(android.app.Dialog) SponsorsFragment(org.fossasia.openevent.core.sponsor.SponsorsFragment) BaseActivity(org.fossasia.openevent.common.ui.base.BaseActivity) CommonTaskLoop(org.fossasia.openevent.common.utils.CommonTaskLoop) SpeakerDownloadEvent(org.fossasia.openevent.common.events.SpeakerDownloadEvent) Menu(android.view.Menu) DownloadCompleteHandler(org.fossasia.openevent.common.api.DownloadCompleteHandler) Settings(android.provider.Settings) Observable(io.reactivex.Observable) DrawerLayout(android.support.v4.widget.DrawerLayout) StrategyRegistry(org.fossasia.openevent.config.StrategyRegistry) ComponentName(android.content.ComponentName) DataDownloadManager(org.fossasia.openevent.common.api.DataDownloadManager) TextUtils(android.text.TextUtils) IOException(java.io.IOException) CounterEvent(org.fossasia.openevent.common.events.CounterEvent) Subscribe(com.squareup.otto.Subscribe) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) Toolbar(android.support.v7.widget.Toolbar) Microlocation(org.fossasia.openevent.data.Microlocation) Session(org.fossasia.openevent.data.Session) JsonReadEvent(org.fossasia.openevent.common.events.JsonReadEvent) RealmDataRepository(org.fossasia.openevent.data.repository.RealmDataRepository) EditText(android.widget.EditText) NavigationView(android.support.design.widget.NavigationView) Rect(android.graphics.Rect) SocialLink(org.fossasia.openevent.data.extras.SocialLink) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SessionDownloadEvent(org.fossasia.openevent.common.events.SessionDownloadEvent) BindView(butterknife.BindView) TracksFragment(org.fossasia.openevent.core.track.TracksFragment) SettingsActivity(org.fossasia.openevent.core.settings.SettingsActivity) EventDownloadEvent(org.fossasia.openevent.common.events.EventDownloadEvent) CustomTabsServiceConnection(android.support.customtabs.CustomTabsServiceConnection) APIClient(org.fossasia.openevent.common.api.APIClient) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) CustomTabsClient(android.support.customtabs.CustomTabsClient) R(org.fossasia.openevent.R) RetrofitResponseEvent(org.fossasia.openevent.common.events.RetrofitResponseEvent) NetworkInfo(android.net.NetworkInfo) SponsorDownloadEvent(org.fossasia.openevent.common.events.SponsorDownloadEvent) Urls(org.fossasia.openevent.common.api.Urls) DiscountCodeFragment(org.fossasia.openevent.core.discount.DiscountCodeFragment) ScheduleFragment(org.fossasia.openevent.core.schedule.ScheduleFragment) SharedPreferencesUtil(org.fossasia.openevent.common.utils.SharedPreferencesUtil) Timber(timber.log.Timber) AuthUtil(org.fossasia.openevent.core.auth.AuthUtil) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) NetworkUtils(org.fossasia.openevent.common.network.NetworkUtils) Nullable(android.support.annotation.Nullable) AboutFragment(org.fossasia.openevent.core.about.AboutFragment) ShowNetworkDialogEvent(org.fossasia.openevent.common.events.ShowNetworkDialogEvent) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) DownloadEvent(org.fossasia.openevent.common.events.DownloadEvent) Utils(org.fossasia.openevent.common.utils.Utils) RealmList(io.realm.RealmList) ZoomableImageUtil(org.fossasia.openevent.common.ui.image.ZoomableImageUtil) Intent(android.content.Intent) FAQFragment(org.fossasia.openevent.core.faqs.FAQFragment) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) GravityCompat(android.support.v4.view.GravityCompat) RetrofitError(org.fossasia.openevent.common.events.RetrofitError) Event(org.fossasia.openevent.data.Event) MotionEvent(android.view.MotionEvent) NotificationsFragment(org.fossasia.openevent.core.notifications.NotificationsFragment) Speaker(org.fossasia.openevent.data.Speaker) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ActionBar(android.support.v7.app.ActionBar) EventLoadedEvent(org.fossasia.openevent.common.events.EventLoadedEvent) DialogInterface(android.content.DialogInterface) MicrolocationDownloadEvent(org.fossasia.openevent.common.events.MicrolocationDownloadEvent) RealmResults(io.realm.RealmResults) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateConverter(org.fossasia.openevent.common.date.DateConverter) NoInternetEvent(org.fossasia.openevent.common.events.NoInternetEvent) FeedFragment(org.fossasia.openevent.core.feed.FeedFragment) SessionTypesDownloadEvent(org.fossasia.openevent.common.events.SessionTypesDownloadEvent) SpeakersListFragment(org.fossasia.openevent.core.speaker.SpeakersListFragment) InputStream(java.io.InputStream) SessionType(org.fossasia.openevent.data.SessionType) SessionTypesDownloadEvent(org.fossasia.openevent.common.events.SessionTypesDownloadEvent) EventDownloadEvent(org.fossasia.openevent.common.events.EventDownloadEvent) MicrolocationDownloadEvent(org.fossasia.openevent.common.events.MicrolocationDownloadEvent) List(java.util.List) RealmList(io.realm.RealmList) Realm(io.realm.Realm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Speaker(org.fossasia.openevent.data.Speaker) SponsorDownloadEvent(org.fossasia.openevent.common.events.SponsorDownloadEvent) RetrofitError(org.fossasia.openevent.common.events.RetrofitError) RealmDataRepository(org.fossasia.openevent.data.repository.RealmDataRepository) Sponsor(org.fossasia.openevent.data.Sponsor) SessionDownloadEvent(org.fossasia.openevent.common.events.SessionDownloadEvent) DataDownloadEvent(org.fossasia.openevent.common.events.DataDownloadEvent) TracksDownloadEvent(org.fossasia.openevent.common.events.TracksDownloadEvent) SpeakerDownloadEvent(org.fossasia.openevent.common.events.SpeakerDownloadEvent) CounterEvent(org.fossasia.openevent.common.events.CounterEvent) JsonReadEvent(org.fossasia.openevent.common.events.JsonReadEvent) SessionDownloadEvent(org.fossasia.openevent.common.events.SessionDownloadEvent) EventDownloadEvent(org.fossasia.openevent.common.events.EventDownloadEvent) RetrofitResponseEvent(org.fossasia.openevent.common.events.RetrofitResponseEvent) SponsorDownloadEvent(org.fossasia.openevent.common.events.SponsorDownloadEvent) ShowNetworkDialogEvent(org.fossasia.openevent.common.events.ShowNetworkDialogEvent) DownloadEvent(org.fossasia.openevent.common.events.DownloadEvent) Event(org.fossasia.openevent.data.Event) MotionEvent(android.view.MotionEvent) EventLoadedEvent(org.fossasia.openevent.common.events.EventLoadedEvent) MicrolocationDownloadEvent(org.fossasia.openevent.common.events.MicrolocationDownloadEvent) NoInternetEvent(org.fossasia.openevent.common.events.NoInternetEvent) SessionTypesDownloadEvent(org.fossasia.openevent.common.events.SessionTypesDownloadEvent) TracksDownloadEvent(org.fossasia.openevent.common.events.TracksDownloadEvent) Track(org.fossasia.openevent.data.Track) Microlocation(org.fossasia.openevent.data.Microlocation) Session(org.fossasia.openevent.data.Session) Subscribe(com.squareup.otto.Subscribe)

Aggregations

Session (org.fossasia.openevent.data.Session)13 Intent (android.content.Intent)5 Track (org.fossasia.openevent.data.Track)4 Build (android.os.Build)3 Bundle (android.os.Bundle)3 View (android.view.View)3 BindView (butterknife.BindView)3 R (org.fossasia.openevent.R)3 ConstantStrings (org.fossasia.openevent.common.ConstantStrings)3 DateConverter (org.fossasia.openevent.common.date.DateConverter)3 Utils (org.fossasia.openevent.common.utils.Utils)3 RealmDataRepository (org.fossasia.openevent.data.repository.RealmDataRepository)3 ZonedDateTime (org.threeten.bp.ZonedDateTime)3 Timber (timber.log.Timber)3 Context (android.content.Context)2 Color (android.graphics.Color)2 PorterDuff (android.graphics.PorterDuff)2 AppBarLayout (android.support.design.widget.AppBarLayout)2 Snackbar (android.support.design.widget.Snackbar)2 Fragment (android.support.v4.app.Fragment)2