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;
}
}
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();
}
}
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));
}
});
}
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());
}
}
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);
}
Aggregations