Search in sources :

Example 6 with SimpleItemCollection

use of me.zhanghai.android.douya.network.api.info.frodo.SimpleItemCollection in project Douya by DreaminginCodeZH.

the class BaseItemDataAdapter method bindItemCollectionHolder.

protected void bindItemCollectionHolder(RecyclerView.ViewHolder holder, T item) {
    ItemCollectionHolder itemCollectionHolder = (ItemCollectionHolder) holder;
    CollectableItem.Type type = item.getType();
    itemCollectionHolder.todoButton.setText(ItemCollectionState.TODO.getString(type, itemCollectionHolder.todoButton.getContext()));
    itemCollectionHolder.doingButton.setText(ItemCollectionState.DOING.getString(type, itemCollectionHolder.doingButton.getContext()));
    itemCollectionHolder.doneButton.setText(ItemCollectionState.DONE.getString(type, itemCollectionHolder.doneButton.getContext()));
    SimpleItemCollection itemCollection = item.collection;
    ItemCollectionState state = itemCollection != null ? itemCollection.getState() : null;
    boolean todoVisible = itemCollection == null;
    ViewUtils.setVisibleOrGone(itemCollectionHolder.todoButton, todoVisible);
    itemCollectionHolder.todoButton.setOnClickListener(view -> {
        Context context = view.getContext();
        context.startActivity(ItemCollectionActivity.makeIntent(item, ItemCollectionState.TODO, context));
    });
    boolean doingVisible = item.getType().hasDoingState() && (itemCollection == null || state == ItemCollectionState.TODO);
    ViewUtils.setVisibleOrGone(itemCollectionHolder.doingButton, doingVisible);
    itemCollectionHolder.doingButton.setOnClickListener(view -> {
        Context context = view.getContext();
        context.startActivity(ItemCollectionActivity.makeIntent(item, ItemCollectionState.DOING, context));
    });
    boolean doneVisible = itemCollection == null || state == ItemCollectionState.TODO || state == ItemCollectionState.DOING;
    ViewUtils.setVisibleOrGone(itemCollectionHolder.doneButton, doneVisible);
    itemCollectionHolder.doneButton.setOnClickListener(view -> {
        Context context = view.getContext();
        context.startActivity(ItemCollectionActivity.makeIntent(item, ItemCollectionState.DONE, context));
    });
    boolean buttonBarVisible = todoVisible || doingVisible || doneVisible;
    ViewUtils.setVisibleOrGone(itemCollectionHolder.buttonBar, buttonBarVisible);
    ViewUtils.setVisibleOrGone(itemCollectionHolder.buttonBarSpace, !buttonBarVisible);
    boolean hasItemCollection = itemCollection != null;
    ViewUtils.setVisibleOrGone(itemCollectionHolder.itemCollectionLayout, hasItemCollection);
    if (hasItemCollection) {
        itemCollectionHolder.stateText.setText(state.getString(item.getType(), itemCollectionHolder.stateText.getContext()));
        boolean hasRating = itemCollection.rating != null;
        ViewUtils.setVisibleOrGone(itemCollectionHolder.ratingBar, hasRating);
        if (hasRating) {
            itemCollectionHolder.ratingBar.setRating(itemCollection.rating.getRatingBarRating());
        }
        itemCollectionHolder.dateText.setText(TimeUtils.formatDate(TimeUtils.parseDoubanDateTime(itemCollection.createTime), itemCollectionHolder.dateText.getContext()));
        itemCollectionHolder.commentText.setText(itemCollection.comment);
        itemCollectionHolder.itemCollectionLayout.setOnClickListener(view -> {
            Context context = view.getContext();
            context.startActivity(ItemCollectionActivity.makeIntent(item, context));
        });
        itemCollectionHolder.menu.setOnMenuItemClickListener(menuItem -> {
            switch(menuItem.getItemId()) {
                case R.id.action_edit:
                    {
                        Context context = RecyclerViewUtils.getContext(holder);
                        context.startActivity(ItemCollectionActivity.makeIntent(item, context));
                        return true;
                    }
                case R.id.action_uncollect:
                    mListener.onUncollectItem(item);
                    return true;
                default:
                    return false;
            }
        });
    }
    ViewUtils.setVisibleOrGone(itemCollectionHolder.dividerView, !hasItemCollection);
}
Also used : Context(android.content.Context) CollectableItem(me.zhanghai.android.douya.network.api.info.frodo.CollectableItem) SimpleItemCollection(me.zhanghai.android.douya.network.api.info.frodo.SimpleItemCollection) ItemCollectionState(me.zhanghai.android.douya.network.api.info.frodo.ItemCollectionState)

Example 7 with SimpleItemCollection

use of me.zhanghai.android.douya.network.api.info.frodo.SimpleItemCollection in project Douya by DreaminginCodeZH.

the class GameFragment method update.

