use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class SinglePageItemRecyclerViewAdapter method attach.
@Override
public void attach(Context context, RecyclerView recyclerView) {
super.attach(context, recyclerView);
mLevelIndicatorWidth = AppUtils.getDimensionInDp(mContext, R.dimen.level_indicator_width);
mColors = mResourcesProvider.obtainTypedArray(R.array.color_codes);
mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
Item item = getItem(viewHolder.getAdapterPosition());
if (item == null || item.getKidCount() == 0) {
return 0;
}
return super.getSwipeDirs(recyclerView, viewHolder);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
Item item = getItem(position);
if (item != null) {
notifyItemChanged(position);
toggleKids(item);
}
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
float swipeWidth = viewHolder.itemView.getWidth() * getSwipeThreshold(viewHolder);
dX = Math.max(dX, -swipeWidth);
dX = Math.min(dX, swipeWidth);
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
return 0.1f;
}
});
mItemTouchHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(mScrollListener);
}
use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class WebFragment method setUpWebControls.
private void setUpWebControls(View view) {
view.findViewById(R.id.toolbar_web).setOnClickListener(v -> scrollToTop());
view.findViewById(R.id.button_back).setOnClickListener(v -> mWebView.goBack());
view.findViewById(R.id.button_forward).setOnClickListener(v -> mWebView.goForward());
view.findViewById(R.id.button_clear).setOnClickListener(v -> {
mSystemUiHelper.setFullscreen(true);
reset();
mControls.showNext();
});
view.findViewById(R.id.button_find).setOnClickListener(v -> {
mEditText.requestFocus();
toggleSoftKeyboard(true);
mControls.showNext();
});
mButtonRefresh.setOnClickListener(v -> {
if (mWebView.getProgress() < 100) {
mWebView.stopLoading();
} else {
mWebView.reload();
}
});
view.findViewById(R.id.button_exit).setOnClickListener(v -> LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(EXTRA_FULLSCREEN, false)));
mButtonNext.setOnClickListener(v -> mWebView.findNext(true));
mButtonMore.setOnClickListener(v -> mPopupMenu.create(getActivity(), mButtonMore, Gravity.NO_GRAVITY).inflate(R.menu.menu_web).setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.menu_font_options) {
showPreferences();
return true;
}
if (item.getItemId() == R.id.menu_zoom_in) {
mWebView.zoomIn();
return true;
}
if (item.getItemId() == R.id.menu_zoom_out) {
mWebView.zoomOut();
return true;
}
return false;
}).setMenuItemVisible(R.id.menu_font_options, fontEnabled()).show());
mEditText.setOnEditorActionListener((v, actionId, event) -> {
findInPage();
return true;
});
}
use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class StoryRecyclerViewAdapter method setUpdated.
private void setUpdated(ArrayList<Item> items) {
if (!mHighlightUpdated || getItems() == null) {
return;
}
mUpdated.clear();
mUpdatedPositions.clear();
mPromoted.clear();
for (Item item : items) {
Integer position = mItemPositions.get(item.getLongId());
if (position == null) {
mUpdated.add(item);
mUpdatedPositions.put(item.getLongId(), mUpdated.size() - 1);
} else {
Item currentRevision = mItems.get(position);
item.setLastKidCount(currentRevision.getLastKidCount());
int lastRank = currentRevision.getRank();
if (lastRank > item.getRank()) {
mPromoted.put(item.getId(), lastRank - item.getRank());
}
}
}
if (!mUpdated.isEmpty()) {
notifyUpdated();
}
}
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;
}
}
use of io.github.hidroh.materialistic.data.Item 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));
}
});
}
Aggregations