use of androidx.recyclerview.widget.GridLayoutManager in project GestureViews by alexvasilkov.
the class DefaultEndlessRecyclerAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
spanCount = gridManager.getSpanCount();
originalSpanLookup = gridManager.getSpanSizeLookup();
gridManager.setSpanSizeLookup(spanSizes);
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project GestureViews by alexvasilkov.
the class DemoActivity method onPhotosLoaded.
/**
* Photos loading results callback.
*/
@Result(FlickrApi.LOAD_IMAGES_EVENT)
private void onPhotosLoaded(List<Photo> photos, boolean hasMore) {
// RecyclerView will continue scrolling when new items are added, we need to stop it.
// Seems like this buggy behavior was introduced in support library v26.0.x
final boolean onBottom = views.grid.findViewHolderForAdapterPosition(gridAdapter.getCount() - 1) != null;
if (onBottom) {
views.grid.stopScroll();
}
// Setting new photos list
gridAdapter.setPhotos(photos, hasMore);
pagerAdapter.setPhotos(photos);
gridAdapter.onNextItemsLoaded();
// Ensure listener called for 0 position
pagerListener.onPageSelected(views.pager.getCurrentItem());
// Restoring saved state
if (savedPagerPosition != NO_POSITION && savedPagerPosition < photos.size()) {
pagerAdapter.setActivated(true);
listAnimator.enter(savedPagerPosition, false);
}
if (savedGridPosition != NO_POSITION && savedGridPosition < photos.size()) {
GridLayoutManager manager = (GridLayoutManager) Objects.requireNonNull(views.grid.getLayoutManager());
manager.scrollToPositionWithOffset(savedGridPosition, savedGridPositionFromTop);
}
clearScreenState();
}
use of androidx.recyclerview.widget.GridLayoutManager in project Conversations by siacs.
the class GridManager method setupLayoutManager.
public static void setupLayoutManager(final Context context, RecyclerView recyclerView, @DimenRes int desiredSize) {
int maxWidth = context.getResources().getDisplayMetrics().widthPixels;
ColumnInfo columnInfo = calculateColumnCount(context, maxWidth, desiredSize);
Log.d(Config.LOGTAG, "preliminary count=" + columnInfo.count);
MediaAdapter.setMediaSize(recyclerView, columnInfo.width);
recyclerView.setLayoutManager(new GridLayoutManager(context, columnInfo.count));
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
final int availableWidth = recyclerView.getMeasuredWidth();
if (availableWidth == 0) {
Log.e(Config.LOGTAG, "GridManager: available width was 0; probably because layout was hidden");
return;
}
final ColumnInfo columnInfo = calculateColumnCount(context, recyclerView.getMeasuredWidth(), desiredSize);
Log.d(Config.LOGTAG, "final count " + columnInfo.count);
final RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter != null && adapter.getItemCount() != 0) {
Log.e(Config.LOGTAG, "adapter already has items; just go with it now");
return;
}
setupLayoutManagerInternal(recyclerView, columnInfo);
MediaAdapter.setMediaSize(recyclerView, columnInfo.width);
}
});
}
use of androidx.recyclerview.widget.GridLayoutManager in project AntennaPod by AntennaPod.
the class SubscriptionFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_subscriptions, container, false);
toolbar = root.findViewById(R.id.toolbar);
toolbar.setOnMenuItemClickListener(this);
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
}
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
toolbar.inflateMenu(R.menu.subscriptions);
for (int i = 0; i < COLUMN_CHECKBOX_IDS.length; i++) {
// Do this in Java to localize numbers
toolbar.getMenu().findItem(COLUMN_CHECKBOX_IDS[i]).setTitle(String.format(Locale.getDefault(), "%d", i + MIN_NUM_COLUMNS));
}
refreshToolbarState();
if (getArguments() != null) {
displayedFolder = getArguments().getString(ARGUMENT_FOLDER, null);
if (displayedFolder != null) {
toolbar.setTitle(displayedFolder);
}
}
subscriptionRecycler = root.findViewById(R.id.subscriptions_grid);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns()), RecyclerView.VERTICAL, false);
subscriptionRecycler.setLayoutManager(gridLayoutManager);
subscriptionRecycler.addItemDecoration(new SubscriptionsRecyclerAdapter.GridDividerItemDecorator());
gridLayoutManager.setSpanCount(prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns()));
registerForContextMenu(subscriptionRecycler);
subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
progressBar = root.findViewById(R.id.progLoading);
feedsFilteredMsg = root.findViewById(R.id.feeds_filtered_message);
feedsFilteredMsg.setOnClickListener((l) -> SubscriptionsFilterDialog.showDialog(requireContext()));
SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
swipeRefreshLayout.setOnRefreshListener(() -> {
AutoUpdateManager.runImmediate(requireContext());
new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false), getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
});
speedDialView = root.findViewById(R.id.fabSD);
speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay));
speedDialView.inflate(R.menu.nav_feed_action_speeddial);
speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {
@Override
public boolean onMainActionSelected() {
return false;
}
@Override
public void onToggleChanged(boolean isOpen) {
}
});
speedDialView.setOnActionSelectedListener(actionItem -> {
new FeedMultiSelectActionHandler((MainActivity) getActivity(), subscriptionAdapter.getSelectedItems()).handleAction(actionItem.getId());
return true;
});
return root;
}
use of androidx.recyclerview.widget.GridLayoutManager in project AntennaPod by AntennaPod.
the class SubscriptionFragment method setColumnNumber.
private void setColumnNumber(int columns) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) subscriptionRecycler.getLayoutManager();
gridLayoutManager.setSpanCount(columns);
subscriptionAdapter.notifyDataSetChanged();
prefs.edit().putInt(PREF_NUM_COLUMNS, columns).apply();
refreshToolbarState();
}
Aggregations