use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class ItemFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
if (savedInstanceState != null) {
mCacheMode = savedInstanceState.getInt(STATE_CACHE_MODE, ItemManager.MODE_DEFAULT);
mItem = savedInstanceState.getParcelable(STATE_ITEM);
mItemId = savedInstanceState.getString(STATE_ITEM_ID);
mAdapterItems = savedInstanceState.getParcelable(STATE_ADAPTER_ITEMS);
} else {
mCacheMode = getArguments().getInt(EXTRA_CACHE_MODE, ItemManager.MODE_DEFAULT);
WebItem item = getArguments().getParcelable(EXTRA_ITEM);
if (item instanceof Item) {
mItem = (Item) item;
}
mItemId = item != null ? item.getId() : null;
}
}
use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class StoryRecyclerViewAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
ContentResolver cr = recyclerView.getContext().getContentResolver();
cr.registerContentObserver(MaterialisticProvider.URI_VIEWED, true, mObserver);
cr.registerContentObserver(MaterialisticProvider.URI_FAVORITE, true, mObserver);
mCallback = new ItemTouchHelperCallback(recyclerView.getContext(), Preferences.getListSwipePreferences(recyclerView.getContext())) {
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
Item item = getItem(viewHolder.getAdapterPosition());
if (item == null) {
return 0;
}
mSaved = item.isFavorite();
return checkSwipeDir(0, ItemTouchHelper.LEFT, mCallback.getLeftSwipeAction(), item) | checkSwipeDir(0, ItemTouchHelper.RIGHT, mCallback.getRightSwipeAction(), item);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
Preferences.SwipeAction action = direction == ItemTouchHelper.LEFT ? getLeftSwipeAction() : getRightSwipeAction();
Item item = getItem(viewHolder.getAdapterPosition());
if (item == null) {
return;
}
switch(action) {
case Save:
toggleSave(item);
break;
case Refresh:
refresh(item, viewHolder);
break;
case Vote:
notifyItemChanged(viewHolder.getAdapterPosition());
vote(item, viewHolder);
break;
}
}
private int checkSwipeDir(int swipeDirs, int swipeDir, Preferences.SwipeAction action, Item item) {
switch(action) {
case None:
break;
case Vote:
if (!item.isVoted() && !item.isPendingVoted()) {
swipeDirs |= swipeDir;
}
break;
default:
swipeDirs |= swipeDir;
break;
}
return swipeDirs;
}
};
mItemTouchHelper = new ItemTouchHelper(mCallback);
mItemTouchHelper.attachToRecyclerView(recyclerView);
toggleAutoMarkAsViewed(recyclerView.getContext());
mPrefObservable.subscribe(recyclerView.getContext(), (key, contextChanged) -> {
mCallback.setSwipePreferences(recyclerView.getContext(), Preferences.getListSwipePreferences(recyclerView.getContext()));
notifyDataSetChanged();
}, R.string.pref_list_swipe_left, R.string.pref_list_swipe_right);
}
use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class StoryRecyclerViewAdapter method markAsViewed.
@Synthetic
void markAsViewed(int position) {
if (position < 0) {
return;
}
Item item = mItems != null && position < mItems.size() ? mItems.get(position) : null;
if (item == null || !isItemAvailable(item) || item.isViewed()) {
return;
}
mSessionManager.view(mContext, item.getId());
}
use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class StoryRecyclerViewAdapter method loadItem.
@Override
protected void loadItem(final int adapterPosition) {
Item item = getItem(adapterPosition);
if (item.getLocalRevision() == 0) {
return;
}
item.setLocalRevision(0);
mItemManager.getItem(item.getId(), getItemCacheMode(), new ItemResponseListener(this, item));
}
use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.
the class StoryRecyclerViewAdapter method bindItem.
@Override
protected void bindItem(final ItemViewHolder holder) {
final Item story = getItem(holder.getAdapterPosition());
bindItemUpdated(holder, story);
highlightUserPost(holder, story);
holder.mStoryView.setViewed(story.isViewed());
if (story.getLocalRevision() < mFavoriteRevision) {
story.setFavorite(false);
}
holder.mStoryView.setFavorite(story.isFavorite());
holder.itemView.setOnLongClickListener(v -> {
showMoreOptions(holder.mStoryView.getMoreOptions(), story, holder);
return true;
});
holder.mStoryView.getMoreOptions().setOnClickListener(v -> showMoreOptions(v, story, holder));
}
Aggregations