private void update(Game game, Rating rating, List<Photo> photoList, List<SimpleItemCollection> itemCollectionList, List<SimpleReview> gameGuideList, List<SimpleReview> reviewList, List<SimpleItemForumTopic> forumTopicList, List<CollectableItem> recommendationList, List<Doulist> relatedDoulistList) {
    if (game != null) {
        super.updateWithSimpleItem(game);
    }
    if (game == null || photoList == null) {
        return;
    }
    if (!mBackdropBound) {
        // TODO: Add game videos like movie trailer.
        mExcludeFirstPhoto = false;
        String backdropUrl = null;
        if (!photoList.isEmpty()) {
            backdropUrl = photoList.get(0).getLargeUrl();
            mExcludeFirstPhoto = true;
            mBackdropLayout.setOnClickListener(view -> {
                // TODO
                Context context = view.getContext();
                context.startActivity(GalleryActivity.makeImageListIntent(photoList, 0, context));
            });
        } else if (game.cover != null) {
            backdropUrl = game.cover.getLargeUrl();
            mBackdropLayout.setOnClickListener(view -> {
                // TODO
                Context context = view.getContext();
                context.startActivity(GalleryActivity.makeIntent(game.cover, context));
            });
        }
        if (backdropUrl != null) {
            ImageUtils.loadItemBackdropAndFadeIn(mBackdropImage, backdropUrl, null);
        } else {
            mBackdropImage.setBackgroundColor(game.getThemeColor());
            ViewUtils.fadeIn(mBackdropImage);
        }
        mBackdropBound = true;
    }
    mAdapter.setData(new GameDataAdapter.Data(game, rating, photoList, mExcludeFirstPhoto, itemCollectionList, gameGuideList, reviewList, forumTopicList, recommendationList, relatedDoulistList));
    if (mAdapter.getItemCount() > 0) {
        mContentStateLayout.setLoaded(true);
    }
}
Also used : Context(android.content.Context) SimpleReview(me.zhanghai.android.douya.network.api.info.frodo.SimpleReview) Context(android.content.Context) UncollectItemManager(me.zhanghai.android.douya.item.content.UncollectItemManager) UriHandler(me.zhanghai.android.douya.link.UriHandler) GalleryActivity(me.zhanghai.android.douya.gallery.ui.GalleryActivity) BaseItemFragmentResource(me.zhanghai.android.douya.item.content.BaseItemFragmentResource) CollectableItem(me.zhanghai.android.douya.network.api.info.frodo.CollectableItem) CopyTextDialogFragment(me.zhanghai.android.douya.ui.CopyTextDialogFragment) BindDimen(butterknife.BindDimen) Doulist(me.zhanghai.android.douya.network.api.info.frodo.Doulist) Rating(me.zhanghai.android.douya.network.api.info.frodo.Rating) Game(me.zhanghai.android.douya.network.api.info.frodo.Game) ImageUtils(me.zhanghai.android.douya.util.ImageUtils) ViewUtils(me.zhanghai.android.douya.util.ViewUtils) ConfirmUncollectItemDialogFragment(me.zhanghai.android.douya.item.content.ConfirmUncollectItemDialogFragment) ItemAwardItem(me.zhanghai.android.douya.network.api.info.frodo.ItemAwardItem) SimpleCelebrity(me.zhanghai.android.douya.network.api.info.frodo.SimpleCelebrity) BarrierAdapter(me.zhanghai.android.douya.ui.BarrierAdapter) R(me.zhanghai.android.douya.R) GameFragmentResource(me.zhanghai.android.douya.item.content.GameFragmentResource) DoubanUtils(me.zhanghai.android.douya.util.DoubanUtils) List(java.util.List) SimpleItemForumTopic(me.zhanghai.android.douya.network.api.info.frodo.SimpleItemForumTopic) SimpleItemCollection(me.zhanghai.android.douya.network.api.info.frodo.SimpleItemCollection) Photo(me.zhanghai.android.douya.network.api.info.frodo.Photo) SimpleGame(me.zhanghai.android.douya.network.api.info.frodo.SimpleGame)

Aggregations

SimpleItemCollection (me.zhanghai.android.douya.network.api.info.frodo.SimpleItemCollection)7 Context (android.content.Context)4 List (java.util.List)3 CollectableItem (me.zhanghai.android.douya.network.api.info.frodo.CollectableItem)3 BindDimen (butterknife.BindDimen)2 R (me.zhanghai.android.douya.R)2 GalleryActivity (me.zhanghai.android.douya.gallery.ui.GalleryActivity)2 BaseItemFragmentResource (me.zhanghai.android.douya.item.content.BaseItemFragmentResource)2 ConfirmUncollectItemDialogFragment (me.zhanghai.android.douya.item.content.ConfirmUncollectItemDialogFragment)2 UncollectItemManager (me.zhanghai.android.douya.item.content.UncollectItemManager)2 UriHandler (me.zhanghai.android.douya.link.UriHandler)2 Doulist (me.zhanghai.android.douya.network.api.info.frodo.Doulist)2 ItemAwardItem (me.zhanghai.android.douya.network.api.info.frodo.ItemAwardItem)2 ItemCollectionState (me.zhanghai.android.douya.network.api.info.frodo.ItemCollectionState)2 Photo (me.zhanghai.android.douya.network.api.info.frodo.Photo)2 Rating (me.zhanghai.android.douya.network.api.info.frodo.Rating)2 SimpleCelebrity (me.zhanghai.android.douya.network.api.info.frodo.SimpleCelebrity)2 SimpleItemForumTopic (me.zhanghai.android.douya.network.api.info.frodo.SimpleItemForumTopic)2 SimpleReview (me.zhanghai.android.douya.network.api.info.frodo.SimpleReview)2 BarrierAdapter (me.zhanghai.android.douya.ui.BarrierAdapter)2