diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/GroupedImageListQuestAnswerFragment.java b/app/src/main/java/de/westnordost/streetcomplete/quests/GroupedImageListQuestAnswerFragment.java index 4ab609f458..2c929bb423 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/GroupedImageListQuestAnswerFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/GroupedImageListQuestAnswerFragment.java @@ -1,7 +1,10 @@ package de.westnordost.streetcomplete.quests; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.support.annotation.Nullable; +import android.support.v4.widget.NestedScrollView; import android.support.v7.app.AlertDialog; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; @@ -32,10 +35,14 @@ public abstract class GroupedImageListQuestAnswerFragment extends AbstractQuestF { public static final String OSM_VALUE = "osm_value"; + private final Handler uiThread = new Handler(Looper.getMainLooper()); + protected GroupedImageSelectAdapter imageSelector; private Button showMoreButton; private RecyclerView valueList; + private NestedScrollView scrollView; + private List allItems; private List topItems; @@ -54,6 +61,8 @@ public abstract class GroupedImageListQuestAnswerFragment extends AbstractQuestF { View view = super.onCreateView(inflater, container, savedInstanceState); + scrollView = view.findViewById(R.id.scrollView); + View contentView = setContentView(R.layout.quest_generic_list); valueList = contentView.findViewById(R.id.listSelect); @@ -73,6 +82,27 @@ public abstract class GroupedImageListQuestAnswerFragment extends AbstractQuestF imageSelector = new GroupedImageSelectAdapter(lm); imageSelector.addOnItemSelectionListener(item -> checkIsFormComplete()); + imageSelector.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() + { + @Override public void onItemRangeInserted(int positionStart, int itemCount) + { + super.onItemRangeInserted(positionStart, itemCount); + + View item = lm.getChildAt(Math.max(0,positionStart-1)); + if(item != null) + { + int[] itemPos = new int[2]; + item.getLocationInWindow(itemPos); + int[] scrollViewPos = new int[2]; + scrollView.getLocationInWindow(scrollViewPos); + + uiThread.postDelayed(() -> + { + scrollView.smoothScrollTo(0,itemPos[1] - scrollViewPos[1]); + }, 250); + } + } + }); checkIsFormComplete(); return view; diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/GroupedImageSelectAdapter.java b/app/src/main/java/de/westnordost/streetcomplete/view/GroupedImageSelectAdapter.java index a353dcdd9e..bea183b9e5 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/GroupedImageSelectAdapter.java +++ b/app/src/main/java/de/westnordost/streetcomplete/view/GroupedImageSelectAdapter.java @@ -95,19 +95,6 @@ private void toggle(int index) selectedItem = null; } - if(selectedItem != null) - { - int selectedIndex = items.indexOf(selectedItem); - notifyItemChanged(selectedIndex); - - if(selectedItem.isGroup()) - { - if(prevSelectedItem == null || getGroup(items.indexOf(prevSelectedItem)) != selectedIndex ) - { - expandGroup(selectedIndex); - } - } - } if(prevSelectedItem != null) { int prevSelectedIndex = items.indexOf(prevSelectedItem); @@ -122,6 +109,19 @@ private void toggle(int index) } } } + if(selectedItem != null) + { + int selectedIndex = items.indexOf(selectedItem); + notifyItemChanged(selectedIndex); + + if(selectedItem.isGroup()) + { + if(prevSelectedItem == null || getGroup(items.indexOf(prevSelectedItem)) != selectedIndex ) + { + expandGroup(selectedIndex); + } + } + } for (OnItemSelectionListener listener : listeners) { listener.onItemSelected(selectedItem); diff --git a/app/src/main/res/layout/fragment_quest_answer.xml b/app/src/main/res/layout/fragment_quest_answer.xml index 84a0151a41..95892387ec 100644 --- a/app/src/main/res/layout/fragment_quest_answer.xml +++ b/app/src/main/res/layout/fragment_quest_answer.xml @@ -63,8 +63,9 @@ + be still too large to fit onto the screen without scrolling (it often is) -->