From 88c2d2ff1443ba24fc473c8f26b3c920aa17c46a Mon Sep 17 00:00:00 2001 From: maniac103 Date: Mon, 10 Sep 2018 21:25:47 +0200 Subject: [PATCH] Don't scroll to selected list item if it didn't change. (#989) Fixes #976 Signed-off-by: Danny Baumann --- .../org/openhab/habdroid/ui/OpenHABWidgetAdapter.java | 5 +++-- .../openhab/habdroid/ui/OpenHABWidgetListFragment.java | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetAdapter.java b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetAdapter.java index fc104e680e..85b0f26a27 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetAdapter.java +++ b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetAdapter.java @@ -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); @@ -324,6 +324,7 @@ public void setSelectedPosition(int position) { if (position >= 0) { notifyItemChanged(position); } + return true; } @Override diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetListFragment.java b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetListFragment.java index e2ca0e5da6..6b7128c00e 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetListFragment.java +++ b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABWidgetListFragment.java @@ -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 widgets) {