Search in sources :

Example 1 with ItemCollectionState

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

the class ProfileItemsLayout method bind.

protected void bind(UserItems primaryItems, UserItems secondaryItems, UserItems tertiaryItems) {
    final Context context = getContext();
    ItemCollectionState state = primaryItems.getState();
    CollectableItem.Type type = primaryItems.getType();
    String stateString = state.getString(type, context);
    mTitleText.setText(stateString);
    OnClickListener viewMoreListener = new OnClickListener() {

        @Override
        public void onClick(View view) {
            onViewPrimaryItems();
        }
    };
    mTitleText.setOnClickListener(viewMoreListener);
    mViewMoreText.setOnClickListener(viewMoreListener);
    mItemAdapter.replace(primaryItems.items);
    ViewUtils.setVisibleOrGone(mItemList, !primaryItems.items.isEmpty());
    mEmptyView.setText(context.getString(R.string.profile_items_empty_format, stateString, type.getName(context)));
    ViewUtils.setVisibleOrGone(mEmptyView, primaryItems.items.isEmpty());
    if (primaryItems.total > primaryItems.items.size()) {
        mViewMoreText.setText(context.getString(R.string.view_more_with_count_format, primaryItems.total));
    } else {
        mViewMoreText.setVisibility(GONE);
    }
    if (secondaryItems != null && secondaryItems.total > 0) {
        mSecondaryText.setText(context.getString(R.string.profile_items_non_primary_format, secondaryItems.getState().getString(secondaryItems.getType(), context), secondaryItems.total));
        mSecondaryText.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                onViewSecondaryItems();
            }
        });
    } else {
        mSecondaryText.setVisibility(GONE);
    }
    if (tertiaryItems != null && tertiaryItems.total > 0) {
        mTertiaryText.setText(context.getString(R.string.profile_items_non_primary_format, tertiaryItems.getState().getString(tertiaryItems.getType(), context), tertiaryItems.total));
        mTertiaryText.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                onViewTertiaryItems();
            }
        });
    } else {
        mTertiaryText.setVisibility(GONE);
    }
}
Also used : Context(android.content.Context) CollectableItem(me.zhanghai.android.douya.network.api.info.frodo.CollectableItem) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) FriendlyCardView(me.zhanghai.android.douya.ui.FriendlyCardView) ItemCollectionState(me.zhanghai.android.douya.network.api.info.frodo.ItemCollectionState)

Example 2 with ItemCollectionState

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

the class ItemCollectionFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    //activity.setTitle(getTitle());
    activity.setSupportActionBar(mToolbar);
    // As in https://developer.android.com/guide/topics/ui/controls/radiobutton.html .
    View.OnClickListener collectionStateButtonOnClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!((RadioButton) view).isChecked()) {
                return;
            }
            ItemCollectionState oldCollectionState = mCollectionState;
            switch(view.getId()) {
                case R.id.todo:
                    mCollectionState = ItemCollectionState.TODO;
                    break;
                case R.id.doing:
                    mCollectionState = ItemCollectionState.DOING;
                    break;
                case R.id.done:
                    mCollectionState = ItemCollectionState.DONE;
                    break;
            }
            if (mCollectionState != oldCollectionState) {
                onCollectionStateChanged();
            }
        }
    };
    mTodoButton.setOnClickListener(collectionStateButtonOnClickListener);
    mDoingButton.setOnClickListener(collectionStateButtonOnClickListener);
    mDoneButton.setOnClickListener(collectionStateButtonOnClickListener);
    mRatingBar.setOnRatingChangeListener(new MaterialRatingBar.OnRatingChangeListener() {

        @Override
        public void onRatingChanged(MaterialRatingBar ratingBar, float rating) {
            mRatingHintText.setText(DoubanUtils.getRatingHint((int) rating, mRatingHintText.getContext()));
        }
    });
}
Also used : MaterialRatingBar(me.zhanghai.android.materialratingbar.MaterialRatingBar) AppCompatActivity(android.support.v7.app.AppCompatActivity) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) ItemCollectionState(me.zhanghai.android.douya.network.api.info.frodo.ItemCollectionState)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 ItemCollectionState (me.zhanghai.android.douya.network.api.info.frodo.ItemCollectionState)2 Context (android.content.Context)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 RecyclerView (android.support.v7.widget.RecyclerView)1 CollectableItem (me.zhanghai.android.douya.network.api.info.frodo.CollectableItem)1 FriendlyCardView (me.zhanghai.android.douya.ui.FriendlyCardView)1 MaterialRatingBar (me.zhanghai.android.materialratingbar.MaterialRatingBar)1