5454import com .github .aakira .expandablelayout .ExpandableLinearLayout ;
5555import com .github .aakira .expandablelayout .ExpandableRelativeLayout ;
5656import com .github .aakira .expandablelayout .Utils ;
57+ import com .pacific .timer .Rx2Timer ;
5758import com .polidea .rxandroidble2 .RxBleClient ;
5859import com .polidea .rxandroidble2 .scan .ScanRecord ;
5960import com .polidea .rxandroidble2 .scan .ScanResult ;
6869import java .util .List ;
6970import java .util .Map ;
7071import java .util .UUID ;
72+ import java .util .concurrent .TimeUnit ;
7173
7274
7375import io .reactivex .android .schedulers .AndroidSchedulers ;
@@ -82,6 +84,7 @@ public class ScannerFragment extends BaseMainFragment implements View.OnFocusCha
8284 private RxBleClient rxBleClient ;
8385 private HashMap <String , LeBeacon > mLeBeaconHashMap = new HashMap <String , LeBeacon >();
8486 private UUID ALFABEACON_UUID = UUID .fromString ("0000a55a-0000-1000-8000-00805f9b34fb" );
87+ private Rx2Timer mCountTimer = null ;
8588
8689 private Disposable scanSubscription ;
8790 private DeviceAdapter mAdapter ;
@@ -259,6 +262,29 @@ public void onEnterAnimationEnd(Bundle savedInstanceState) {
259262 private void initDelayView () {
260263 // Auto start discover nearby devices
261264 hideSoftInput ();
265+ mCountTimer = Rx2Timer .builder ()
266+ .initialDelay (0 )
267+ .period (1 )
268+ .take (500 )
269+ .unit (TimeUnit .MILLISECONDS )
270+ .onCount (new Rx2Timer .OnCount () {
271+ @ Override
272+ public void onCount (Long count ) {
273+ }
274+ })
275+ .onError (new Rx2Timer .OnError () {
276+ @ Override
277+ public void onError (Throwable t ) {
278+ }
279+ })
280+ .onComplete (new Rx2Timer .OnComplete () {
281+ @ Override
282+ public void onComplete () {
283+ updateBeaconList ();
284+ mCountTimer .restart ();
285+ }
286+ })
287+ .build ();
262288 }
263289
264290 @ Override
@@ -301,6 +327,7 @@ private boolean startScan(){
301327 mFloatingActionButton .setImageDrawable (ContextCompat .getDrawable (getContext (), R .drawable .pause_icon ));
302328 mLeBeaconHashMap = new HashMap <String , LeBeacon >();
303329 updateBeaconList ();
330+ mCountTimer .start ();
304331
305332 scanSubscription = rxBleClient .scanBleDevices (
306333 new ScanSettings .Builder ()
@@ -325,6 +352,7 @@ private boolean stopScan(){
325352
326353 if (!scanSubscription .isDisposed ()) {
327354 scanSubscription .dispose ();
355+ mCountTimer .stop ();
328356 mProgressBar .setVisibility (View .GONE );
329357 mFloatingActionButton .setImageDrawable (ContextCompat .getDrawable (getContext (), R .drawable .play_icon ));
330358 return true ;
@@ -385,7 +413,7 @@ private void scanResultParser(ScanResult result) {
385413 previous .setRssi (result .getRssi ());
386414 mLeBeaconHashMap .put (previous .getMacAddress (), previous );
387415 }
388- updateBeaconList ();
416+ // updateBeaconList();
389417 }
390418 }
391419
0 commit comments