use of android.support.v7.widget.RecyclerView.ViewHolder in project Reader by TheKeeperOfPie.
the class FragmentProfile method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_profile, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
listener = new ControllerProfile.Listener() {
@Override
public void setSortAndTime(Sort sort, Time time) {
menu.findItem(sort.getMenuId()).setChecked(true);
menu.findItem(time.getMenuId()).setChecked(true);
itemSortTime.setTitle(getString(R.string.time_description, menu.findItem(controllerProfile.getTime().getMenuId()).toString()));
}
@Override
public void setPage(Page page) {
spinnerPage.setSelection(adapterProfilePage.getPages().indexOf(page));
if (page.getPage().equals(ControllerProfile.PAGE_HIDDEN)) {
callback.setDrawable(getResources().getDrawable(R.drawable.ic_visibility_white_24dp));
} else {
callback.setDrawable(getResources().getDrawable(R.drawable.ic_visibility_off_white_24dp));
}
}
@Override
public void setIsUser(boolean isUser) {
// TODO: Fix set page for Profile view
adapterProfilePage.setIsUser(isUser);
}
@Override
public void loadLink(Comment comment) {
Log.d(TAG, "Link ID: " + comment.getLinkId());
Intent intent = new Intent(activity, ActivityMain.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(ActivityMain.REDDIT_PAGE, Reddit.BASE_URL + "/r/" + comment.getSubreddit() + "/comments/" + comment.getLinkId().replace("t3_", ""));
startActivity(intent);
}
@Override
public RecyclerView.Adapter getAdapter() {
return adapterProfile;
}
@Override
public void setToolbarTitle(CharSequence title) {
toolbar.setTitle(title);
}
@Override
public void setRefreshing(boolean refreshing) {
swipeRefreshProfile.setRefreshing(refreshing);
}
@Override
public void post(Runnable runnable) {
recyclerProfile.post(runnable);
}
};
int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(activity, UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
toolbar = (Toolbar) activity.getLayoutInflater().cloneInContext(contextThemeWrapper).inflate(R.layout.toolbar, layoutAppBar, false);
layoutAppBar.addView(toolbar);
((AppBarLayout.LayoutParams) toolbar.getLayoutParams()).setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
if (getFragmentManager().getBackStackEntryCount() <= 1) {
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.openDrawer();
}
});
} else {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onNavigationBackClick();
}
});
}
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
setUpOptionsMenu();
adapterProfilePage = new AdapterProfilePage(activity);
spinnerPage = new AppCompatSpinner(contextThemeWrapper);
toolbar.addView(spinnerPage);
((Toolbar.LayoutParams) spinnerPage.getLayoutParams()).setMarginEnd((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
spinnerPage.setAdapter(adapterProfilePage);
spinnerPage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
controllerProfile.setPage(adapterProfilePage.getItem(position)).subscribe(getReloadObserver());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
swipeRefreshProfile = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_profile);
swipeRefreshProfile.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
controllerProfile.reload().subscribe(getReloadObserver());
}
});
linearLayoutManager = new LinearLayoutManager(activity);
recyclerProfile = (RecyclerView) view.findViewById(R.id.recycler_profile);
recyclerProfile.setHasFixedSize(true);
recyclerProfile.setItemAnimator(null);
recyclerProfile.setLayoutManager(linearLayoutManager);
recyclerProfile.addItemDecoration(new ItemDecorationDivider(activity, ItemDecorationDivider.VERTICAL_LIST));
AdapterListener adapterListener = new AdapterListener() {
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerProfile, false);
}
@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void clearDecoration() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestMore() {
controllerProfile.loadMoreLinks().observeOn(AndroidSchedulers.mainThread()).subscribe(new ObserverError<Listing>() {
@Override
public void onError(Throwable e) {
Toast.makeText(getContext(), getString(R.string.error_loading_links), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
recyclerProfile.requestDisallowInterceptTouchEvent(disallow);
swipeRefreshProfile.requestDisallowInterceptTouchEvent(disallow);
itemTouchHelper.select(null, CustomItemTouchHelper.ACTION_STATE_IDLE);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
itemTouchHelper.setDisallow(disallow);
}
};
AdapterLink.ViewHolderLink.Listener listenerLink = new AdapterLink.ViewHolderLink.Listener() {
@Override
public void onSubmitComment(Link link, String text) {
}
@Override
public void onDownloadImage(Link link) {
}
@Override
public void onDownloadImage(Link link, String title, String fileName, String url) {
}
@Override
public void onLoadUrl(Link link, boolean forceExternal) {
}
@Override
public void onShowFullEditor(Link link) {
}
@Override
public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
}
@Override
public void onCopyText(Link link) {
}
@Override
public void onEdit(Link link) {
}
@Override
public void onDelete(Link link) {
}
@Override
public void onReport(Link link) {
}
@Override
public void onSave(Link link) {
}
@Override
public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
}
@Override
public void onShowError(String error) {
}
@Override
public void onMarkNsfw(Link link) {
}
};
AdapterCommentList.ViewHolderComment.Listener listenerComments = new AdapterCommentList.ViewHolderComment.Listener() {
@Override
public void onToggleComment(Comment comment) {
}
@Override
public void onShowReplyEditor(Comment comment) {
}
@Override
public void onEditComment(Comment comment, String text) {
}
@Override
public void onSendComment(Comment comment, String text) {
}
@Override
public void onMarkRead(Comment comment) {
}
@Override
public void onLoadNestedComments(Comment comment) {
}
@Override
public void onJumpToParent(Comment comment) {
}
@Override
public void onViewProfile(Comment comment) {
}
@Override
public void onCopyText(Comment comment) {
}
@Override
public void onDeleteComment(Comment comment) {
}
@Override
public void onReport(Comment comment) {
}
@Override
public void onVoteComment(Comment comment, AdapterCommentList.ViewHolderComment viewHolderComment, Likes vote) {
}
@Override
public void onSave(Comment comment) {
}
};
if (adapterProfile == null) {
adapterProfile = new AdapterProfile(getActivity(), controllerProfile, adapterListener, listenerLink, listenerComments, listener);
}
recyclerProfile.setAdapter(adapterProfile);
callback = new CustomItemTouchHelper.SimpleCallback(activity, R.drawable.ic_delete_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
int position = viewHolder.getAdapterPosition();
if (position == 2 || (position >= 6 && controllerProfile.getViewType(position - 6) == ControllerProfile.VIEW_TYPE_LINK)) {
return super.getSwipeDirs(recyclerView, viewHolder);
}
return 0;
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
Log.d(TAG, "onSwiped: " + viewHolder.getAdapterPosition());
final int adapterPosition = viewHolder.getAdapterPosition();
final int position = adapterPosition == 2 ? -1 : adapterPosition - 6;
final Link link = adapterPosition == 2 ? controllerProfile.remove(-1) : controllerProfile.remove(position);
mListener.getEventListenerBase().hide(link);
if (snackbar != null) {
snackbar.dismiss();
}
SpannableString text = new SpannableString(link.isHidden() ? getString(R.string.link_hidden) : getString(R.string.link_shown));
text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//noinspection ResourceType
snackbar = Snackbar.make(recyclerProfile, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.getEventListenerBase().hide(link);
if (adapterPosition == 2) {
controllerProfile.setTopLink(link);
adapterProfile.notifyItemChanged(2);
} else {
controllerProfile.add(position, link);
}
recyclerProfile.invalidate();
}
});
snackbar.getView().setBackgroundColor(themer.getColorPrimary());
snackbar.show();
}
};
itemTouchHelper = new CustomItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerProfile);
return view;
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project Reader by TheKeeperOfPie.
the class FragmentSearch method onCreateView.
// TODO: Remove/fix ResourceType warning
@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = bind(inflater.inflate(R.layout.fragment_search, container, false));
listenerSearch = new ControllerSearch.Listener() {
@Override
public AdapterSearchSubreddits getAdapterSearchSubreddits() {
return adapterSearchSubreddits;
}
@Override
public AdapterSearchSubreddits getAdapterSearchSubredditsRecommended() {
return adapterSearchSubredditsRecommended;
}
@Override
public void scrollToLinks(int position) {
layoutManagerLinks.scrollToPositionWithOffset(0, 0);
}
@Override
public void scrollToLinksSubreddit(int position) {
layoutManagerLinksSubreddit.scrollToPositionWithOffset(0, 0);
}
};
int windowBackground = UtilsTheme.getAttributeColor(getContext(), android.R.attr.windowBackground, 0);
setUpToolbar();
adapterSearchSubreddits = new AdapterSearchSubreddits(getActivity(), new ControllerSearchBase() {
@Override
public Subreddit getSubreddit(int position) {
return controllerSearch.getSubreddit(position);
}
@Override
public int getSubredditCount() {
return controllerSearch.getCountSubreddit();
}
}, new AdapterSearchSubreddits.ViewHolder.EventListener() {
@Override
public void onClickSubreddit(Subreddit subreddit) {
controllerSearch.addViewedSubreddit(subreddit);
controllerLinks.setParameters(subreddit.getDisplayName(), Sort.HOT, Time.ALL);
closeKeyboard();
mListener.onNavigationBackClick();
}
@Override
public boolean supportsDrag() {
return true;
}
@Override
public void onStartDrag(AdapterSearchSubreddits.ViewHolder viewHolder) {
itemTouchHelperSubreddits.startDrag(viewHolder);
}
@Override
public void sendToTop(AdapterSearchSubreddits.ViewHolder viewHolder) {
controllerSearch.moveSubreddit(viewHolder.getAdapterPosition(), 0);
recyclerSearchSubreddits.postOnAnimationDelayed(() -> {
if (layoutManagerSubreddits.findFirstVisibleItemPosition() <= 1) {
layoutManagerSubreddits.smoothScrollToPosition(recyclerSearchSubreddits, null, 0);
}
}, 150);
}
@Override
public boolean isSubscriptionListShown() {
return controllerSearch.isSubscriptionListShown();
}
});
layoutManagerSubreddits = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerSearchSubreddits.setLayoutManager(layoutManagerSubreddits);
recyclerSearchSubreddits.setAdapter(adapterSearchSubreddits);
recyclerSearchSubreddits.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
itemTouchHelperSubreddits = new ItemTouchHelper(new SimpleCallbackBackground(0, 0, windowBackground) {
@Override
public int getDragDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (controllerSearch.isSubscriptionListShown()) {
return ItemTouchHelper.UP | ItemTouchHelper.DOWN;
}
return super.getDragDirs(recyclerView, viewHolder);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
controllerSearch.moveSubreddit(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
});
itemTouchHelperSubreddits.attachToRecyclerView(recyclerSearchSubreddits);
AdapterLink.ViewHolderLink.Listener listenerLink = new AdapterLink.ViewHolderLink.Listener() {
@Override
public void onSubmitComment(Link link, String text) {
}
@Override
public void onDownloadImage(Link link) {
}
@Override
public void onDownloadImage(Link link, String title, String fileName, String url) {
}
@Override
public void onLoadUrl(Link link, boolean forceExternal) {
}
@Override
public void onShowFullEditor(Link link) {
}
@Override
public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
}
@Override
public void onCopyText(Link link) {
}
@Override
public void onEdit(Link link) {
}
@Override
public void onDelete(Link link) {
}
@Override
public void onReport(Link link) {
}
@Override
public void onSave(Link link) {
}
@Override
public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
}
@Override
public void onShowError(String error) {
}
@Override
public void onMarkNsfw(Link link) {
}
};
adapterLinks = new AdapterSearchLinkList(getActivity(), new AdapterListener() {
@Override
public void requestMore() {
controllerSearch.loadMoreLinks().subscribe(getReloadObserver());
}
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerSearchLinks, false);
}
@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void clearDecoration() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
recyclerSearchLinks.requestDisallowInterceptTouchEvent(disallow);
recyclerSearchLinksSubreddit.requestDisallowInterceptTouchEvent(disallow);
pagerSearch.requestDisallowInterceptTouchEvent(disallow);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
}
}, new AdapterLink.ViewHolderHeader.EventListener() {
@Override
public void onClickSubmit(Reddit.PostType postType) {
}
@Override
public void showSidebar() {
}
}, listenerLink, Source.SEARCH_LINKS);
adapterLinksSubreddit = new AdapterSearchLinkList(getActivity(), new AdapterListener() {
@Override
public void requestMore() {
controllerSearch.loadMoreLinksSubreddit().subscribe(getReloadObserver());
}
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerSearchLinksSubreddit, false);
}
@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void clearDecoration() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
recyclerSearchLinks.requestDisallowInterceptTouchEvent(disallow);
recyclerSearchLinksSubreddit.requestDisallowInterceptTouchEvent(disallow);
pagerSearch.requestDisallowInterceptTouchEvent(disallow);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
}
}, new AdapterLink.ViewHolderHeader.EventListener() {
@Override
public void onClickSubmit(Reddit.PostType postType) {
}
@Override
public void showSidebar() {
}
}, listenerLink, Source.SEARCH_LINKS_SUBREDDIT);
layoutManagerLinks = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerSearchLinks.setLayoutManager(layoutManagerLinks);
recyclerSearchLinks.setAdapter(adapterLinks);
recyclerSearchLinks.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
layoutManagerLinksSubreddit = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerSearchLinksSubreddit.setLayoutManager(layoutManagerLinksSubreddit);
recyclerSearchLinksSubreddit.setAdapter(adapterLinksSubreddit);
recyclerSearchLinksSubreddit.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
adapterSearchSubredditsRecommended = new AdapterSearchSubreddits(getActivity(), new ControllerSearchBase() {
@Override
public Subreddit getSubreddit(int position) {
return controllerSearch.getSubredditRecommended(position);
}
@Override
public int getSubredditCount() {
return controllerSearch.getCountSubredditRecommended();
}
}, new AdapterSearchSubreddits.ViewHolder.EventListener() {
@Override
public void onClickSubreddit(Subreddit subreddit) {
controllerLinks.setParameters(subreddit.getDisplayName(), Sort.HOT, Time.ALL);
closeKeyboard();
mListener.onNavigationBackClick();
}
@Override
public boolean supportsDrag() {
return false;
}
@Override
public void onStartDrag(AdapterSearchSubreddits.ViewHolder viewHolder) {
}
@Override
public void sendToTop(AdapterSearchSubreddits.ViewHolder viewHolder) {
}
@Override
public boolean isSubscriptionListShown() {
return controllerSearch.isSubscriptionListShown();
}
});
layoutManagerSubredditsRecommended = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerSearchSubredditsRecommended.setLayoutManager(layoutManagerSubredditsRecommended);
recyclerSearchSubredditsRecommended.setAdapter(adapterSearchSubredditsRecommended);
recyclerSearchSubredditsRecommended.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
pagerSearch.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
controllerSearch.setCurrentPage(position).subscribe(getReloadObserver());
boolean sortSubredditsShown = controllerSearch.getCurrentPage() == ControllerSearch.PAGE_SUBREDDITS || controllerSearch.getCurrentPage() == ControllerSearch.PAGE_SUBREDDITS_RECOMMENDED;
menu.findItem(R.id.item_sort_subreddits).setEnabled(sortSubredditsShown);
menu.findItem(R.id.item_sort_subreddits).setVisible(sortSubredditsShown);
menu.findItem(R.id.item_sort).setEnabled(!sortSubredditsShown);
menu.findItem(R.id.item_sort).setVisible(!sortSubredditsShown);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
final int count = controllerLinks.isOnSpecificSubreddit() ? pagerSearch.getChildCount() : pagerSearch.getChildCount() - 1;
pagerAdapter = new PagerAdapter() {
@Override
public Object instantiateItem(ViewGroup container, int position) {
return pagerSearch.getChildAt(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// No need to destroy the RecyclerViews since they'll be reused for a new query
}
@Override
public CharSequence getPageTitle(int position) {
switch(position) {
case ControllerSearch.PAGE_SUBREDDITS:
return getString(R.string.subreddit);
case ControllerSearch.PAGE_LINKS:
return getString(R.string.all);
case ControllerSearch.PAGE_LINKS_SUBREDDIT:
return controllerLinks.getSubredditName();
case ControllerSearch.PAGE_SUBREDDITS_RECOMMENDED:
return getString(R.string.recommended);
}
return super.getPageTitle(position);
}
@Override
public int getCount() {
return count;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
};
pagerSearch.setAdapter(pagerAdapter);
layoutTabs.setTabMode(TabLayout.MODE_SCROLLABLE);
layoutTabs.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
layoutTabs.setBackgroundColor(getResources().getColor(android.R.color.transparent));
layoutTabs.setupWithViewPager(pagerSearch);
pagerSearch.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(layoutTabs));
return view;
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project BoomMenu by Nightonke.
the class RecyclerViewAdapter method onCreateViewHolder.
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, null, false);
view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
return new ViewHolder(view);
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project CoCoin by Nightonke.
the class MonthViewRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
if (IS_EMPTY) {
holder.expanseSum.setText("¥0");
holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.emptyTip.setText(mContext.getResources().getString(R.string.tag_empty));
holder.emptyTip.setTypeface(CoCoinUtil.GetTypeface());
holder.tags.setVisibility(View.GONE);
holder.date.setVisibility(View.INVISIBLE);
holder.pie.setVisibility(View.INVISIBLE);
holder.iconLeft.setVisibility(View.INVISIBLE);
holder.iconRight.setVisibility(View.INVISIBLE);
holder.all.setVisibility(View.GONE);
} else {
holder.date.setText(dateStringList.get(position));
holder.expanseSum.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position)));
holder.date.setTypeface(CoCoinUtil.GetTypeface());
holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.tags.setTypeface(CoCoinUtil.typefaceLatoLight);
if ("zh".equals(CoCoinUtil.GetLanguage())) {
holder.tags.setText(" ● " + records + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_records) + tags + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_tags));
} else {
holder.tags.setText(" ● " + records + " " + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_records) + " " + tags + " " + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_tags));
}
if (SumList.get(position).equals(Double.valueOf(0))) {
holder.emptyTip.setVisibility(View.VISIBLE);
holder.emptyTip.setTypeface(CoCoinUtil.typefaceLatoLight);
} else {
holder.emptyTip.setVisibility(View.GONE);
}
holder.pie.setPieChartData(pieChartDataList.get(position));
holder.pie.setOnValueTouchListener(new PieValueTouchListener(position));
holder.pie.setChartRotationEnabled(false);
if (!SumList.get(position).equals(Double.valueOf(0))) {
holder.iconRight.setVisibility(View.VISIBLE);
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectedPositionList.set(position, (selectedPositionList.get(position) + 1) % sliceValuesList.get(position).size());
SelectedValue selectedValue = new SelectedValue(selectedPositionList.get(position), 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
holder.iconLeft.setVisibility(View.VISIBLE);
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectedPositionList.set(position, (selectedPositionList.get(position) - 1 + sliceValuesList.get(position).size()) % sliceValuesList.get(position).size());
SelectedValue selectedValue = new SelectedValue(selectedPositionList.get(position), 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
} else {
holder.iconLeft.setVisibility(View.GONE);
holder.iconRight.setVisibility(View.GONE);
}
holder.all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = mContext.getResources().getString(R.string.in) + dateStringList.get(position) + " " + CoCoinUtil.GetSpendString((int) (double) SumList.get(position));
} else {
dialogTitle = CoCoinUtil.GetSpendString((int) (double) SumList.get(position)) + mContext.getResources().getString(R.string.in) + " " + dateStringList.get(position);
}
((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, list, dialogTitle), "MyDialog").commit();
}
});
}
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project CoCoin by Nightonke.
the class TagViewRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
switch(getItemViewType(position)) {
case TYPE_HEADER:
if (IS_EMPTY) {
holder.sum.setText(mContext.getResources().getString(R.string.tag_empty));
holder.sum.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
holder.from.setVisibility(View.INVISIBLE);
holder.to.setVisibility(View.INVISIBLE);
} else {
holder.from.setText(mContext.getResources().getString(R.string.from) + " " + startYear + " " + CoCoinUtil.GetMonthShort(startMonth));
holder.sum.setText(CoCoinUtil.GetInMoney((int) Sum));
holder.to.setText(mContext.getResources().getString(R.string.to) + " " + endYear + " " + CoCoinUtil.GetMonthShort(endMonth));
holder.to.setTypeface(CoCoinUtil.GetTypeface());
holder.from.setTypeface(CoCoinUtil.GetTypeface());
}
holder.sum.setTypeface(CoCoinUtil.typefaceLatoLight);
break;
case TYPE_CELL:
int year = contents.get(position - 1).get(0).getCalendar().get(Calendar.YEAR);
int month = contents.get(position - 1).get(0).getCalendar().get(Calendar.MONTH) + 1;
PieChartData pieChartData;
List<SubcolumnValue> subcolumnValues;
final List<Column> columns;
ColumnChartData columnChartData;
final List<SliceValue> sliceValues;
holder.date.setTypeface(CoCoinUtil.GetTypeface());
holder.expanse.setTypeface(CoCoinUtil.GetTypeface());
switch(chartType) {
case PIE:
sliceValues = new ArrayList<>();
for (Map.Entry<Integer, Double> entry : AllTagExpanse.get(position - 1).entrySet()) {
if (entry.getValue() >= 1) {
SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), mContext.getResources().getColor(CoCoinUtil.GetTagColorResource(entry.getKey())));
sliceValue.setLabel(String.valueOf(entry.getKey()));
sliceValues.add(sliceValue);
}
}
pieChartData = new PieChartData(sliceValues);
pieChartData.setHasLabels(false);
pieChartData.setHasLabelsOnlyForSelected(false);
pieChartData.setHasLabelsOutside(false);
pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
holder.pie.setPieChartData(pieChartData);
holder.pie.setOnValueTouchListener(new PieValueTouchListener(position - 1));
holder.pie.setChartRotationEnabled(false);
if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
} else {
holder.date.setText(year + " ");
}
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SelectedPosition[position] = (SelectedPosition[position] + 1) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SelectedPosition[position] = (SelectedPosition[position] - 1 + sliceValues.size()) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
break;
case SUM_HISTOGRAM:
columns = new ArrayList<>();
if (type.get(position - 1).equals(SHOW_IN_YEAR)) {
int numColumns = 12;
for (int i = 0; i < numColumns; i++) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue(MonthExpanseSum[(year - startYear) * 12 + i], CoCoinUtil.GetRandomColor());
value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + year);
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < numColumns; i++) {
axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetMonthShort(i + 1)));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + "");
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
Calendar tempCal = new GregorianCalendar(year, month - 1, 1);
int daysInMonth = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
int numColumns = daysInMonth;
for (int i = 0; i < numColumns; ++i) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue((float) DayExpanseSum[(year - startYear) * 372 + (month - 1) * 31 + i], CoCoinUtil.GetRandomColor());
value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + (i + 1) + " " + year);
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < daysInMonth; i++) {
axisValueList.add(new AxisValue(i).setLabel(i + 1 + ""));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] + 1) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.COLUMN);
holder.chart.selectValue(selectedValue);
}
});
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] - 1 + columns.size()) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.COLUMN);
holder.chart.selectValue(selectedValue);
}
});
break;
case HISTOGRAM:
columns = new ArrayList<>();
if (type.get(position - 1).equals(SHOW_IN_YEAR)) {
int numColumns = 12;
for (int i = 0; i < numColumns; i++) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue(MonthExpanseSum[(year - startYear) * 12 + i], CoCoinUtil.GetRandomColor());
value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + year);
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < numColumns; i++) {
axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetMonthShort(i + 1)));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + "");
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
Calendar tempCal = Calendar.getInstance();
tempCal.set(year, month - 1, 1);
tempCal.add(Calendar.SECOND, 0);
int daysInMonth = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
int p = contents.get(position - 1).size() - 1;
int numColumns = daysInMonth;
for (int i = 0; i < numColumns; ++i) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue(0, CoCoinUtil.GetRandomColor());
subcolumnValues.add(value);
while (p >= 0 && contents.get(position - 1).get(p).getCalendar().get(Calendar.DAY_OF_MONTH) == i + 1) {
subcolumnValues.get(0).setValue(subcolumnValues.get(0).getValue() + (float) contents.get(position - 1).get(p).getMoney());
subcolumnValues.get(0).setLabel(p + "");
p--;
}
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < daysInMonth; i++) {
axisValueList.add(new AxisValue(i).setLabel(i + 1 + ""));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] + 1) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.chart.selectValue(selectedValue);
}
});
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] - 1 + columns.size()) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.chart.selectValue(selectedValue);
}
});
break;
}
}
}
Aggregations