use of com.winsonchiu.reader.theme.ThemeWrapper 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 com.winsonchiu.reader.theme.ThemeWrapper in project Reader by TheKeeperOfPie.
the class FragmentInbox method onCreateView.
@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_inbox, container, false);
listener = new ControllerInbox.Listener() {
@Override
public void setPage(Page page) {
spinnerPage.setSelection(adapterInboxPage.getPages().indexOf(page));
}
@Override
public RecyclerView.Adapter getAdapter() {
return adapterInbox;
}
@Override
public void setToolbarTitle(CharSequence title) {
toolbar.setTitle(title);
}
@Override
public void setRefreshing(boolean refreshing) {
swipeRefreshInbox.setRefreshing(refreshing);
}
@Override
public void post(Runnable runnable) {
recyclerInbox.post(runnable);
}
};
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
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);
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.openDrawer();
}
});
setUpOptionsMenu();
floatingActionButtonNewMessage = (FloatingActionButton) view.findViewById(R.id.fab_new_message);
floatingActionButtonNewMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentNewMessage fragmentNewMessage = FragmentNewMessage.newInstance();
getFragmentManager().beginTransaction().hide(FragmentInbox.this).add(R.id.frame_fragment, fragmentNewMessage, FragmentNewMessage.TAG).addToBackStack(null).commit();
}
});
floatingActionButtonNewMessage.setColorFilter(themer.getColorFilterAccent());
behaviorFloatingActionButton = new ScrollAwareFloatingActionButtonBehavior(activity, null, new ScrollAwareFloatingActionButtonBehavior.OnVisibilityChangeListener() {
@Override
public void onStartHideFromScroll() {
}
@Override
public void onEndHideFromScroll() {
}
});
((CoordinatorLayout.LayoutParams) floatingActionButtonNewMessage.getLayoutParams()).setBehavior(behaviorFloatingActionButton);
adapterInboxPage = new AdapterInboxPage(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(adapterInboxPage);
spinnerPage.setSelection(adapterInboxPage.getPages().indexOf(controllerInbox.getPage()));
spinnerPage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
controllerInbox.setPage(adapterInboxPage.getItem(position));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
swipeRefreshInbox = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_inbox);
swipeRefreshInbox.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
controllerInbox.reload();
}
});
linearLayoutManager = new LinearLayoutManager(activity);
recyclerInbox = (RecyclerView) view.findViewById(R.id.recycler_inbox);
recyclerInbox.setHasFixedSize(true);
recyclerInbox.setItemAnimator(new DefaultItemAnimator());
recyclerInbox.getItemAnimator().setRemoveDuration(UtilsAnimation.EXPAND_ACTION_DURATION);
recyclerInbox.setLayoutManager(linearLayoutManager);
recyclerInbox.addItemDecoration(new ItemDecorationDivider(activity, ItemDecorationDivider.VERTICAL_LIST));
AdapterListener adapterListener = new AdapterListener() {
@Override
public void scrollAndCenter(int position, int height) {
linearLayoutManager.scrollToPositionWithOffset(position, 0);
}
@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() {
behaviorFloatingActionButton.animateOut(floatingActionButtonNewMessage);
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestMore() {
controllerInbox.loadMore();
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
recyclerInbox.requestDisallowInterceptTouchEvent(disallow);
swipeRefreshInbox.requestDisallowInterceptTouchEvent(disallow);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
}
};
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 (adapterInbox == null) {
adapterInbox = new AdapterInbox(controllerInbox, controllerUser, adapterListener, listenerComments, mListener.getEventListenerBase());
}
recyclerInbox.setAdapter(adapterInbox);
return view;
}
use of com.winsonchiu.reader.theme.ThemeWrapper in project Reader by TheKeeperOfPie.
the class FragmentHistory method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_history, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(getActivity(), UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
toolbar = (Toolbar) getActivity().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(v -> mListener.openDrawer());
} else {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(v -> mListener.onNavigationBackClick());
}
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setTitle(R.string.history);
setUpOptionsMenu();
swipeRefreshHistory = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_history);
swipeRefreshHistory.setOnRefreshListener(() -> controllerHistory.reload());
AdapterLink.ViewHolderHeader.EventListener eventListenerHeader = new AdapterLink.ViewHolderHeader.EventListener() {
@Override
public void onClickSubmit(Reddit.PostType postType) {
}
@Override
public void showSidebar() {
}
};
AdapterListener adapterListener = new AdapterListener() {
@Override
public void requestMore() {
controllerHistory.loadMoreLinks().observeOn(AndroidSchedulers.mainThread()).subscribe(new ObserverError<Listing>() {
@Override
public void onError(Throwable e) {
Toast.makeText(getContext(), getContext().getString(R.string.error_loading_links), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerHistory, 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) {
swipeRefreshHistory.requestDisallowInterceptTouchEvent(disallow);
recyclerHistory.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) {
}
};
if (adapterLinkList == null) {
adapterLinkList = new AdapterHistoryLinkList(getActivity(), adapterListener, eventListenerHeader, listenerLink);
}
if (adapterLinkGrid == null) {
adapterLinkGrid = new AdapterHistoryLinkGrid(getActivity(), adapterListener, eventListenerHeader, listenerLink);
}
if (AppSettings.MODE_LIST.equals(preferences.getString(AppSettings.INTERFACE_MODE, AppSettings.MODE_GRID))) {
adapterLink = adapterLinkList;
} else {
adapterLink = adapterLinkGrid;
}
layoutManager = adapterLink.getLayoutManager();
itemDecorationDivider = new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST);
recyclerHistory = (RecyclerView) view.findViewById(R.id.recycler_history);
recyclerHistory.setHasFixedSize(true);
recyclerHistory.setItemAnimator(null);
resetAdapter(adapterLink);
itemTouchHelper = new CustomItemTouchHelper(new CustomItemTouchHelper.SimpleCallback(getActivity(), R.drawable.ic_visibility_off_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {
@Override
public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
if (layoutManager instanceof StaggeredGridLayoutManager) {
return 1f / ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
}
return 0.4f;
}
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder.getAdapterPosition() == 0) {
return 0;
}
ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams && !((StaggeredGridLayoutManager.LayoutParams) layoutParams).isFullSpan()) {
int spanCount = layoutManager instanceof StaggeredGridLayoutManager ? ((StaggeredGridLayoutManager) layoutManager).getSpanCount() : 2;
int spanIndex = ((StaggeredGridLayoutManager.LayoutParams) layoutParams).getSpanIndex() % spanCount;
if (spanIndex == 0) {
return ItemTouchHelper.END;
} else if (spanIndex == spanCount - 1) {
return ItemTouchHelper.START;
}
}
return super.getSwipeDirs(recyclerView, viewHolder);
}
@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) {
final int position = viewHolder.getAdapterPosition();
final Link link = controllerHistory.remove(position);
if (snackbar != null) {
snackbar.dismiss();
}
SpannableString text = new SpannableString(getString(R.string.history_entry_deleted));
text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//noinspection ResourceType
snackbar = Snackbar.make(recyclerHistory, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerHistory.add(position, link);
recyclerHistory.invalidate();
}
});
snackbar.getView().setBackgroundColor(themer.getColorPrimary());
snackbar.show();
}
});
itemTouchHelper.attachToRecyclerView(recyclerHistory);
if (layoutManager instanceof LinearLayoutManager) {
recyclerHistory.setPadding(0, 0, 0, 0);
} else {
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
recyclerHistory.setPadding(padding, 0, padding, 0);
}
return view;
}
Aggregations