Merge pull request #10024 from osmandapp/HorizontalSelectionAdapterFix

Fix get item by position
This commit is contained in:
Vitaliy 2020-10-14 23:08:16 +03:00 committed by GitHub
commit ed7e379adb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View file

@ -632,7 +632,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
horizontalSelectionAdapter.notifyDataSetChanged();
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPosition(selectedIconCategory));
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory));
for (String name : iconNameList) {
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
}

View file

@ -110,13 +110,16 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
return items.size();
}
public int getItemPosition(String name) {
return items.indexOf(name);
public int getItemPositionByTitle(String title) {
return getItemPosition(getItemByTitle(title));
}
public void setSelectedItemByTitle(String selectedItemTitle) {
HorizontalSelectionItem selectedItem = getItemByTitle(selectedItemTitle);
setSelectedItem(selectedItem);
public int getItemPosition(HorizontalSelectionItem item) {
return items.indexOf(item);
}
public void setSelectedItemByTitle(String title) {
setSelectedItem(getItemByTitle(title));
}
public void setSelectedItem(HorizontalSelectionItem selectedItem) {

View file

@ -122,7 +122,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
}
selectedItem = preference.getEntryFromValue(String.valueOf(currentValue));
adapter.setSelectedItemByTitle(selectedItem);
int itemPosition = adapter.getItemPosition(selectedItem);
int itemPosition = adapter.getItemPositionByTitle(selectedItem);
if (itemPosition >= 0) {
recyclerView.smoothScrollToPosition(itemPosition);
}