Search in sources :

Example 1 with BookmarkStatus

use of org.fossasia.openevent.core.bookmark.BookmarkStatus 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 2 with BookmarkStatus

use of org.fossasia.openevent.core.bookmark.BookmarkStatus in project open-event-android by fossasia.

the class DayScheduleViewHolder method bindSession.

public void bindSession(RealmDataRepository realmRepo) {
    String startTimeText = DateConverter.formatDateWithDefault(DateConverter.FORMAT_24H, session.getStartsAt());
    String endTimeText = DateConverter.formatDateWithDefault(DateConverter.FORMAT_24H, session.getEndsAt());
    String title = Utils.checkStringEmpty(session.getTitle());
    startTime.setText(startTimeText);
    endTime.setText(endTimeText);
    slotTitle.setText(title);
    Track sessionTrack = session.getTrack();
    if (!RealmDataRepository.isNull(sessionTrack)) {
        int storedColor = Color.parseColor(sessionTrack.getColor());
        slotTrack.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            slotTrack.setBackground(context.getDrawable(R.drawable.button_ripple));
        }
        slotTrack.getBackground().setColorFilter(storedColor, PorterDuff.Mode.SRC_ATOP);
        slotTrack.setText(sessionTrack.getName());
        if (session.getIsBookmarked()) {
            slotBookmark.setImageResource(R.drawable.ic_bookmark_white_24dp);
        } else {
            slotBookmark.setImageResource(R.drawable.ic_bookmark_border_white_24dp);
        }
        slotBookmark.setColorFilter(storedColor, PorterDuff.Mode.SRC_ATOP);
        final int sessionId = session.getId();
        slotBookmark.setOnClickListener(v -> {
            if (session.getIsBookmarked()) {
                realmRepo.setBookmark(sessionId, false).subscribe();
                slotBookmark.setImageResource(R.drawable.ic_bookmark_border_white_24dp);
                if (onBookmarkSelectedListener != null)
                    onBookmarkSelectedListener.showSnackbar(new BookmarkStatus(storedColor, sessionId, CODE_UNDO_REMOVED));
            } else {
                // TODO: Move all logic to ViewModel
                NotificationUtil.createNotification(session, context).subscribe(() -> {
                    if (onBookmarkSelectedListener != null)
                        onBookmarkSelectedListener.showSnackbar(new BookmarkStatus(storedColor, sessionId, CODE_UNDO_ADDED));
                }, throwable -> {
                    if (onBookmarkSelectedListener != null)
                        onBookmarkSelectedListener.showSnackbar(new BookmarkStatus(-1, -1, CODE_ERROR));
                });
                realmRepo.setBookmark(sessionId, true).subscribe();
                slotBookmark.setImageResource(R.drawable.ic_bookmark_white_24dp);
                slotBookmark.setColorFilter(storedColor, PorterDuff.Mode.SRC_ATOP);
            }
            WidgetUpdater.updateWidget(context);
        });
        slotTrack.setOnClickListener(v -> {
            Intent intent = new Intent(context, TrackSessionsActivity.class);
            intent.putExtra(ConstantStrings.TRACK, sessionTrack.getName());
            intent.putExtra(ConstantStrings.TRACK_ID, sessionTrack.getId());
            context.startActivity(intent);
        });
        itemView.setOnClickListener(v -> {
            final String sessionName = session.getTitle();
            realmRepo.getTrack(session.getTrack().getId()).addChangeListener((RealmChangeListener<Track>) track -> {
                String trackName = track.getName();
                Intent intent = new Intent(context, SessionDetailActivity.class);
                intent.putExtra(ConstantStrings.SESSION, sessionName);
                intent.putExtra(ConstantStrings.TRACK, trackName);
                intent.putExtra(ConstantStrings.ID, session.getId());
                context.startActivity(intent);
            });
        });
    } else {
        slotTrack.setOnClickListener(null);
        slotTrack.setVisibility(View.GONE);
        itemView.setOnClickListener(v -> {
            final String sessionName = session.getTitle();
            Intent intent = new Intent(context, SessionDetailActivity.class);
            intent.putExtra(ConstantStrings.SESSION, sessionName);
            intent.putExtra(ConstantStrings.ID, session.getId());
            context.startActivity(intent);
        });
        Timber.d("This session has no track somehow : " + session + " " + sessionTrack);
    }
    if (session.getMicrolocation() != null) {
        String locationName = Utils.checkStringEmpty(session.getMicrolocation().getName());
        slotLocation.setText(locationName);
    }
}
Also used : RealmChangeListener(io.realm.RealmChangeListener) Context(android.content.Context) ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) ConstantStrings(org.fossasia.openevent.common.ConstantStrings) ButterKnife(butterknife.ButterKnife) Utils(org.fossasia.openevent.common.utils.Utils) Intent(android.content.Intent) BindView(butterknife.BindView) Track(org.fossasia.openevent.data.Track) CODE_ERROR(org.fossasia.openevent.core.bookmark.BookmarkStatus.Status.CODE_ERROR) View(android.view.View) Button(android.widget.Button) Build(android.os.Build) R(org.fossasia.openevent.R) SessionDetailActivity(org.fossasia.openevent.core.track.session.SessionDetailActivity) BookmarkStatus(org.fossasia.openevent.core.bookmark.BookmarkStatus) WidgetUpdater(org.fossasia.openevent.common.ui.WidgetUpdater) DateConverter(org.fossasia.openevent.common.date.DateConverter) NotificationUtil(org.fossasia.openevent.common.notification.NotificationUtil) TrackSessionsActivity(org.fossasia.openevent.core.track.session.TrackSessionsActivity) PorterDuff(android.graphics.PorterDuff) Timber(timber.log.Timber) Color(android.graphics.Color) CODE_UNDO_REMOVED(org.fossasia.openevent.core.bookmark.BookmarkStatus.Status.CODE_UNDO_REMOVED) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) OnBookmarkSelectedListener(org.fossasia.openevent.core.bookmark.OnBookmarkSelectedListener) Session(org.fossasia.openevent.data.Session) RealmDataRepository(org.fossasia.openevent.data.repository.RealmDataRepository) CODE_UNDO_ADDED(org.fossasia.openevent.core.bookmark.BookmarkStatus.Status.CODE_UNDO_ADDED) BookmarkStatus(org.fossasia.openevent.core.bookmark.BookmarkStatus) Intent(android.content.Intent) SessionDetailActivity(org.fossasia.openevent.core.track.session.SessionDetailActivity) Track(org.fossasia.openevent.data.Track)

Aggregations

Intent (android.content.Intent)2 Color (android.graphics.Color)2 PorterDuff (android.graphics.PorterDuff)2 Build (android.os.Build)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageButton (android.widget.ImageButton)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 R (org.fossasia.openevent.R)2 ConstantStrings (org.fossasia.openevent.common.ConstantStrings)2 DateConverter (org.fossasia.openevent.common.date.DateConverter)2 NotificationUtil (org.fossasia.openevent.common.notification.NotificationUtil)2 WidgetUpdater (org.fossasia.openevent.common.ui.WidgetUpdater)2 Utils (org.fossasia.openevent.common.utils.Utils)2 BookmarkStatus (org.fossasia.openevent.core.bookmark.BookmarkStatus)2 OnBookmarkSelectedListener (org.fossasia.openevent.core.bookmark.OnBookmarkSelectedListener)2 Session (org.fossasia.openevent.data.Session)2 Track (org.fossasia.openevent.data.Track)2