Search in sources :

Example 16 with Item

use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.

the class StoryView method setStory.

public void setStory(@NonNull WebItem story, int hotThreshold) {
    if (!mIsLocal && story instanceof Item) {
        Item item = (Item) story;
        boolean hot = item.getScore() >= hotThreshold * AppUtils.HOT_FACTOR;
        mScoreTextView.setTextColor(hot ? mHotColorResId : mSecondaryTextColorResId);
        mRankTextView.setText(String.valueOf(item.getRank()));
        mScoreTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, hot ? R.drawable.ic_whatshot_orange500_18dp : 0);
        mScoreTextView.setText(getContext().getResources().getQuantityString(R.plurals.score, item.getScore(), item.getScore()));
        if (item.getKidCount() > 0) {
            hot = item.getKidCount() >= hotThreshold;
            mCommentButton.setTextColor(hot ? mHotColorResId : mAccentColorResId);
            if (hot) {
                mCommentButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_whatshot_orange500_24dp, 0, 0, 0);
            } else {
                mCommentButton.setCompoundDrawablesWithIntrinsicBounds(mCommentDrawable, null, null, null);
            }
            mCommentButton.setText(String.valueOf(item.getKidCount()));
        } else {
            mCommentButton.setTextColor(mAccentColorResId);
            mCommentButton.setText(null);
            mCommentButton.setCompoundDrawablesWithIntrinsicBounds(mCommentDrawable, null, null, null);
        }
    }
    mCommentButton.setVisibility(View.VISIBLE);
    mTitleTextView.setText(getContext().getString(R.string.loading_text));
    mTitleTextView.setText(story.getDisplayedTitle());
    mPostedTextView.setText(story.getDisplayedTime(getContext()));
    mPostedTextView.append(story.getDisplayedAuthor(getContext(), false, 0));
    switch(story.getType()) {
        case Item.JOB_TYPE:
            mSourceTextView.setText(null);
            mSourceTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_work_white_18dp, 0, 0, 0);
            break;
        case Item.POLL_TYPE:
            mSourceTextView.setText(null);
            mSourceTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_poll_white_18dp, 0, 0, 0);
            break;
        default:
            mSourceTextView.setText(story.getSource());
            mSourceTextView.setCompoundDrawables(null, null, null, null);
            break;
    }
}
Also used : WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item)

Aggregations

Item (io.github.hidroh.materialistic.data.Item)16 WebItem (io.github.hidroh.materialistic.data.WebItem)6 Bundle (android.os.Bundle)4 Fragment (android.support.v4.app.Fragment)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Intent (android.content.Intent)3 MenuItem (android.view.MenuItem)3 Context (android.content.Context)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 Synthetic (io.github.hidroh.materialistic.annotation.Synthetic)2 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)2 Test (org.junit.Test)2 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentResolver (android.content.ContentResolver)1 IntentFilter (android.content.IntentFilter)1