Skip to content

Commit

Permalink
Don't scroll to selected list item if it didn't change. (#989)
Browse files Browse the repository at this point in the history
Fixes #976

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 authored and mueller-ma committed Sep 10, 2018
1 parent bef96cc commit 88c2d2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ private int getItemViewType(OpenHABWidget widget) {
}
}

public void setSelectedPosition(int position) {
public boolean setSelectedPosition(int position) {
if (mSelectedPosition == position) {
return;
return false;
}
if (mSelectedPosition >= 0) {
notifyItemChanged(mSelectedPosition);
Expand All @@ -324,6 +324,7 @@ public void setSelectedPosition(int position) {
if (position >= 0) {
notifyItemChanged(position);
}
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,19 @@ public void setHighlightedPageLink(String highlightedPageLink) {
if (openHABWidgetAdapter == null) {
return;
}
openHABWidgetAdapter.setSelectedPosition(-1);
if (highlightedPageLink != null) {
for (int i = 0; i < openHABWidgetAdapter.getItemCount(); i++) {
OpenHABLinkedPage page = openHABWidgetAdapter.getItem(i).linkedPage();
if (page != null && highlightedPageLink.equals(page.link())) {
openHABWidgetAdapter.setSelectedPosition(i);
mLayoutManager.scrollToPosition(i);
break;
if (openHABWidgetAdapter.setSelectedPosition(i)) {
mLayoutManager.scrollToPosition(i);
}
return;
}
}
}
// We didn't find a matching page link, so unselect everything
openHABWidgetAdapter.setSelectedPosition(-1);
}

public void update(String pageTitle, List<OpenHABWidget> widgets) {
Expand Down

0 comments on commit 88c2d2f

Please sign in to comment.