Search in sources :

Example 6 with WebItem

use of io.github.hidroh.materialistic.data.WebItem 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)

Example 7 with WebItem

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

the class BaseListActivity method onItemSelected.

@Override
public void onItemSelected(@Nullable WebItem item) {
    WebItem previousItem = mSelectedItem;
    mSelectedItem = item;
    if (mIsMultiPane) {
        if (previousItem != null && item != null && TextUtils.equals(item.getId(), previousItem.getId())) {
            return;
        }
        if (previousItem == null && item != null || previousItem != null && item == null) {
            supportInvalidateOptionsMenu();
        }
        openMultiPaneItem();
    } else if (item != null) {
        openSinglePaneItem();
    }
}
Also used : WebItem(io.github.hidroh.materialistic.data.WebItem)

Example 8 with WebItem

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

the class AppUtils method toggleFabAction.

public static void toggleFabAction(FloatingActionButton fab, WebItem item, boolean commentMode) {
    Context context = fab.getContext();
    fab.setImageResource(commentMode ? R.drawable.ic_reply_white_24dp : R.drawable.ic_zoom_out_map_white_24dp);
    fab.setOnClickListener(v -> {
        if (commentMode) {
            context.startActivity(new Intent(context, ComposeActivity.class).putExtra(ComposeActivity.EXTRA_PARENT_ID, item.getId()).putExtra(ComposeActivity.EXTRA_PARENT_TEXT, item instanceof Item ? ((Item) item).getText() : null));
        } else {
            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
        }
    });
}
Also used : Context(android.content.Context) WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 9 with WebItem

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

the class WebActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        WebItem item = getIntent().getParcelableExtra(EXTRA_ITEM);
        Bundle args = new Bundle();
        args.putParcelable(WebFragment.EXTRA_ITEM, item);
        fragment = (WebFragment) Fragment.instantiate(this, WebFragment.class.getName(), args);
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, WebFragment.class.getName()).commit();
    } else {
        fragment = (WebFragment) getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
    }
}
Also used : Bundle(android.os.Bundle) WebFragment(io.github.hidroh.materialistic.WebFragment) WebItem(io.github.hidroh.materialistic.data.WebItem)

Example 10 with WebItem

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

the class ReadabilityFragmentLazyLoadTest method setUp.

@Before
public void setUp() {
    TestApplication.applicationGraph.inject(this);
    reset(readabilityClient);
    controller = Robolectric.buildActivity(TestReadabilityActivity.class);
    activity = controller.create().start().resume().visible().get();
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_readability)).apply();
    Bundle args = new Bundle();
    WebItem item = new TestWebItem() {

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public String getUrl() {
            return "http://example.com/article.html";
        }
    };
    args.putParcelable(WebFragment.EXTRA_ITEM, item);
    fragment = (WebFragment) Fragment.instantiate(activity, WebFragment.class.getName(), args);
}
Also used : Bundle(android.os.Bundle) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) TestReadabilityActivity(io.github.hidroh.materialistic.test.TestReadabilityActivity) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Before(org.junit.Before)

Aggregations

WebItem (io.github.hidroh.materialistic.data.WebItem)15 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)8 Test (org.junit.Test)8 Bundle (android.os.Bundle)7 TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)6 Intent (android.content.Intent)5 Fragment (android.support.v4.app.Fragment)4 Item (io.github.hidroh.materialistic.data.Item)4 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 KeyEvent (android.view.KeyEvent)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 TestReadabilityActivity (io.github.hidroh.materialistic.test.TestReadabilityActivity)2 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)2 Before (org.junit.Before)2 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 ConnectivityManager (android.net.ConnectivityManager)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 AppBarLayout (android.support.design.widget.AppBarLayout)1