Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit e46828a

Browse files
committed
Fix Blocky UI behavior while scanning.
onUrlDeviceDiscoveryUpdate being called rapidly during scanning. Because of inefficiencies in the process of adding it to the UI this caused blocky behavior. This fix optimizes when we call the UIThread to empty the GroupIdQueue.
1 parent 79eac72 commit e46828a

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

android/PhysicalWeb/app/src/main/java/org/physical_web/physicalweb/NearbyBeaconsFragment.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -296,32 +296,28 @@ public void onListItemClick(ListView l, View v, int position, long id) {
296296

297297
@Override
298298
public void onUrlDeviceDiscoveryUpdate() {
299+
for (PwPair pwPair : mPwCollection.getGroupedPwPairsSortedByRank(
300+
new Utils.PwPairRelevanceComparator())) {
301+
String groupId = Utils.getGroupId(pwPair.getPwsResult());
302+
Log.d(TAG, "groupid to add " + groupId);
303+
if (mNearbyDeviceAdapter.containsGroupId(groupId)) {
304+
mNearbyDeviceAdapter.updateItem(pwPair);
305+
} else if (!mGroupIdQueue.contains(groupId)
306+
&& !Utils.isBlocked(pwPair)) {
307+
mGroupIdQueue.add(groupId);
308+
}
309+
}
310+
311+
if(mGroupIdQueue.isEmpty() || !mSecondScanComplete) {
312+
return;
313+
}
299314
// Since this callback is given on a background thread and we want
300315
// to update the list adapter (which can only be done on the UI thread)
301316
// we have to interact with the adapter on the UI thread.
302317
new Handler(Looper.getMainLooper()).post(new Runnable() {
303318
@Override
304319
public void run() {
305-
if (SwipeDismissListViewTouchListener.isLocked()) {
306-
return;
307-
}
308-
for (PwPair pwPair : mPwCollection.getGroupedPwPairsSortedByRank(
309-
new Utils.PwPairRelevanceComparator())) {
310-
String groupId = Utils.getGroupId(pwPair.getPwsResult());
311-
Log.d(TAG, "groupid to add " + groupId);
312-
if (mNearbyDeviceAdapter.containsGroupId(groupId)) {
313-
mNearbyDeviceAdapter.updateItem(pwPair);
314-
} else if (!mGroupIdQueue.contains(groupId)
315-
&& !Utils.isBlocked(pwPair)) {
316-
mGroupIdQueue.add(groupId);
317-
if (mSecondScanComplete) {
318-
// If we've already waited for the second scan timeout,
319-
// go ahead and put the item in the listview.
320-
emptyGroupIdQueue();
321-
}
322-
}
323-
}
324-
mNearbyDeviceAdapter.notifyDataSetChanged();
320+
emptyGroupIdQueue();
325321
}
326322
});
327323
}

0 commit comments

Comments
 (0)