Favorites icon groups jump after selection.

This commit is contained in:
androiddevkotlin 2021-03-30 14:39:35 +03:00
parent adbcb141a7
commit 8fe9fc99d3

View file

@ -619,6 +619,26 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
} }
private void createIconForCategory() { private void createIconForCategory() {
createIconList();
final HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(app, nightMode);
horizontalSelectionAdapter.setTitledItems(new ArrayList<>(iconCategories.keySet()));
horizontalSelectionAdapter.setSelectedItemByTitle(selectedIconCategory);
horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() {
@Override
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
selectedIconCategory = item.getTitle();
createIconList();
updateIconSelector(selectedIcon, PointEditorFragmentNew.this.view);
horizontalSelectionAdapter.notifyDataSetChanged();
}
});
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.group_name_recycler_view);
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
}
private void createIconList() {
FlowLayout selectIcon = view.findViewById(R.id.select_icon); FlowLayout selectIcon = view.findViewById(R.id.select_icon);
selectIcon.removeAllViews(); selectIcon.removeAllViews();
JSONArray iconJsonArray = iconCategories.get(selectedIconCategory); JSONArray iconJsonArray = iconCategories.get(selectedIconCategory);
@ -631,22 +651,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
e.printStackTrace(); e.printStackTrace();
} }
} }
HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(app, nightMode);
horizontalSelectionAdapter.setTitledItems(new ArrayList<>(iconCategories.keySet()));
horizontalSelectionAdapter.setSelectedItemByTitle(selectedIconCategory);
horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() {
@Override
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
selectedIconCategory = item.getTitle();
createIconForCategory();
updateIconSelector(selectedIcon, PointEditorFragmentNew.this.view);
}
});
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.group_name_recycler_view);
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
horizontalSelectionAdapter.notifyDataSetChanged();
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory));
for (String name : iconNameList) { for (String name : iconNameList) {
int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding); int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding);
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(minimalPaddingBetweenIcon, 0)); selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(minimalPaddingBetweenIcon, 0));